

Article 1921 of comp.lang.postscript:
Path: mimsy!tank!ncar!unmvax!tut.cis.ohio-state.edu!bloom-beacon!oberon!sm.unisys.com!far-side.sm.unisys.com!dinh
>From: [email-masked] (Dinh Le)
Newsgroups: comp.lang.postscript
Subject: local variables implementation
Message-ID: <[email-masked]>
Date: 24 Feb 89 03:03:29 GMT
Sender: [email-masked]
Reply-To: [email-masked] (Dinh Le)
Organization: Unisys Santa Monica
Lines: 48

I have problems implementing local variables in postscript and wonder if
there are solutions (good or bad).  Here is a description:

Using C-prolog, I wrote a LOGO compiler using postscript as the target
language.  Most commands in LOGO can easily be simulated by postscript;
however, I have a hard time trying to simulate local variables declara-
tion in a LOGO procedure and the return function inside a LOGO procedure.

For example, if I have the following procedure

	procedure hilbert (size level parity)
	begin
		if level = 0 then return;
		left(parity * 90);	/* turn the turtle left by deg */ 
		hilbert(size level-1 -parity);
		forward(size);		/* forward turtle by size units */
		right(parity * 90);	/* turn the turtle right by deg */
		hilbert(size level-1 parity);
		forward size;
		hilbert(size level-1 parity);
		right(parity * 90);
		forward(size);
		hilbert(size level-1 -parity);
		left(parity * 90);
	end

	I've used following solution for local variables implementation, 
	but it doesn't work

	/hilbert {
		/hilbertdict begin
			/size exch def
			/level exch def
			/parity exch def

				...

		end
	} def

	Can someone spot the mistake(s) and suggest a solution for 
	local variable implementation?  Is there a nice way to 
	implement the return function which exit from a postscript 
	procedure?

				Thanks for any hints,

					'Dinh