1 % requires types.ps to be included first
3 % ast print_readably -> _pr_str -> string
4 /_pr_str
{ 4 dict begin
5 /print_readably
exch def
6 dup xcheck
{ (Cannot print proc
: ) print
dup == quit } if % assert
9 obj _list?
{ (\
() (\
)) }{ ([) (]) } ifelse
10 obj
/data get
( ) print_readably _pr_str_args
11 exch concatenate concatenate
14 % get array of contents with keys stringified
15 [ obj
/data get
{ exch dup length string cvs
exch } forall
]
16 ( ) print_readably _pr_str_args
19 }{ obj _function?
{ % if builtin function
21 obj
/data get
dup length array
copy cvlit
22 ( ) print_readably _pr_str_args
24 concatenate concatenate
25 }{ obj _mal_function?
{ % if user defined mal_function
27 obj
/params get print_readably _pr_str
29 obj
/ast get print_readably _pr_str
31 concatenate concatenate concatenate concatenate
32 }{ obj _atom?
{ % if atom
34 obj
/data get print_readably _pr_str
36 concatenate concatenate
37 }{ /arraytype obj type eq
{ % if list or code block
38 % accumulate an array of strings
40 obj
( ) print_readably _pr_str_args
44 }{ /integertype obj type eq
{ % if number
45 /slen obj
abs log ceiling cvi
2 add def
46 obj
10 slen string cvrs
47 }{ /stringtype obj type eq
{ % if string
48 obj length
0 gt
{ % if string length > 0
49 obj
0 get
127 eq
{ %if starts with 0x7f (keyword)
50 obj
dup length string
copy
51 dup 0 58 put
% 58 is ':'
54 obj (\\) (\\\\) replace
57 (") concatenate concatenate
61 }{ % else empty string
68 }{ null obj eq
{ % if nil
70 }{ true obj eq
{ % if true
72 }{ false obj eq
{ % if false
74 }{ /nametype obj type eq
{ % if symbol
75 obj
dup length string cvs
78 } ifelse } ifelse } ifelse } ifelse } ifelse } ifelse } ifelse } ifelse } ifelse } ifelse } ifelse } ifelse
81 % array delim print_readably -> _pr_str_args -> new_string
82 /_pr_str_args
{ 3 dict begin
83 /print_readably
exch def
87 args length
0 gt
{ %if any elements
89 args
{ %foreach argument in array
90 dup xcheck
{ %if executable
93 print_readably _pr_str
97 { concatenate delim concatenate
} forall
98 dup length delim length
sub 0 exch getinterval
% strip off final delim
104 (DICT contents
:\n) print
107 exch dup length string cvs print
% key