To understand what's going on, consider the following program:

    #lang at-exp racket

    (define a "this")
    (define (f . l)
      (for-each displayln l))

    @f{^@a}

which prints

    ^
    this

What's going on is that the `{}` in at-exp notation will evaluate to a
list of strings. One for the "^", and one for `a`. `pregexp` accepts a
single string as argument (whereas `f` accepts as many as you want).

To make this work, you have to combine all these strings into one, as
you did using `~a`.

Vincent



On Fri, 28 Oct 2016 14:18:10 -0500,
David Storrs wrote:
> 
> tl;dr :  Why is the following an error?
> 
> #lang at-exp racket
> (define a "this")
> @pregexp{^@a}  ;; Should produce #px"^this" but errors out
> @pregexp{@(~a "^" a)}  ;; This works but is clumsy
> 
> Long version:
> 
> The at-exp language
> (http://www.greghendershott.com/2015/08/at-expressions.html and
> https://docs.racket-lang.org/scribble/reader-internals.html) allows
> for (among other things) more convenient construction of regexen, like
> so:
> 
> (pregexp "\\d\\d\\.\\d\\d") ;; base racket. Ugh.
> @pregexp{\d\d\.\d\d}      ;; at-exp...ah, much better
> 
> I started to reply to Ken MacKenzie's recent post about string
> prefixes with a suggestion that, although string-prefix was what he
> wanted in this case, a regex would be a more general solution.  When I
> went to test the code I was suggesting, I was surprised to find it
> didn't work as expected.  I thought maybe "^@" was a function or
> special form in Racket, but a quick search of the docs revealed
> nothing.  I tried various forms of quoting inside the at-exp but
> nothing worked.
> 
> What am I missing?
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to