[plt-scheme] Pretty printing of expanded syntax

From: Doug Orleans (dougo at place.org)
Date: Tue Jul 26 13:54:52 EDT 2005

I have a similar function; the only thing mine has that yours doesn't
is a rule for `and':

      ((if e1 e2 (#%datum . #f))
       (syntax-case #`(and #,(unexpand-syntax #'e1)
			   #,(unexpand-syntax #'e2)) (and)
	 ((and (and e1 ...) (and e2 ...)) #'(and e1 ... e2 ...))
	 ((and (and e1 ...) e2) #'(and e1 ... e2))
	 ((and e1 (and e2 ...)) #'(and e1 e2 ...))
	 (stx #'stx)))

It's maybe a bit too aggressive in merging nested `and' expressions,
but not all of the original structure is preserved in expansion:

> (syntax-object->datum (expand #'(and x y z)))
(if (#%top . x) (if (#%top . y) (#%top . z) (#%datum . #f)) (#%datum . #f))
> (syntax-object->datum (expand #'(and x (and y z))))
(if (#%top . x) (if (#%top . y) (#%top . z) (#%datum . #f)) (#%datum . #f))

I thought I had something for `or' as well, but I guess not.  That's a
bit harder because it uses `let'.

--dougo at place.org



Posted on the users mailing list.