1
1
mirror of https://github.com/kanaka/mal.git synced 2024-11-11 00:52:44 +03:00
mal/ps/env.ps
Joel Martin db4c329aff All: perf test, Makefile refactor, add *host-language*
Other:
- bash,make,postscript: quasiquote of vectors
- Fix Java slurp
- add time function to core.mal
    - switches on *host-language* for make time-secs vs time-ms
- Ignore */experiments directories
2014-04-17 21:49:07 -05:00

58 lines
1.4 KiB
PostScript

% outer binds exprs -> env_new -> new_env
/env_new { 3 dict begin
%(in env_new\n) print
/exprs exch dup _sequential? { /data get }{ pop [ ] } ifelse def
/binds exch dup _sequential? { /data get }{ pop [ ] } ifelse def
/outer exch def
<<
/__outer__ outer
0 1 binds length 1 sub {
/idx exch def
binds idx get (&) eq { %if &
binds idx 1 add get % key
exprs idx exprs length idx sub getinterval % value
_list_from_array
exit
} if
binds idx get % key
exprs idx get % value
} for
>>
end } def
% env key -> env_find -> env
% env key -> env_find -> null
/env_find { 2 dict begin
/key exch def
/env exch def
env key known { %if key in env
env
}{ env /__outer__ get null ne { %elseif __outer__ not null
env /__outer__ get key env_find
}{ %else
null
} ifelse } ifelse
end } def
% env key val -> env_set -> val
/env_set {
dup 4 1 roll % stack: val env key val
put % stack: val
} def
/env_get {
dup 3 1 roll % stack: key env key
env_find % stack: key env/null
dup null eq {
pop % stack: key
(') exch % stack: (') key
dup length string cvs
(' not found)
concatenate concatenate
_throw
}{
exch % stack: env key
get
} ifelse
} def