chicken-users
[Top][All Lists]
Advanced

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

Re: [Chicken-users] Irregex - inserting variables into an SRE?


From: Peter Bex
Subject: Re: [Chicken-users] Irregex - inserting variables into an SRE?
Date: Sun, 27 Sep 2015 19:09:17 +0200
User-agent: Mutt/1.5.21 (2010-09-15)

On Sun, Sep 27, 2015 at 11:33:26AM +0000, Tim Gallant wrote:
> Hi All,
> 
> I'm attempting to create a mustache template parser using the irregex
> library. I have the following code:
> 
>  (irregex-fold
> '(: open-tag (*? (~ #\>)) close-tag)
> ... )
> 
> open-tag and close-tag are variables I have defined in scope. SREs have
> their own keywords defined so it just barfs saying open-tag/close-tag
> aren't valid keywords.

Hi Tim,

This is to be expected; you're quoting the expression, after all.
Because the entire expression is quoted, it'll see the _symbol_
open-tag, rather than the value of the identifier represented by
that symbol.

Basically, you have:

(irregex-fold (list ': 'open-tag (list '*? (list '~ #\>)) 'close-tag) ...)

While you want:

(irregex-fold (list ': open-tag (list '*? (list '~ #\>)) close-tag) ...)

The above code would work, but it's rather ugly, so there's a shortcut:
instead of quoting the expression, you can quasiquote the expression.
This adds an "escape hatch" so you have a quoted list with values that
you can selectively have evaluated:

(irregex-fold `(: ,open-tag (*? (~ #\>)) ,close-tag) ...)

This just says that open-tag and close-tag should be evaluated: it should
use the _value_ of the identifier instead of the literal symbol.

I hope my explanation was clear to you.  It's a bit tricky to explain :)

Cheers,
Peter

Attachment: signature.asc
Description: Digital signature


reply via email to

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