11.07.2015 Views

Advanced Programming Guide

Advanced Programming Guide

Advanced Programming Guide

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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

42 • Chapter 3: <strong>Programming</strong> with ModulesObjects are easily represented using modules. In software engineeringor object-oriented programming, an object is defined as something thathas both state and behavior. You compute with objects by sending themmessages, to which they respond by performing services.Generic Programs accept objects that possess specific properties or behaviors.The underlying representation of the object is transparent togeneric programs.ExamplesFor better understanding, it is helpful to examine a small module.Example 1: Simple Module When Maple evaluates the right side ofthe assignment to TempGenerator, it creates a module using the moduledefinition that begins with module()... and ends with end module.> TempGenerator := module()> description "generator for temporary symbols";> export gentemp;> local count;>> count := 0;> gentemp := proc()> count := 1 + count;> ‘tools/gensym‘( T || count )> end proc;> end module;TempGenerator := module()local count;export gentemp;description “generator for temporary symbols”;end moduleExample Summary The module definition resembles a procedure definition.The main differences are the use of the keyword module insteadof proc (and the corresponding terminator) and the export declarationfollowing the description string.Example 2: Procedure In the following example, the previous moduleis written using only procedures.> TempGeneratorProc := proc()> description "generator for temporary symbols";> local count, gentemp;> count := 0;

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

Saved successfully!

Ooh no, something went wrong!