Sujet : Re: On Stack-Based Languages (was Re: on Perl)
De : ldo (at) *nospam* nz.invalid (Lawrence D'Oliveiro)
Groupes : comp.unix.programmer comp.lang.miscDate : 18. Apr 2024, 08:55:42
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <uvqjlu$257pa$1@dont-email.me>
References : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
User-Agent : Pan/0.155 (Kherson; fc5a80b8)
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