joy-expression-to-string

This commit is contained in:
sforman 2023-08-04 08:14:45 -07:00
parent 35ffe71482
commit ea60a04d96
1 changed files with 12 additions and 1 deletions

View File

@ -44,6 +44,17 @@
(define (text-to-expression text) (parse (tokenize text))) (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) (newline)