I have a Racket list with some values (list 'foo 'bar 2 #t 42 9 2 'some)
. In reality these values follow some more specific pattern but for the question this is irrelevant. I want to test test if there are two identical values in the list, in this case the number 2, and get the element and the other elements. This is my attempt:
#lang racket
(match (list 'foo 'bar 2 #t 42 9 2 'some)
[(list-no-order a a rest ...)
"Do some stuff"]
[_ "Do some other stuff"])
The pattern is (list-no-order a a rest ...)
. But the interpretation of the program fails with:
a11: unbound identifier;
also, no #%top syntax transformer is bound in: a11
To me it looks an error when transforming the macro. If one changes list-no-order
to list
the pattern works but of course only if the elements are at the beginning of the list.
Is my pattern wrong, if so how to correct it or is the intended pattern not possible and what is the best way to work around it?
For now, the best work-around is to use a #:when
condition:
#lang racket
(match (list 'foo 'bar 2 #t 42 9 2 'some)
[(list-no-order a b rest ...)
#:when (equal? a b)
"Do some stuff"]
[_ "Do some other stuff"])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With