使用语法->字符串将列表列表转换为字符串列表
基本上,我想要 '( (whatever1) (whatever2) (whatever3) ... )
===> ( "(whatever1)" "(whatever2)" "(whatever3)" )
,只是在列表之外添加引号,列表中的内容保持不变。例如
'((define X ::int)
(define b0 :: bool (=> T (and (= X X) (= 0 0)))))
将变成:
'("(define X ::int)"
"(define b0 :: bool (=> T (and (= X X) (= 0 0))))")
但是,我使用的以下代码消除了所有空格!
#lang racket
(require syntax/to-string)
(define lst-sub '((define x :: int) (=> T (and (= X X) (= 0 0)))))
(pretty-write (map (λ (x) (string-append "(" (syntax->string (datum->syntax #f x)) ")")) lst-sub))
返回
("(definex::int)" "(=>T(and(=XX)(=00)))")
所以问题是:不再有空格了! 我该如何解决这个问题?
Basically, I want '( (whatever1) (whatever2) (whatever3) ... )
===> ( "(whatever1)" "(whatever2)" "(whatever3)" )
, which is just add quotes outside of the list, and keep the contents in the list unchanged. e.g.
'((define X ::int)
(define b0 :: bool (=> T (and (= X X) (= 0 0)))))
will be turned into:
'("(define X ::int)"
"(define b0 :: bool (=> T (and (= X X) (= 0 0))))")
However, the following code I am using eliminate all spaces!
#lang racket
(require syntax/to-string)
(define lst-sub '((define x :: int) (=> T (and (= X X) (= 0 0)))))
(pretty-write (map (λ (x) (string-append "(" (syntax->string (datum->syntax #f x)) ")")) lst-sub))
which returns
("(definex::int)" "(=>T(and(=XX)(=00)))")
So the question is: there is no spaces anymore!
How can I get around this??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好吧。我不走我认为的“简单”路线。并按如下方式计算,最终会产生更多行代码:(
Alright. I don't take the "easy" route I thought. and worked out as follows, which ends up with more lines of code :(