I want to match one of the following two lists in Racket (formerly PLT Scheme):
'(somename : (_ptr o sometype))
or
'(somename : (_ptr io sometype))
As you can see, the only difference is the literals 'o and 'io in the embedded list.
I can see two basic ways to do this.
Either:
(match myexpr
[(list name ': (list '_ptr 'o _)) name]
[(list name ': (list '_ptr 'io _)) name]
[_ 0])
which seems like duplication of the effort, but is very clear. Or:
(match myexpr
[(list name ': (list '_ptr mode _))
(if (or (eq? mode 'o)
(eq? mode 'io))
name
0)]
[_ 0])
which avoids the almost duplicated patterns, but is much less clear.
My question is, is there a way to specify alternatives in racket pattern matching, something along the lines of {'o | 'io}? And, if not, which of the two ways outlined above would be the most idiomatic Racket way?