6 format_string: procedure /* format_string(str, readable) */
10 res
= changestr('5C'x
, str
, "\\")
11 res
= changestr('"', res
, '\"')
12 res
= changestr('0A'x
, res
, "\n")
13 return '"' || res
|| '"'
18 format_sequence: procedure expose values
. /* format_sequence(val, open_char, close_char, readable) */
25 element
= word(val
, i
)
26 if i
> 1 then res
= res
|| " "
27 res
= res
|| pr_str
(element
, readable
)
29 return open_char
|| res
|| close_char
31 pr_str: procedure expose values
. /* pr_str(ast, readable) */
37 when type
== "nill" then return "nil"
38 when type
== "true" then return "true"
39 when type
== "fals" then return "false"
40 when type
== "numb" then return val
41 when type
== "symb" then return val
42 when type
== "stri" then return format_string
(val
, readable
)
43 when type
== "keyw" then return ":" || val
44 when type
== "list" then return format_sequence
(val
, "(", ")", readable
)
45 when type
== "vect" then return format_sequence
(val
, "[", "]", readable
)
46 when type
== "hash" then return format_sequence
(val
, "{", "}", readable
)
47 when type
== "nafn" then return "#<nativefunction:" || val
|| ">"
48 when type
== "func" then return "#<function:args=" || pr_str
(func_binds
(ast
), readable
) || ">"
49 when type
== "atom" then return "(atom " || pr_str
(val
, readable
) || ")"
51 return "#<UNKNOWN-TYPE>"