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.

78 • Chapter 3: <strong>Programming</strong> with Modules> end if> end proc;>> append := proc( lst1, lst2 )> if nullp( lst1 ) then> lst2> else> pair( head( lst1 ),> procname( tail( lst1 ), lst2 ) )> end if> end proc;>> reverse1 := proc( sofar, todo )> if nullp( todo ) then> sofar> else> procname( pair( head( todo ), sofar ),> tail( todo ) )> end if> end proc;>> reverse := lst -> reverse1( nil, lst );>> setup();>> end module:Normally, a package definition like this would be entered into a Maplesource file using a text editor, or in a worksheet using Maple’s graphicaluser interface. In either case, the definition would then be followed by acall to the savelib procedure using the name of the module as its soleargument:> savelib( ’LinkedList’ );Evaluating the savelib call saves the module to the first repositoryfound in the global variable libname, or the repository named with theglobal variable savelibname, if it is defined. (At least one of these mustbe defined.)Important Always ensure that your standard Maple library is writeprotectedto avoid saving your expressions in it. If you accidentally savesomething to the standard Maple library, you may need to restore theoriginal from the media on which you obtained your copy of the Maplesoftware.The package exports are listed as the exports of the module. A fewlocal variables are used to implement the package. The local proceduresmap1 and reverse1 are part of the package implementation that is notavailable to users of the package. They are visible only within the module

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

Saved successfully!

Ooh no, something went wrong!