[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Format strings are wrong

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)
         (if space " " "")
           ((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.