Re: Postscript questions



François Robert wrote:

To add to the remarks already made by others posters :

It looks as if you believe the curly braces {} are defining a scope (as in C, C++, Java etc...). Hence an outer procedure being perceived as "global" and the inner one as "local".

This is *not* the way Postscript uses curly braces (or scopes).

Curly braces are behaving much more like the square brackets [], the array "delimiters". The difference is deferred execution (and the executable attribute), as already mentionned.
In Postscript, as in Lisp, data and program are more or less the same. A procedure is an executable array. Executable arrays can be nested, but that does not imply a local scope.

I would say the closest thing Postscript has to a C++ scope are dictionnaries on the dictionnary stack, combined with the name lookup rules. (Conceivably, the operand stack can also be another distinct, mechanism to manage scope).

In other words, there is not much difference between :
[ [] ]
and { { } }

Both of those create an array.
Both of those arrays have a single element which is itself an empty array.
Those lines differ in the way the interpreter executes (evaluate) them. What's enclosed in a [] pair is evaluated immediately at parsing time. What's enclosed in {} is evaluated later (possibly never).
They also differ by the fact that the array created by {} have an executable attribute set (and for that reason is commonly called a 'procedure')
You can mutate executable array into litteral one and back with the 'cvlit' and 'cvx' operators.

In other words : [ [ ] cvx ] cvx is indistinguishable from (yields the same operand stack as) :
{ { } }

Likewise :
{} cvlit and
[]

While I am at comparing languages, I may as well mention that code like:
MyProc
does not merely operate like a function call (as one would expect coming from C / C++ background). It is closer to Lisp evaluation :

Such a line leaves an executable name on the operand stack and the interpreter attempts to evaluate it.
Evaluating an executable name means that the interpreter searchs the name through the dictionnary stack and when found, evaluate the value associated with the name.
What happens next depends on both the type and the executable attribute of the value.
If the value is an executable name, it's looked up and evaluated as described above.
If the value is an executable array (a procedure if you prefer), each element of the array is evaluated in the order of the array.
If the value is anything else, it's placed on the operand stack.

In a nutshell :
{} are array delimiter, with execution (evaluation) deferred until after parsing time. Unlike other languages, {} don't define a scope.

_______________________________________________________
François Robert
(to mail me, reverse character order in reply address)
Well, i have found that a "procedure" defined inside another is not accessable outside - and that is why i think of it as being local.
So far, i found that by pre-defining that "inner" procedure, i then had access to the "inner" definition - and that is why i used the term "global".

Looks like i have to study your explaination and carefully go over what i have so far, and maybe do some re-writes.
.



Relevant Pages

  • Re: Postscript questions
    ... It looks as if you believe the curly braces are defining a scope ... The difference is deferred execution (and ... A procedure is an executable array. ... Evaluating an executable name means that the interpreter searchs ...
    (comp.lang.postscript)
  • Re: Is it possible to use the value of the PROGRAM ID within the source code?
    ... Until the universal availability of scope terminators there were ... But 'reusability' is not a unique feature of OO design. ... remain and some are now garbage. ... A tree can be made faster by increasing its width; an array ...
    (comp.lang.cobol)
  • Re: Packages and returning errors
    ... > array intact. ... sub is_a_instance_method { ... my $class = shift; ... You need to fix the scope of $error by moving its declaration outside ...
    (comp.lang.perl.misc)
  • Re: Thq Quiz
    ... If 'arg' is a non-negative integer less than ... limited in scope and all of the behaviour that is being objected to is ... determined upon entering an execution context, ... execution of the function, and only the latter comes into existence ...
    (comp.lang.javascript)
  • Re: Re: Re: RE: Perl Question: Optimization
    ... @ids array changes, the statement gets re-prepared, so unless you have the ... # THIS INPUT DATA FILE CONTAINS ABOUT 40000 ROWS ... >prepared statement inside the loop of 40000. ...
    (perl.dbi.users)