*@pregexp{^@a}* is read as *(pregexp "^" a)* [you can test this by
evaluating the quoted form, '*@pregexp{^@a}* ], but the function pregexp
expects a single string as its first argument (and, apparently, a function
or #f as its optional second argument).
More generally, the body part of an @-expression is read as several strings
(i.e. a list, or several arguments to a function), not a single string.
You could get what you want by writing, for example, *(pregexp @~a{^@a})*

On Fri, Oct 28, 2016 at 2:41 PM David Storrs <david.sto...@gmail.com> wrote:

> On Fri, Oct 28, 2016 at 3:24 PM, Ken MacKenzie <deviloc...@gmail.com>
> wrote:
> > In a future version of what I am working on I see regex being an
> excellent solution.  My search is against a file I load into a list at
> program initialization.  However for other parts of this to load a list
> based on a partial file filtered with regex may be a better solution.
>
> So you're doing something like "load the whole file, then search for
> all lines that start with prefix X"?
>
> You might try something like this:
>
> (define prefix #px"^foo")  ;; Construct this however you like
>
> (for ((line (file->lines "/path/to/file)))
>   (when (pregexp-match prefix l)
>       (do-the-thing-with line)))
>
> Code not tested.
> >
> > There is also the case that I eventually switch to a DB backend, but at
> prototype stage I have been skipping that.
> >
> > Sorry not an answer to your query, but I think I could make use of the
> answer so inserting myself into the thread.
> >
> > Ken
> >
> > On Friday, October 28, 2016 at 3:18:14 PM UTC-4, David K. 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.
>

-- 
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