[racket] selectively local-expand sub-expressions

From: Scott Klarenbach (scott at pointyhat.ca)
Date: Thu Jan 23 20:06:18 EST 2014

I'm trying use local-expand

(
http://docs.racket-lang.org/reference/stxtrans.html?q=local-expand&q=local-expand#%28def._%28%28quote._~23~25kernel%29._local-expand%29%29
)

to partially expand sub-expressions.  The only expressions I want to expand
are known in advance, I'm just having trouble coming up with an elegant
recursive algorithm for doing this.

For example:

(define (pred-a? x) (equal? x "hey"))
(define (pred-b? y) (equal? y "there"))
(define other-expr (lambda (z) (or (equal? z "you") (pred-a? z) (pred-b?
z)))

I'd like to expand other-expr like so that:

(expand other-expr) >> (lambda (z) (or (equal? z "you") (equal? z
"hey") (equal? z "there"))

local-expand sort of works, but provides either too little expansion (#f
stop-ids) whereby only the outer macro is expanded, or else it provides too
much expansion (list of stop-ids), whereby "and" and "or" etc is expanded
into let-values bindings.

What I'd like is something in between.  Rather than a "stop-list", I want
an "include-list".  I don't want or / and to expand to let-values, but I do
want any of my special nested expressions (that might be 3 levels deep in
an or clause) to expand inside the original or.

I figure this is not possible using the built-in functions, and so set out
trying to build a recursive function that would reconstruct the expression
and selectively expand the inner procedures I wish by applying local-expand
to the nested operands.

My question is:

1.) Is there a simple library way to do this with local-expand that I'm
missing?
2.) Does anyone have a hint or code example to do this manually using
recursion?  It should be simple enough but I'm embarrassed to admit how
long I've wrestled with it.

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/20140123/50cb3270/attachment.html>

Posted on the users mailing list.