Recently, I started playing with the Racket pattern matching system and got into a problem that I cannot 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.
(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 Klein star ...for some reason does not work with the structural type. Why is this so?
...
It seems that what you really want to do is map a subset of the fields in the structure, and not bind the remaining fields in the structure to (z ...). In this case, you can try using the struct * matching pattern .
Here is an example:
(match (date* 5 18 13 18 11 2011 5 321 #f 3600 0 "W. Europe Standard Time") [(struct* date ([minute x] [hour y])) (list y ': x)])
, Kleene ... - .
. ... ..k ___ __k , list -matching hash-table -matching . , , lvp ( pat, pat ... ) , pat.
..k
___
__k
list
hash-table
lvp
pat
?
, ... - - , . , , ... - β , - β , , . , .