Here's an example:

#lang racket

(require (for-syntax syntax/parse))

(define-syntax (foo stx)
  (syntax-parse stx
    [(_ arg:id)
     #:when (regexp-match "[$]" (symbol->string (syntax-e #'arg)))
     #'1]
    [(_ arg) #'2]))

(foo $abc)
(foo abc)


That prints 1 followed by 2.

Sam

On Wed, Dec 9, 2020 at 12:29 PM Kevin Forchione <[email protected]> wrote:
>
> Hi guys,
> Is there a way to detect a character in a symbol in a macro so that one 
> branch of the syntax-parse would be chosen or discarded based on that?
>
> Here’s roughly what I’m getting at….
>
> #lang racket
>
> (require (for-syntax syntax/parse))
>
> (define-syntax (foo stx)
>   (syntax-parse stx
>     [(_ arg) #'(do-$ arg)]
>     [(_ arg) #'(do-other arg)]))
>
> (foo $abc)
> (foo abc)
>
> I was thinking expo/c might come into play here, but maybe there’s another 
> approach?
>
> Thanks!
>
> Kevin
>
> --
> 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 [email protected].
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/racket-users/FE7ED3FD-EAF0-4F03-8D3C-94D2092A9721%40gmail.com.

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/CAK%3DHD%2Bb%3D1iB_H7Wh0Ti2r%2BhTfDQQPJ_bTHd47ndDVkbjnvJjUA%40mail.gmail.com.

Reply via email to