Download Maple Programming Guide

Transcript
330 • 8 Programming with Modules
has the structured module type `module`( a, b ):
> type( m, '`module`( a, b )' );
(8.48)
It also has the type `module`( a )
> type( m, '`module`( a )' );
(8.49)
because any module that exports symbols a and b is a module that exports the symbol a.
For more information about structured types, refer to the type,structure help page.
8.5 Records
The Record command, which was introduced in Records (page 159), is an example of a
module factory that can help you to write reusable code. Like an Array, a record is a fixed
size collection of items but, like a table, individual items stored within the record can be
referenced by a name, rather than a numeric offset. In Maple, records, which are called
structures in C++, are implemented as modules.
Creating Records
To create a record, use the Record constructor. In the simplest form, it takes the fiel names
as arguments.
> rec := Record( 'a', 'b', 'c' );
(8.50)
The name rec is now assigned a record with field named a, b, and c. You can access and
assign values to these field by using the expressions rec:-a, rec:-b, and rec:-c.
> rec:-a := 2;
(8.51)
> rec:-a;
(8.52)
If unassigned, a record fiel evaluates to the local instance of the fiel name.
> rec:-b;
(8.53)