11.07.2015 Views

Advanced Programming Guide

Advanced Programming Guide

Advanced Programming Guide

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

70 • Chapter 3: <strong>Programming</strong> with Modules(You can use a different argument to diff to avoid recalling the answerfrom its remember table.) The traditional mechanism fails becauseit relies on the external representation of names, and not upon theirbindings, so each attempt to define an extension to diff in fact adds adefinition for the derivative of all functions whose names are spelled "F".Note: A commented version of the differentiator module is availablein the samples directory of your Maple installation. The implementationshown in the text has been somewhat simplified.3.2 RecordsThe simplest way to use modules is as Pascal-style records (or structures,as in C and C++). A record is a data structure that has some numberof named slots or fields. In Maple, these slots can be assigned arbitraryvalues.Instantiating Records To create a record, use the Record constructor.It takes the slot names as arguments.> rec := Record( ’a’, ’b’, ’c’ );rec :=module() export a, b, c; option record ; end moduleThe name rec is now assigned a record with slots named a, b, and c.These are the slot names for the record rec. You can access and assignthese slots by using the expressions rec:-a, rec:-b, and rec:-c.> rec:-a := 2;a := 2> rec:-a;2If not assigned, the record slot evaluates to the local instance of theslot name.> rec:-b;

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!