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

Inline list pattern #103

Open
david-a-wheeler opened this issue Oct 26, 2014 · 4 comments
Open

Inline list pattern #103

david-a-wheeler opened this issue Oct 26, 2014 · 4 comments

Comments

@david-a-wheeler
Copy link

The "list" and "list*" patterns are nice, but sometimes it's convenient to have them inline (so that the list itself doesn't need to be spliced in).

Consider adding these as built-in:

(defpattern ilist (arg)
  (when (consp arg) `(cons ,(car arg) (ilist ,(cdr arg)))))

(defpattern ilist* (arg)
   (if (null (cdr arg)) `(and ,(car arg) (type list)) `(cons ,(car arg) (ilist* ,(cdr arg)))))
@m2ym
Copy link
Owner

m2ym commented Oct 26, 2014

I don't understand how they are convenient. Are they really important for many other people?

@david-a-wheeler
Copy link
Author

If others don't find it convenient, don't worry about adding it. I just offer it as something you might consider adding. I use a shorthand for infix operators that create lists. As a result, this alternate pattern template is especially convenient when there are a lot of patterns. Trivial sampler here of the Common Lisp code is here:
https://sourceforge.net/p/readable/code/ci/develop/tree/math.slisp

@guicho271828
Copy link
Contributor

inline pattens are useful in general, not only for lists.
consider the case below, assuming we have a pattern called inline.

(defpattern skip (n)
   `(inline ,@(mapcar (constantly '_) (iota n))) ;; produces (inline _ _ _) for (skip 3)

(match x
   ((list x (skip 10) y) ...))

(match x
   ((list x _ _ _ _ _ _ _ _ _ _ y) ...))

This will save a lot of code when parsing a long list.
also beneficial when implementing array-pattern.

@guicho271828
Copy link
Contributor

This is already implemented in Trivia.

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

No branches or pull requests

3 participants