postscript Getting started with postscript Local namespaces for functions


Example

Postscript is a dynamic-namespacing or LISP 1 language. But it provides the tools to implement local variables in procedures and other effects needed to implement algorithms.

For local names in a procedure, make a new dictionary at the start and pop it at the end.

/myproc {
    10 dict begin
    %... useful code ...
    end
 } def

You can also combine this nicely with a shortcut to define the function's arguments as variables.

% a b c  myproc  result
/myproc {
    10 dict begin
    {/c /b /a} {exch def} forall
    %... useful code yielding result ...
    end
 } def

If you need to update a *"global" * variable while the local dictionary is on top, use store instead of def.