jerome.martin.dev
2019-4-7 12:22:46

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?


jerome.martin.dev
2019-4-7 12:25:48

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)


jerome.martin.dev
2019-4-7 12:28:32

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


jerome.martin.dev
2019-4-7 12:31:48

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


jerome.martin.dev
2019-4-7 12:34:51

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.


jerome.martin.dev
2019-4-7 12:37:04

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


jerome.martin.dev
2019-4-7 12:37:42

Which is not what I would call “elegant”


jerome.martin.dev
2019-4-7 12:40:24

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


alexknauth
2019-4-7 13:08:57

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


jerome.martin.dev
2019-4-7 13:12:58

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


dcbrees
2019-4-7 17:45:05

@dcbrees has joined the channel


oldsin
2019-4-8 01:18:42

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 !?


lexi.lambda
2019-4-8 03:06:04

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


soegaard2
2019-4-8 04:47:28

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