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.

• 43> gentemp := proc()> count := 1 + count;> ‘tools/gensym‘( T || count )> end proc;> eval( gentemp, 1 )> end proc:You can assign the procedure returned by TempGeneratorProc, andthen use it to generate temporary symbols.> f := TempGeneratorProc();> f();f := proc()count := 1 + count ; ‘tools/gensym‘(T ||count)end procT1> f();T2Module Versus ProcedureThe module TempGenerator and the procedure TempGeneratorProc aresimilar.In the procedure version, the local variable gentemp is assigned a procedurethat references another local variable count; the value of gentempis returned by the procedure to its caller. The module version of thegenerator behaves similarly. Its structure differs: its gentemp variable isdeclared as an export, not a local, and there is no explicit return.In both versions of the generator, the variables count and gentempare local variables. The significant difference here is that, in the moduleversion, one of those local variables is exported. This means that itis available outside the scope of the structure in which it was created.Special syntax is used access exported local variables. For example, tocall the exported variable gentemp of the module, enter> TempGenerator:-gentemp();T1

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

Saved successfully!

Ooh no, something went wrong!