[racket] getting one macro to tell another macro to define something
On Aug 1, 2014, at 8:46 PM, Alexander D. Knauth <alexander at knauth.org> wrote:
> What do you mean?
> Shouldn’t it go something like this:
> (syntax-parameterize ([current-defs (mutable-set)])
> (match-define (sender x) 1)
> (reciever)
> x)
> ; =>
> (syntax-parameterize ([current-defs (mutable-set #’(define x x3)])
> (match-define x3 1)
> (reciever)
> x)
> ; =>
> (syntax-parameterize ([current-defs (mutable-set #’(define x x3)])
> (define x3 (match 1 [x3 x3]))
I just looked at the macro stepper again and saw something similar to this: (I replaced match*/derived with match and () with [])
(define-values (x3) (match 1 [(sender x) (values x3)]))
Why doesn’t match-define reuse the expanded match pattern instead of expanding it twice?
> (reciever)
> x)
> ; =>
> (syntax-parameterize ([current-defs (mutable-set #’(define x x3)])
> (define x3 (match 1 [x3 x3]))
> (define x x3)
> x)
>
> The match-define form never defines “x” as anything, but the receiver should, right?
>
> On Aug 1, 2014, at 8:12 PM, J. Ian Johnson <ianj at ccs.neu.edu> wrote:
>
>> Ah, okay, so... this macro expander you give is fundamentally flawed because match-define does an initial parse (which uses the match expander) to get the identifiers it is going to define. So, when you expand to x3 as the match pattern, you end up returning x3 as one of the values that the match-define -> define-values is going to define. It does not ever define "x" as anything because that was just arbitrary syntax that was given to the match expander. This x3 is x3 definition leads to a use-before-initialization error.
>>
>> Do you have a different example that doesn't fail in this way?
>> -Ian
>
>
> ____________________
> Racket Users list:
> http://lists.racket-lang.org/users