Add [SIMPLE-]VECTOR* and SEQUENCE[*] patterns
I added patterns
-
[simple-]vector*which relate to[simple-]vectorlikelist*tolist -
sequence[*]which behave like the list and vector patterns but match sequences
I placed the pattern designators in the optima package, but optima.extra may be the proper place.
The second commit was necessary because I realized that, like list*, the {[simple-]vector,sequence}* patterns should require at least one argument.
Minimal unit tests and README.md changes are included.
Rebased for master changes.
Is there a reason this wasn't merged? It opens up the possibility for binary patterns as suggested in #29 too.
From his recent comment, I guess m2ym just does not have enough time to handle the merge requests (it even contains conflicts). Trivia already have those patterns, FYI.
@guicho271828 The vector* pattern in Trivia isn't actually the same. Whereas the one in this PR behaves like list*:
(match #(1 2 3 4)
((vector* a b c) (list a b c)))
;=> (1 2 #(3 4))
Trivia's vector* just ignores length mismatches:
(match #(1 2 3 4)
((vector* a b c) (list a b c)))
;=> (1 2 3)
@jorams I see. If I'm getting right, it requires creating a displaced array every time the matcher is invoked. It requires consing, and I don't really like it... Making a displaced array would be out of the scope of a pattern matcher. You know, wouldn't that be unnatural to use vector like a list? I feel it is using an inappropriate data structure.
In contrast, prefixing the access pattern is possible, see Inline pattern. Although the post mentions list pattern only, using inline pattern it is possible to implement something like a skip pattern.
(defpattern skip (n)
`(inline ,@(loop repeat n collect '_)))
(match v
((vector (skip 100) a b c) ...))
This is addressed in Trivia. https://github.com/guicho271828/trivia/blob/master/level2/arrays.lisp#L150