Re: Format strings are wrong
Paul Schlie 27 Dec 2003 16:21 UTC
For the hell of it, now correctly formats embedded character and string
constants within lists when formatted into basic displayable strings:
(module string mzscheme
(provide (rename new-string string))
(define (new-string . params)
(letrec ((loop (lambda (val rest lst space)
(string-append
(if space " " "")
(cond
((number? val) (number->string val))
((symbol? val) (symbol->string val))
((string? val) (string-append (if lst "\"" "")
val (if lst "\"" "")))
((char? val) (string-append (if lst "#\\" "") (string val)))
((list? val) (string-append
"(" (loop (car val) '() #t #f)
(if (pair? (cdr val))
(loop (cadr val) (cddr val) #t #t) "") ")" ))
(else (error 'string)))
(if (pair? rest) (loop (car rest) (cdr rest) lst space) "")))))
(loop (car params) (cdr params) #f #f))))
Although suspect it could be coded a more efficiently.
-paul-