Email list hosting service & mailing list manager

Re: SRFI-49 formatter somewhere? redhog@xxxxxx (01 Dec 2003 23:37 UTC)
SRFI-49 formatter somewhere? Sven.Hartrumpf@xxxxxx (01 Dec 2003 21:41 UTC)
Re: SRFI-49 formatter somewhere?

Re: SRFI-49 formatter somewhere? redhog@xxxxxx 01 Dec 2003 23:37 UTC

A naive formatter should be quite trivial to write. However, one that
is smart when choosing what to format as S-expressions and what to
format as I-expresions, is quite a bit trickier... Hm, now I just
couldn't get to sleep, so I wrote one instaed (it i very naive, but

(define (iformat-head msg)
  (define (iformat-head sep msg)
    (if (and (pair? msg)
	     (not (pair? (car msg))))
	(let ((sl (iformat-head " " (cdr msg))))
	    #f "~A~A~A"
	    sep (car msg) (car sl))
	   (cdr sl)))
	(cons "" msg)))
  (iformat-head "" msg))

(define (iformat-body ind msg)
   ((null? msg)
   ((pair? msg)
     (iformat ind (car msg))
     (iformat-body ind (cdr msg))))
     #f "~A.\n~A" ind
     (iformat ind msg)))))

(define (iformat ind msg)
  (if (not (pair? msg))
      (format #f "~A~A\n" ind msg)
      (let ((sl (iformat-head msg)))
	 #f "~A~A\n~A"
	 (if (equal? (car sl) "")
	     (car sl))
	 (iformat-body (string-append ind " ") (cdr sl))))))

GPG Public key:
Hi! I'm a .signature virus! Copy me into your ~/.signature to help me spread!