> On Nov 25, 2015, at 2:51 AM, Thomas Lynch
> <[email protected]> wrote:
>
> Wolfram language has a feature where predicates or head value checks can be
> added to a pattern. These occur after the
> _ or other pattern match operator.
>
> Now I'm looking at syntax-parse and I see that adding a x:id , for example
> will check that x is an id. That makes the colon an operator.
Not really, because syntax-parse looks for identifiers with names that contain
colon as a special case.
> It also looks like it is going to mess up code that does such thing as using
> prefix on require, where that prefix is followed by a colon. The lex docs,
> for example, show this.
>
> Shouldn't this be (x id) rather than x:id ? As a case of (x predicate).
>
There is the option to use (~var x id) and (~literal lit-id), which you might
have to use when making a macro that expands to a syntax-parse expression. If
you want programs that make the most explicit sense possible, (~var x id) is
better, but if you want programs that are convenient and readable, x:id looks
better.
This means that you can still use syntax classes when they have prefixes with
colons, for example:
#lang racket
(require (only-in syntax/parse ~literal ~var)
(prefix-in rkt: racket/base)
(prefix-in stxparse: syntax/parse))
(syntax->datum
(stxparse:syntax-parse #'(define x 3)
[((~literal rkt:define) (~var x stxparse:id) (~var v stxparse:expr))
#'(define-values [x] v)]))
So syntax/parse doesn't apply the colon special case within the ~var form or
the ~literal form.
Although actually this works too:
#lang racket
(require (only-in syntax/parse ~literal ~var)
(prefix-in rkt: racket/base)
(prefix-in stxparse: syntax/parse))
(syntax->datum
(stxparse:syntax-parse #'(define x 3) #:literals (rkt:define)
[(rkt:define x:stxparse:id v:stxparse:expr)
#'(define-values [x] v)]))
Alex Knauth
--
You received this message because you are subscribed to the Google Groups
"Racket Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/racket-dev/1B03300F-7A7A-4790-9A2A-BC59CBC2B70A%40knauth.org.
For more options, visit https://groups.google.com/d/optout.