使用语法->字符串将列表列表转换为字符串列表

| 基本上,我想要
\'( (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)))\")
因此,问题是:不再有空格! 我该如何解决?     
已邀请:
#lang racket
(define lst-sub \'((define x :: int) (=> T (and (= X X) (= 0 0)))))
(pretty-write (map (λ (x) (format \"~s\" x)) lst-sub))
    
好的。我不采取我认为的“轻松”路线。并得出如下结果,最终得到了更多的代码行:(
(define (toString-with-space data)
  (match data
    [(? symbol?) (string-append (symbol->string data) \" \")]
    [(? number?) (string-append (number->string data) \" \")]))


(define (flat-def def-lst)
  (if  (empty? def-lst)
      (list)
      (begin
        (let ([f (car def-lst)])
          (if (not (list? f))
              (cons (toString-with-space f) (flat-def (drop def-lst 1)))
              (append (list \"(\") (flat-def f) (flat-def (drop def-lst 1)) (list \")\"))))))) 

(define (lstStr->lstChars lst-str)
  (for/fold ([l empty])
     ([el (in-list lst-str)])
     (append  l (string->list el))))


(define flat (flat-def \' (define b1 :: bool (=> (and (= X x) (= Y y)) (and (= Y y) (= X x))))))
(set! flat (append  (list \"\\\"\" \"(\") flat (list  \")\" \"\\\"\"))) 
(set! flat (lstStr->lstChars flat))
(set! flat (list->string flat))
(display flat)
    

要回复问题请先登录注册