1 /runlibfile where
{ pop }{ /runlibfile
{ run
} def
} ifelse %
4 (printer.ps
) runlibfile
8 /_readline
{ print flush
(%stdin) (r) file 1024 string readline } def
17 /eval_ast
{ 2 dict begin
20 %(eval_ast: ) print ast ==
21 ast _symbol?
{ %if symbol
23 }{ ast _sequential?
{ %elseif list or vector
25 ast
/data get
{ %forall items
28 ] ast _list?
{ _list_from_array
}{ _vector_from_array
} ifelse
29 }{ ast _hash_map?
{ %elseif list or vector
31 ast
/data get
{ %forall entries
34 >> _hash_map_from_dict
37 } ifelse } ifelse } ifelse
44 %(EVAL: ) print ast true _pr_str print (\n) print
45 ast _list? not
{ %if not a list
47 }{ %else apply the list
51 }{ /def
! a0 eq
{ %if def!
54 env a1 a2 env EVAL env_set
55 }{ /let
* a0 eq
{ %if let*
58 /let_env env null null env_new def
59 0 2 a1 _count
1 sub { %for each pair
63 a1 idx
1 add _nth let_env EVAL
65 pop % discard the return value
69 /el ast env eval_ast def
70 el _rest el _first
% stack: ast function
71 exec % apply function to args
72 } ifelse } ifelse } ifelse
84 /repl_env null null null env_new def
86 /REP
{ READ repl_env EVAL PRINT
} def
88 /_ref
{ repl_env
3 1 roll env_set
pop } def
89 (+) { dup 0 _nth
exch 1 _nth add
} _ref
90 (-) { dup 0 _nth
exch 1 _nth
sub } _ref
91 (*) { dup 0 _nth
exch 1 _nth
mul } _ref
92 (/) { dup 0 _nth
exch 1 _nth
idiv } _ref
97 not
{ exit } if % exit if EOF
103 get_error_data
false _pr_str print
(\n) print
104 $error
/newerror
false put
105 $error
/errorinfo null put
111 (\n) print
% final newline before exit for cleanliness