Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.postscript > #4007
| From | Lawrence D'Oliveiro <ldo@nz.invalid> |
|---|---|
| Newsgroups | comp.lang.postscript |
| Subject | Lexical Binding |
| Date | 2024-06-04 05:59 +0000 |
| Organization | A noiseless patient Spider |
| Message-ID | <v3mafc$a8mc$2@dont-email.me> (permalink) |
In GXScript, I have renamed “def”, “load”, “store” and “where” to “ddef”,
“dload”, “dstore” and “dwhere” (“d” for “dynamic”) and added corresponding
lexically-bound variants “ldef”, “lload”, “lstore” and “lwhere”. In
effect, GXScript is a “block-structured” language.
Example:
/Count 99 ddef
{
/Count 1 ldef
3
{
/Count dup lload 1 add lstore
(local Count = ) print /Count lload =
(global Count = ) print /Count dload =
(whichever Count = ) print Count =
}
repeat
} exec
produces output
local Count = 2
global Count = 99
whichever Count = 2
local Count = 3
global Count = 99
whichever Count = 3
local Count = 4
global Count = 99
whichever Count = 4
and you can define function factories, e.g.
/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
produces 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
Back to comp.lang.postscript | Previous | Next | Find similar
Lexical Binding Lawrence D'Oliveiro <ldo@nz.invalid> - 2024-06-04 05:59 +0000
csiph-web