OSDN Git Service

joy-expression-to-string
authorsforman <sforman@hushmail.com>
Fri, 4 Aug 2023 15:14:45 +0000 (08:14 -0700)
committersforman <sforman@hushmail.com>
Fri, 4 Aug 2023 15:14:45 +0000 (08:14 -0700)
implementations/scheme-chicken/joy.scm

index d197de7..b983396 100644 (file)
 
 (define (text-to-expression text) (parse (tokenize text)))
 
-(display (text-to-expression "ab  cd [[]] 234 [true] false"))
+
+(define (joy-term-to-string term)
+  (cond ((boolean? term) (if term "true" "false"))
+        ((number? term) (->string term))
+        ((list? term) (conc "[" (joy-expression-to-string term) "]"))
+        (else term)))
+
+(define (joy-expression-to-string expr)
+  (string-intersperse (map joy-term-to-string expr) " "))
+
+
+(display (joy-expression-to-string (text-to-expression "ab  cd [[  ]] 234 [true] false")))
 (newline)