string literals that match a regexp
specifically, I want to match on identifiers that contain the /
character
Identifier is like abc
in (define abc 1)
and string literal is like "def"
in (displayln "def")
. So do you want to match against for/list
or "4 / 2 = 2"
?
#lang racket
(require syntax/parse/define)
(begin-for-syntax
(define-syntax-class my-class
(pattern x:id ; match against an id
#:do [; this is x as a symbol
(define as-symbol (syntax-e #'x))
; this is x as a string
(define as-string (symbol->string as-symbol))]
#:fail-unless
(regexp-match #px"./." as-string)
"must have / in the middle of an identifier name")))
(define-syntax-parser test
[(_ x:my-class) #''yes]
[_ #''no])
(test hello/world) ;=> yes
(test hello/world/) ;=> yes
(test hello/) ;=> no
(test hello) ;=> no
(test /hello) ;=> no
ah that’s perfect, thank you!
i wanted to match against for/list
which this does
do you guys know if ben greemans transiently typed racket is going to ship ? https://youtu.be/uAWcdD40hiI
@ben definitely plans to
integrating back into the main repo is surely a different kind of task
seems like he had a newborn according to his youtbe channel, so his hands are probably tied, also congratz btw