Re: [racket] selectively local-expand sub-expressions

2014-01-26 Thread Carl Eastlund
Oh, and note that I changed define-dsl-syntax to _not_ use define-syntax-rule. That's important, if you're going to use the value of variables used in macro expansion. The define-syntax-rule form protects its output; you can't disassemble it and then run parts of the result. You can print them,

Re: [racket] selectively local-expand sub-expressions

2014-01-26 Thread Carl Eastlund
You can do it like this: https://gist.github.com/carl-eastlund/8640925 Basically, you quasiquote the result of the expansion, and then you unquote variables when you hit them so that they are evaluated normally. Anything with an unbound variable will fail at expansion time. Carl Eastlund On

Re: [racket] selectively local-expand sub-expressions

2014-01-26 Thread Scott Klarenbach
Sorry, I was combining all the examples into one for brevity. x has 2 possible bindings (one in the module and one in the macro), y is bound in the module and closes over the macro, and z is unbound and therefore should result in an error since nothing can be done with it. ;; example 1 (as per ou

Re: [racket] selectively local-expand sub-expressions

2014-01-26 Thread Carl Eastlund
Scott -- I don't understand exactly what you're asking, at least not based on the example you wrote. You defined x and y, but the error is about z. Is this just a typo? Or are you expecting a value for z to come from somewhere? Carl Eastlund On Sun, Jan 26, 2014 at 1:01 PM, Scott Klarenbach wr

Re: [racket] selectively local-expand sub-expressions

2014-01-26 Thread Scott Klarenbach
Thanks a lot Carl...this is very enlightening. If I could impose one last question before I go off and digest everything: What is the "correct" approach to capturing the runtime values of any references that may be bound by the enclosing environment, for splicing into the final recursively-expand

Re: [racket] selectively local-expand sub-expressions

2014-01-25 Thread Carl Eastlund
Scott, I see what you're doing now. You're not actually trying to use macro expansion at all; you're just using local-expand to substitute the definition of pred? where it occurs, so that you can make its macro definition also serve as its DSL definition. That's sensible, but local-expand is sti

Re: [racket] selectively local-expand sub-expressions

2014-01-24 Thread Scott Klarenbach
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-

Re: [racket] selectively local-expand sub-expressions

2014-01-23 Thread Scott Klarenbach
Carl, Don't panic :). I'm not trying to reuse the expanded syntax at runtime. I'm just trying to parse it out for my own purposes in the context of a dsl that I fully control. I'm happy to strip all context and just have a list of symbols if need-be. My problem is much simpler, in that I wish

Re: [racket] selectively local-expand sub-expressions

2014-01-23 Thread Carl Eastlund
Scott, What you're doing isn't possible -- isn't even meaningful -- in general. You want to expand (MACRO-NAME (pred-a? z) (pred-b? z)) into (MACRO-NAME (equal? z "hey") (equal? z "there")) for some arbitrary MACRO-NAME you haven't listed. That's not at all safe! For instance, you did it with th

[racket] selectively local-expand sub-expressions

2014-01-23 Thread Scott Klarenbach
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 comi