
I’m generating a macro which has some parts that, sometimes, need to match nothing (it’s inside an ~alt
sequence, and I want some of the alternatives to never match). The best way would be to generate no code at all, but it’s really difficult to handle syntax attributes with a #f value (need to add ~?
everywhere), so I decided to take a simpler approach and generate a pattern that will match nothing. I ended up with (~not (~or x:expr x:keyword))
, which works like a charm. Any idea about a better way to do this?

In other words, I’d like to generate a syntax object that has no effect at all and will be ignored (but can still be passed around so that the information that this particular piece of syntax should match nothing is not lost)

First thing I tried was (~seq)
, but I’m not in a head-pattern ((~alt (~seq))
does not work)

I guess the experimental templates could help me with that, but I didn’t try them yet

What I wanna do: Let’s say I have a syntax list with patterns, and sometimes #f
values: (define elements (quote-syntax ((~optional x) (~once y) #f (~once z) #f)))
I’d like to do something like (~alt (~@ . elements))
that would ignore #f
values.

My temporary solution is to replace #f
with (~not (~or x:expr x:keyword))
: (define elements (quote-syntax ((~optional x) (~once y) (~not (~or x:expr x:keyword)) (~once z) (~not (~or x:expr x:keyword)))))

Which is not what I would call “elegant”

I guess another way would be to filter out the falsy values, but that’s inconvenient

Match nothing, like {~not _}
or {~or*}
or {~fail #:when #t}
or {~between _ 0 0}
in an EH-pat position?

(~not _)
works perfectly! I should have thought about that :slightly_smiling_face:

@dcbrees has joined the channel

I thought @tt
would be interpreted same as \texttt
, but it turns out not true: my scribble code @tt{set!}
becomes \Scribtexttt{set{\hbox{\texttt{!}}}}
in the generated tex file. Why is there a \hbox
whenever I use a symbol ?
or !
?

@jerome.martin.dev I’m not sure I’m totally understanding what you’re trying to do, but {~fail}
is a pattern that always backtracks.

@oldsin Not 100% sure, but my guess is that LaTeX might be tempted to insert a line and/or space between set
and !
if the hbox
is not there.