[plt-scheme] Pretty printing of expanded syntax

From: Jens Axel Søgaard (jensaxel at soegaard.net)
Date: Tue Jul 26 19:59:04 EDT 2005

Hi Doug,

> 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:
...
> I thought I had something for `or' as well, but I guess not.  That's a
> bit harder because it uses `let'.

Thanks for the suggestion. I have added the following rules to
get AND and OR back in the unexpanded version.

     ; AND
     [(if e1 e2 (#%datum . #f))
      (pe #`(and #,(pe #'e1) #,(pe #'e2)))]
     [(and e1 ... (and e2 ...))
      (pe #'(and e1 ... e2 ...))]
     [(and (and e1 ...) e2 ...)
      (pe #'(and e1 ... e2 ...))]
     [(and expr ...)
      #`(and #,@(pe* #'(expr ...)))]

     ; OR
     [(let-values (((or-part1) x)) (if or-part2 or-part3 y))
      (and (and (identifier? #'or-part2)
                (identifier? #'or-part3))
           (eq? (syntax-e #'or-part1) (syntax-e #'or-part2))
           (eq? (syntax-e #'or-part2) (syntax-e #'or-part3)))
      (pe #`(or #,(pe #'x) #,(pe #'y)))]
     [(or expr1 ... (or expr2 ...))
      (pe #'(or expr1 ... expr2 ...))]
     [(or (or expr1 ...) expr2 ...)
      (pe #'(or expr1 ... expr2 ...))]
     [(or expr ...)
      #`(or #,@(pe* #'(expr ...)))]

The new version is attached - more suggestions are welcome.

-- 
Jens Axel Søgaard
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: pp-syntax.scm
URL: <http://lists.racket-lang.org/users/archive/attachments/20050727/45288d9e/attachment.ksh>

Posted on the users mailing list.