1 /runlibfile where
{ pop }{ /runlibfile
{ run
} def
} ifelse %
4 (printer.ps
) runlibfile
9 /_readline
{ print flush
(%stdin) (r) file 1024 string readline } def
18 /eval_ast
{ 2 dict begin
21 %(eval_ast: ) print ast ==
22 ast _symbol?
{ %if symbol
24 }{ ast _sequential?
{ %elseif list or vector
26 ast
/data get
{ %forall items
29 ] ast _list?
{ _list_from_array
}{ _vector_from_array
} ifelse
30 }{ ast _hash_map?
{ %elseif list or vector
32 ast
/data get
{ %forall entries
35 >> _hash_map_from_dict
38 } ifelse } ifelse } ifelse
45 %(EVAL: ) print ast true _pr_str print (\n) print
46 ast _list? not
{ %if not a list
48 }{ %else apply the list
52 }{ /def
! a0 eq
{ %if def!
55 env a1 a2 env EVAL env_set
56 }{ /let
* a0 eq
{ %if let*
59 /let_env env null null env_new def
60 0 2 a1 _count
1 sub { %for each pair
64 a1 idx
1 add _nth let_env EVAL
66 pop % discard the return value
70 /el ast _rest env eval_ast def
71 el el _count
1 sub _nth
% return last value
75 cond null eq cond
false eq or
{ % if cond is nil or false
76 ast _count
3 gt
{ %if false branch with a3
79 }{ % else false branch with no a3
86 }{ /fn
* a0 eq
{ %if fn*
89 a2 env a1 _mal_function
91 /el ast env eval_ast def
92 el _rest el _first
% stack: ast function
93 dup _mal_function?
{ %if user defined function
94 fload
% stack: ast new_env
96 }{ dup _function?
{ %else if builtin function
98 }{ %else (regular procedure/function)
99 (cannot apply native proc
!\n) print
quit
101 } ifelse } ifelse } ifelse } ifelse } ifelse } ifelse
113 /repl_env null null null env_new def
115 /RE
{ READ repl_env EVAL
} def
116 /REP
{ READ repl_env EVAL PRINT
} def
118 % core.ps: defined using postscript
119 /_ref
{ repl_env
3 1 roll env_set
pop } def
120 core_ns
{ _function _ref
} forall
122 % core.mal: defined using the language itself
123 (\
(def
! not \
(fn
* \
(a\
) \
(if a
false true\
)\
)\
)) RE
pop
128 not
{ exit } if % exit if EOF
134 get_error_data
false _pr_str print
(\n) print
135 $error
/newerror
false put
136 $error
/errorinfo null put
142 (\n) print
% final newline before exit for cleanliness