Record - Maple Help

Online Help

All Products    Maple    MapleSim


Home : Support : Online Help : Programming : Operations : Record

Record

the record constructor

 

Calling Sequence

Parameters

Description

Thread Safety

Examples

Compatibility

Calling Sequence

Record( a, b, ... )

Record[packed]( a, b, ... )

Record[r1,r2]( a, b, ... )

Record[r1,r2,packed]( a, b, ... )

Record[record,r1,r2]( a, b, ... )

Parameters

a, b, ...

-

one or more field specifications

r1, r2, ...

-

one or more existing records

Description

• 

The record constructor Record creates a Maple record. Records are defined by their "field" names, each of which must be a Maple symbol. Two records are considered to be equal if they have the same field names and if, for each slot name n, the values of the fields named n in the two records are equal.

• 

Like an Array, a record is a fixed-size collection of items but, like a table, individual items are addressable by name, rather than by a numeric offset.

• 

Records are implemented in Maple as modules, all of whose variables are exported. The field names are just the module exports. Records are distinguished from modules, in general, by the presence of the record option.

• 

Record takes one or more field specifiers as its arguments. A field specifier is a global name, a `::` expression whose first operand is a global name, or an equation whose left-hand side is one of these two. For example, each of a, a::polynom, a = 2*x, and a::polynom = 2*x is a valid field specifier. The name part of the specifier is the "field name" (a in these examples). A record having fields with the indicated names is returned. Field names cannot be repeated, and unevaluation quotes (' ') may be needed if the symbols used as field names happen to already be assigned values. If a field name has the same spelling as a local name within scope of a call to Record, then the : prefix will be needed on the field name to force the name to be bound globally. An equation is used as the field specifier to indicate an initial value for the corresponding record field. For example, the field a will be assigned the value 2 if the equation a=2 is used.

• 

To make it easier to construct records programmatically, the symbol in a record field specifier may also be passed to the Record constructor as a string. This avoids potential evaluation of field names that correspond to an assigned global variable.

• 

As a special case, you can pass a single record argument to Record, which will copy it for you. (Note that the argument will normally need to be evaluated one level, since last-name evaluation applies to variables that have a record as a value.)

• 

If the Record constructor function call is indexed, the indices must specify existing record(s). The new record will inherit all the field names of the specified records. Unlike the special case of a single record argument, indices that are variables with record values will automatically be evaluated.

• 

A field specifier of the form a will elide the specified inherited field from the record being constructed.

• 

The Record constructor function can be called with the indexed name Record[packed], which will produce a packed record.

  

Unlike a regular record, a packed record does not create a unique instance of each field name for each record instance. When working with thousands of similar records each with many fields, this can save a significant amount of memory and processing time.

  

Fields of packed records do not exhibit last-name evaluation. That is, the expression r:-a always produces a value, even if that value is a procedure, table, Matrix, Vector, or another record.

  

Similarly, it is not possible for a packed record field to have no value. The assigned function will always return true, and unassigning a packed record field will set its value to NULL instead.

  

When calling the Record constructor with one or more indices specifying existing records, the resulting record will automatically be a packed record if any of the prototype records were packed records.

  

This behavior can be overridden, thus forcing the creation of non-packed records, by including the symbol record in the index of the Record constructor function.

• 

You can use verify(...,record) to test the equality of two records.

• 

Printing of records is governed by interface(max_record_depth). The setting of this interface option controls how deeply nested records are printed.

Thread Safety

• 

The Record command is thread-safe as of Maple 15.

• 

For more information on thread safety, see index/threadsafe.

Examples

The following statement creates a simple record r with fields a and b. Because the field names are exported, they can be accessed directly.

rRecord'a','b'

r:=Recorda,b

(1)

r:-a2

a:=2

(2)

r:-a

2

(3)

rRecord'a'=2x,'b'=yx

r:=Recorda=2x,b=yx

(4)

r:-ar:-b

2x2y

(5)

typer,'record'

true

(6)

Records can be combined.

rRecorda=1,b=2

r:=Recorda=1,b=2

(7)

sRecordc=3,d=4

s:=Recordc=3,d=4

(8)

rsRecord[r,s]e=5

rs:=Recorda=1,b=2,c=3,d=4,e=5

(9)

prRecord[packed]x=24,y=25

pr:=Recordpackedx=24,y=25

(10)

rprRecord[r,pr]z=26

rpr:=Recordpackeda=1,b=2,x=24,y=25,z=26

(11)

Specified inherited fields can be elided.

rsRecord[r,s]b,d

rs:=Recorda=1,c=3

(12)

Records are useful for simple, structured data.

circleRecord'center'=0,1,'radius'=3

circle:=Recordcenter=0,1,radius=3

(13)

`type/circle`'recordcenter,radius':

CircleAreac::circle→c:-radiusc:-radiusπ:

CircleAreacircle

9π

(14)

CircleCircumferencec::circle→2πc:-radius:

CircleCircumferencecircle

6π

(15)

You can test the equality of two records by using a procedure such as the following. Alternatively, use the record option to verify.

receq := proc( a::record, b::record )
    description "test whether two records are equal";
    local    e;
    if { exports( a ) } = { exports( b ) } then
        for e in { exports( a ) } do
            if a[ e ] <> b[ e ] then
                return false
            end if
        end do;
        true
    else
        false
    end if
end proc:

rRecord&apos;foo&apos;&equals;2&comma;&apos;bar&apos;&equals;3&colon;

sRecord&apos;foo&apos;&equals;2&comma;&apos;bar&apos;&equals;4&colon;

tRecord&apos;foo&apos;&equals;2&comma;&apos;bar&apos;&equals;3&comma;&apos;baz&apos;&equals;5&colon;

receqr&comma;r

true

(16)

receqr&comma;Recordevalr&comma;1

true

(17)

receqr&comma;s

false

(18)

receqr&comma;t

false

(19)

receqs&comma;t

false

(20)

verifyr&comma;r&comma;record

true

(21)

verifyr&comma;s&comma;record

false

(22)

rRecord&apos;foo&apos;&equals;2&comma;&apos;bar&apos;&equals;Record&apos;subfoo&apos;&equals;3

r:=Recordfoo&equals;2&comma;bar&equals;Record...

(23)

interfacemax_record_depth&equals;2&colon;

printr

Recordfoo&equals;2&comma;bar&equals;Recordsubfoo&equals;3

(24)

interfacemax_record_depth&equals;0&colon;

printr

Record...

(25)

Compatibility

• 

The Record command was updated in Maple 15.

See Also

Array

interface

list

module

symbol

table

type/record

verify/record

 


Download Help Document

Was this information helpful?



Please add your Comment (Optional)
E-mail Address (Optional)
What is ? This question helps us to combat spam