This match binds identifiers a and b to the prefix '(0 1) and the suffix '(3 4 5) of the list:
(match '(0 1 2 3 4 5)
[`(,a ... 2 ,b ...)
(values a b)])
Another equivalent version:
(match '(0 1 2 3 4 5)
[`(,@(list a ... 2) ,b ...)
(values a b)])
How to bind an identifier (within the pattern itself) to the prefix '(0 1 2), including the delimiter?
The
apppattern, which invokes a function with the value being matched and then matches the values it returns, combined with a version ofsplitf-atthat includes the partition element in the first list instead of the second, can be used to do this:(Note the use of
(? list? ...)to make sure the value is a list before trying to call any functions that depend on that.)You can define a match extender to make it nicer-looking:
This version also includes a check to make sure the value you want to split on is actually in the list, or it'll fail to match.