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.

3.1 Syntax and Semantics • 51modexpr :- membernameHere, modexpr must be an expression that evaluates to a module, andmembername must be the name of an export of the module to whichmodexpr evaluates. Anything else signals an exception. You cannot accesslocal variables of an instantiated module by using this syntax.Local variables of a procedure are created when the procedure is called(or invoked). Normally, the locals persist only during the execution of thestatements that form the body of the procedure. Sometimes, however,local variables persist beyond the procedure activation that instantiatedthem. For example:> gen := proc()> local s, p;> s := 2;> p := x -> s * x;> p> end proc:> g := gen();g := p> g( 3 );6The local variable s of gen persists after gen has returned. It is capturedin the closure of the procedure p, whose name is returned by gen.Thus, both local variables p and s of gen escape, but in different ways.The local name p is accessible because it is the assigned value of theglobal variable g. However, there is no way to refer to s once gen hasreturned. No Maple syntax exists for that purpose. The member selectionoperator :- provides a syntax for referencing certain local variables ofmodules–those declared as exports.The most recent Hello example has one export, named say. In thiscase, say is assigned a procedure. To call it, enter> Hello:-say();“HELLO WORLD!”The following expression raises an exception, because the namenoSuchModule is not assigned a module expression.

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

Saved successfully!

Ooh no, something went wrong!