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.

3.3 Packages • 79definition. This allows the package author to make improvements to thepackage without disturbing any code that uses it. If the local proceduresreverse1 and map1 were exported (thus, available to users), it would bedifficult for the author to replace these routines without breaking existingcode that relies upon them.The package includes two special (local) procedures, setup andcleanup. These are executed, respectively, when the module is first readfrom a repository, and when the package is either garbage collected orwhen Maple is about to exit.Using the Package The package exports can always be accessed byusing the long form of their names.> LinkedList:-pair( a, b );(a, b)For consistency with the older table-based package implementations,an indexed notation can also be used.> LinkedList[ ’pair’ ]( a, b );(a, b)This form requires that the index (in this case, the symbol pair) beprotected from evaluation, and the notation does not extend to packageswith nested subpackages.To access the package exports interactively, use the with command.> with( LinkedList );Warning, the protected names length, map and memberhave been redefined and unprotected[append , head , length, list, map, member, nil , nullp, pair,reverse, tail ]Note that, since some of the package exports shadow global procedureswith the same name, the with command issues warnings. These warningsare normal. They remind you that these names now refer to expressionsdifferent from the expressions to which they referred previously. Once theexports of the package LinkedList have been bound, you can call themas you would global Maple routines with those names. Note that you can

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

Saved successfully!

Ooh no, something went wrong!