Re: [racket-users] Building regexen in at-exp

2016-11-05 Thread Eli Barzilay
On Fri, Oct 28, 2016 at 3:18 PM, 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

I see that the problem was pointed to you several times, but I didn't
see suggestions for a convenient replacement.  I often have something
like this:

#lang at-exp racket
(define px (compose pregexp string-append))   ; <--- like this
(define a "this")
@px{^@a}  ; works fine, and looks like a variant of #px"..."


[[ You can also do this for a one-time-use:

@(compose pregexp string-append){^@a}

but that's almost as bad as one of

@pregexp{@string-append{^@a}}
@pregexp[@string-append{^@a}]
(pregexp @string-append{^@a})

]]

-- 
   ((x=>x(x))(x=>x(x)))  Eli Barzilay:
   http://barzilay.org/  Maze is Life!

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


Re: [racket-users] Building regexen in at-exp

2016-10-28 Thread Vincent St-Amour
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.


[racket-users] Building regexen in at-exp

2016-10-28 Thread David Storrs
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.