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

Re: SRFI-49 formatter somewhere?

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: http://redhog.org/PGP%20Public%20key.asc
Hi! I'm a .signature virus! Copy me into your ~/.signature to help me spread!