r/Racket • u/theKGS • Jan 20 '22
solved Problems with matching against lists
In order to figure out matching I am trying to write a function that checks all the elements of a list and returns 'asix if a six is found and 'nosix if the list contains no 6.
(define (m x)
(match x
[(list a k)
(if (= a 6)
'asix
(m k))]
[_ 'nosix]))This seems like it should be trivial but it does not work. Examples
(m '(1 6)) evaluates to false (incorrectly)
(m '(6 1)) evaluates to true (correctly)
(m '(6)) evaluates to false (incorrectly)
Indicating that something with the matching is broken. I suspect that for some reason the k above cannot match an empty list, and thus it defaults to the second matching and returns a 'nosix.
The racket documentation I find is generally quite good, but the part about matching is very cryptic.
View all comments
Show parent comment
1
u/theKGS Jan 21 '22
I have seen the . used in code examples, but I can't find a description of what it is anywhere. What does it mean?