Article View: comp.lang.postscript
Article #829Re: newcomer, need help with forall
From: Richard G. Knowles
Date: Wed, 09 Aug 1989 23:08
Date: Wed, 09 Aug 1989 23:08
44 lines
2515 bytes
2515 bytes
In article <JNP.89Aug9134311@mjolner.tele.nokia.fi> jnp@mjolner.tele.nokia.fi (J|rgen N|rgaard) writes:
>Consider the following program:
>
> /Helvetica findfont 10 scalefont setfont
> 100 100 translate
> /en { gsave 0 0 moveto 1 10 string cvs show grestore } def
> /to { gsave 0 0 moveto 2 10 string cvs show grestore } def
> /tre { gsave 0 0 moveto 3 10 string cvs show grestore } def
> /fire { gsave 0 0 moveto 4 10 string cvs show grestore } def
>
>%% method one
> [en to tre fire]{ 0 50 translate exec} forall showpage
>
> 100 100 translate
>%% method two
> [1 2 3 4]{ 0 50 translate 0 0 moveto 10 string cvs show} forall showpage
>
>I would expect "method one" and "method two" to be equivalent. But they are
>not, but why ?
>(method one prints all characters on top of each other,
> method two prints all characters one above the other:
They are different because method 1 forall recieves an empty array and thus
does not ever execute the proc. What is happening, however, is that the en,
to, tre, and fire procedures are getting executed instead of being placed
into the array. Since those procedures leave nothing on the operand stack
the array ends up empty.
Arrays are built, not created verbatim. Thus the '[' leaves a mark on the
stack, each following token is parsed (and "executed" if executable), and
the ']' packs all objects on the stack down to the mark into an array object.
Correct ways of specifying method one are:
[//en //to //tre //fire ] { 0 50 translate exec} forall
[/en load /to load /tre load /fire load] { 0 50 translate exec} forall
[/en /to /tre /fire ] { 0 50 translate load exec} forall
-------- Whatever I say is my fault and no one elses! -----------
Richard G. Knowles richk@pogo.WV.TEK.COM
Graphics Printing and Imaging (503) 685-3860
Tektronix, Inc; D/S 63-356
Wilsonville, Or 97070 or just yell "Hey, Rich!"
Technical Details
Message-ID:
<7725@pogo.WV.TEK.COM>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!watmath!att!dptg!rutgers!mailrus!wasatch!cs.utexas.edu!uunet!zephyr.ens.tek.com!orca!pogo!richkReferences:
<JNP.89Aug9134311@mjolner.tele.nokia.fi>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!watmath!att!dptg!rutgers!mailrus!wasatch!cs.utexas.edu!uunet!zephyr.ens.tek.com!orca!pogo!richk From: richk@pogo.WV.TEK.COM (Richard G. Knowles) Newsgroups: comp.lang.postscript Subject: Re: newcomer, need help with forall Message-ID: <7725@pogo.WV.TEK.COM> Date: 9 Aug 89 23:08:03 GMT References: <JNP.89Aug9134311@mjolner.tele.nokia.fi> Reply-To: richk@pogo.WV.TEK.COM (Richard G. Knowles) Distribution: comp Organization: Tektronix, Inc., Wilsonville, OR. Lines: 44