String escape not working?

27 views
Skip to first unread message

emum

unread,
Aug 11, 2022, 9:56:00 AM8/11/22
to Shen
Am I doing something wrong?

(define shen-print-json
Json -> "{\"a\":\"b\",\"c\":\"d\"}")

I'm getting

syntax error here:
(define shen-print-json
Json -> "{\"a\":\"b\", ...Exception in abort: 

In python this works

>>> def py_pr_json():
...     return "{\"a\":\"b\",\"c\":\"d\"}"
...
>>> py_pr_json()
'{"a":"b","c":"d"}'

What am I doing wrong? Couldn't find string escapes in the book.

Mark Tarver

unread,
Aug 11, 2022, 11:56:51 AM8/11/22
to Shen
there are no escapes; use character codes for strings in strings.

M.

Mark Tarver

unread,
Aug 11, 2022, 12:50:46 PM8/11/22
to Shen
e.g. 

(27-) "c#34;ac#34; c#34;bc#34;"
""a" "b""

Too clunky?    Invent your own notation.

(define embed-h
   {string --> string}
    "" -> ""
    (@s "£" S Ss) -> (@s "c#34;" S "c#34;" (embed-h Ss))
    (@s S Ss) -> (@s S (embed-h Ss)))
   
 (defmacro escape-macro
    S -> (embed-h S)  where (string? S))   

(29-) "£a £b £c"
""a" "b" "c""

Mark

emum

unread,
Aug 11, 2022, 5:44:15 PM8/11/22
to Shen
O_O Got it thanks, that works. I'll also check out the Strings package in the std lib for any tools that assist with this.
Reply all
Reply to author
Forward
0 new messages