[racket] Unquote symbol outside quasiquote

From: Stephen Chang (stchang at ccs.neu.edu)
Date: Wed Sep 5 11:18:46 EDT 2012

(Assuming you meant to reply-all.)

Does Ryan's syntax-local-eval suggestion help you?

On Tue, Sep 4, 2012 at 4:57 PM, André Matheus <amatheus at mac.com> wrote:
> Em 04 set 2012 às 13:25, Stephen Chang <stchang at ccs.neu.edu> escreveu:
>>> I want to create a macro to get fields of an object specified by a list
>>> of
>>> symbols. Like
>>> (get-fields '(x y) obj) -> (list (get-field x obj) (get-field y obj))
>> I'm not sure you want a macro for this? Will map suffice?
>> (define (get-fields flds obj)
>> (map (λ (fld) (get-field fld obj)) flds))
> Oops, I misunderstood how to use get-field (and my example happened to
> work because I had a field named "fld" in my test example).
> Yes, you need a macro. One way to do it is to match the "quote" directly:
> (define-syntax (test stx)
> (syntax-case stx ()
> [(_ (quote (fld ...)) obj)
> #'(list (get-field fld obj) ...)]))
> Thanks for everyone who told about matching the quote, it worked like you
> said but
> then I discovered it's not what I need, I misunderstood my problem. What I
> want to
> do is have a macro that in fact takes a list of symbols and get all theses
> symbol from
> the object, like the list of symbols that field-names returns:
> (field-names obj)
> '(y x)
> I want a macro that expands like this:
> (get-fields (field-names x) obj) --> (list (get-field x obj) (get-field y
> obj))
> I don't know, maybe I'll need a function first to compute (field-names obj)
> and later
> call the macro?
> Frankly this compile-time/run-time thing is confusing me a little.
> Thanks and sorry for the confusion.

Posted on the users mailing list.