I started playing with Racket pattern matching system recently and got into a problem i can’t understand.
If i do:
(match (list 1 2 3 4 5 6 7 8 9 10 11 12)
[(list _ x y z ...) (list y ': x)])
in REPL i get
'(3 : 2)
as my desired result.
If i do:
(match (current-date)
[(date* _ x y z ...) (list y ': x)])
or
(match (date* 5 18 13 18 11 2011 5 321 #f 3600 0 "W. Europe Standard Time")
[(date* _ x y z ...) (list y ': x)])
i get this error:
match: wrong number for fields for structure date*: expected 12 but got 5 in: (_ x y z ...)
i suspect that the Kleene star ... does not work with struct type for some reason. Why is it so?
It seems that what you really want to do is match a subset of the fields in a struct, rather than actually bind the rest of the fields in the struct to (z …). In this case, you may want to try using the struct* match pattern instead.
Here’s an example: