Skip to content
This repository has been archived by the owner on Dec 29, 2018. It is now read-only.

Add [SIMPLE-]VECTOR* and SEQUENCE[*] patterns #82

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

scymtym
Copy link
Contributor

@scymtym scymtym commented Jul 6, 2013

I added patterns

  • [simple-]vector* which relate to [simple-]vector like list* to list
  • 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.

@scymtym
Copy link
Contributor Author

scymtym commented Mar 30, 2014

Rebased for master changes.

@jorams
Copy link

jorams commented May 4, 2015

Is there a reason this wasn't merged? It opens up the possibility for binary patterns as suggested in #29 too.

@guicho271828
Copy link
Contributor

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.

@jorams
Copy link

jorams commented May 4, 2015

@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)

@guicho271828
Copy link
Contributor

@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) ...))

@guicho271828
Copy link
Contributor

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants