As joojaa correctly explains, LOCAL
is not defined to anything which is ok since it is replaced before executing. It parses as an executable name during construction of the procedure body (array) and its use here is just to allocate a slot in the array. It could actually be any type, and I've often seen (and written) { 0 begin ...}
for the same purpose. Using a name lets you give more semantic information to a human reader of the code. I've also seen it written { DICT begin ... }
Here in my matrix functions, I called it STATICDICT
, apparently.
There is a convention of using all upper-case for any meta-syntactical tokens like this. It is a nametype token, but meta-syntactically, it refers to a dicttype object to be filled-in later. There's no need (nor even any mechanism) to declare what you're doing for the benefit of the interpreter, but there is much to be gained by preferring DICT
over 0
. Again, since it will be completely replaced, you could also use a literal name /LOCAL
to try to, idunno, relieve the next noob to read your code from the wild-goose-chase of looking for where LOCAL
is defined?? To this end, I've also written simply DUMMY
for token to-be-filled-in-later. I suppose the choice among these terms is a matter of style or audience or some other intangible quality. sigh... or just a matter of context.
There is another style that works well for making dynamic substitutions in procedure bodies. By placing the dictionary on the dictstack and naming it (within itself, so it's a closed namespace), we can refer to it with an //immediate
name
4 dict begin
/mydict currentdict def
/proc {
//mydict begin
...
end
}
and then remove the dictionary before defining.
end def
Thus defining the procedure normally (in the outer-level dictionary (unnamed here, presumably userdict
)), but with the dictionary embedded by name, from having been available by that name while the procedure body was scanned.
This can be extended to more procedures sharing the same private dictionary by juggling the dict off of the stack for each definition.
/enddefbegin { currentdict 3 1 roll end def begin } def
4 dict begin
/mydict currentdict def
/proc1 {
//mydict begin
...
end
} enddefbegin
/proc2 {
//mydict begin
...
end
} enddefbegin
end
The enddefbegin end
at the end can of course be simplified to end def
.
One caveat. The dictionary created this way is recursively contained with itself. Do not try to print it with ghostscript's ===
operator!