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

Re: Format strings are wrong

This page is part of the web mail archives of SRFI 48 from before July 7th, 2015. The new archives for SRFI 48 contain all messages, not just those from before July 7th, 2015.



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-