guile-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: advice on how to use syntax transformers


From: Federico Beffa
Subject: Re: advice on how to use syntax transformers
Date: Fri, 6 Mar 2015 17:23:13 +0100

On Fri, Mar 6, 2015 at 4:54 PM, Panicz Maciej Godek
<address@hidden> wrote:
> I think that the following code (without additional syntax transformers)
> should work for you:
>
> (define (key->value meta key)
>   (match meta
>     (() '())
>     ((((? (lambda(x) (equal? x key))) value) rest ...)
>      value)
>     (((key value) rest ...)
>      (key->value (cdr meta)))
>     (_
>      'key-not-found)))
>
> but I don't know if that answers your question.

Hi,

thanks for your reply! Indeed your function does what I need.

>
> It seems to me that you are trying to use the value of a function argument
> to construct a macro. Even if you managed to make it run somehow (which
> should be possible through some nasty hacks), it would be an abuse, because
> macros are intended to be used during macro expansion time, and not during
> runtime (Oleg Kiselyov showed how to take advantage of macros in runtime, if
> you're interested:
> http://okmij.org/ftp/Scheme/macros.html#first-class-macros).
>
> So don't interpret the code that you wrote as "a function that first defines
> syntax 'match-key' and then uses that new syntax to generate pattern
> matching code", because that's not how it works. The macro expander tries to
> substitute the usage of "match-key" macro with appropriate code immediately
> upon its usage, before you even run the function.

That is exactly the mistake I was doing in my mind.

Thanks again for your help!
Regards,
Fede



reply via email to

[Prev in Thread] Current Thread [Next in Thread]