XPost: comp.unix.programmer
On Wed, 17 Apr 2024 08:05:23 -0700, John Ames wrote:
*Syntactically* it's very simple, but explicit stack-orientation with reverse-Polish notation is a *very* different programming paradigm than practically everything else out there ...
The only really tricky part of stack-based programming is keeping track of what’s on the stack.
I did some messing about with a reboot of PostScript which tried to add
some niceties, like stack guards and lexical binding. Here’s an example of the sort of thing I was able to get working (“ddef” and “dstore” define and assign to dynamically-bound variables, while “ldef” and “lstore” correspondingly work on lexically-bound ones):
/Count 99 ddef
/metatry
{ % provides context for nonlocals
dup
/Name exch ldef
/Count 0 ldef
{ % actual proc
/Count dup lload 1 add lstore
/Count dup dload 1 add dstore
Name =
(local Count = ) print /Count lload =
(global Count = ) print /Count dload =
(whichever Count = ) print Count =
}
}
ddef
/try1 metatry ddef
/try2 metatry ddef
try1
try2
try1
try2
Output:
try1
local Count = 1
global Count = 100
whichever Count = 1
try2
local Count = 1
global Count = 101
whichever Count = 1
try1
local Count = 2
global Count = 102
whichever Count = 2
try2
local Count = 2
global Count = 103
whichever Count = 2
--- SoupGate-Win32 v1.05
* Origin: fsxNet Usenet Gateway (21:1/5)