[racket] selectively local-expand sub-expressions

From: Scott Klarenbach (scott at pointyhat.ca)
Date: Fri Jan 24 13:30:11 EST 2014

Just an update, I was able to make this work.

#lang racket
(require (for-syntax racket/syntax syntax/stx))

(define-syntax-rule (pred? x) (> 3 x))

(define-for-syntax (recursive-expand stx)
  (let loop ([l (syntax->list stx)])
(cond [(stx-null? l) l]
  [(stx-pair? (stx-car l))
   (cons (loop (stx-car l)) (loop (stx-cdr l)))]
  [(equal? 'pred? (syntax->datum (stx-car l)))
   (local-expand (cons (stx-car l) (loop (stx-cdr l))) 'expression #f)] ;;
this works
  [else
   (cons (stx-car l) (loop (stx-cdr l)))])))

(define-syntax (test stx)
  (syntax-case stx ()
[(_ x)
 (with-syntax ([expanded (recursive-expand #'x)])
   #''expanded)]))

(module+ test
  (require rackunit)
  (check-equal? (test (or (< 10 x) (pred? y)))
'(or (< 10 x) (> 3 y))))

The code I couldn't figure out last night was:
(local-expand (cons (stx-car l) (loop (stx-cdr l))) 'expression #f)]

Thanks.

-- 
Talk to you soon,

Scott Klarenbach

PointyHat Software Corp.
www.pointyhat.ca
p 604-568-4280
e scott at pointyhat.ca
200-1575 W. Georgia
Vancouver, BC V6G2V3

_______________________________________
To iterate is human; to recur, divine
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20140124/eacbd2da/attachment.html>

Posted on the users mailing list.