36 lines
856 B
Text
36 lines
856 B
Text
|
|
q = "\""
|
||
|
|
e = "\\"
|
||
|
|
is-number = { x -> == (type x) "number" }
|
||
|
|
to-repr = ({
|
||
|
|
aux = {
|
||
|
|
[] -> ""
|
||
|
|
[x?is-number ~xs] -> & " " (tostring x) " " (aux xs)
|
||
|
|
[x ~xs] -> & q x q (aux xs)
|
||
|
|
}
|
||
|
|
|
||
|
|
{parts -> & "[" (aux parts) "]"}
|
||
|
|
})
|
||
|
|
fmt = {
|
||
|
|
[] _ -> ""
|
||
|
|
[x?is-number ~xs] args -> & args@x (fmt xs args)
|
||
|
|
[x ~xs] args -> & x (fmt xs args)
|
||
|
|
}
|
||
|
|
p = ["q = " 1 2 1 1 "
|
||
|
|
e = " 1 2 2 1 "
|
||
|
|
is-number = { x -> == (type x) " 1 "number" 1 " }
|
||
|
|
to-repr = ({
|
||
|
|
aux = {
|
||
|
|
[] -> " 1 1 "
|
||
|
|
[x?is-number ~xs] -> & " 1 " " 1 " (tostring x) " 1 " " 1 " (aux xs)
|
||
|
|
[x ~xs] -> & q x q (aux xs)
|
||
|
|
}
|
||
|
|
|
||
|
|
{parts -> & " 1 "[" 1 " (aux parts) " 1 "]" 1 "}
|
||
|
|
})
|
||
|
|
fmt = {
|
||
|
|
[] _ -> " 1 1 "
|
||
|
|
[x?is-number ~xs] args -> & args@x (fmt xs args)
|
||
|
|
[x ~xs] args -> & x (fmt xs args)
|
||
|
|
}
|
||
|
|
p = " 0 "; print (fmt p [(to-repr p) q e])"]; print (fmt p [(to-repr p) q e])
|