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

Commit

Permalink
Added list* pattern.
Browse files Browse the repository at this point in the history
  • Loading branch information
Tomohiro Matsuyama committed Apr 18, 2012
1 parent 8384037 commit 3e46aab
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 8 deletions.
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ Examples:
### Or Pattern

An or pattern matches a value that is matched with one of
PATTERNs. There is a restriction that every PATTERN of PATTERNs must
PATTERNs. There is a restriction that every pattern of PATTERNs must
have same set of variables.

Examples:
Expand Down Expand Up @@ -163,10 +163,9 @@ will be translated to
match-values values-form &body clauses

Matches the multiple values of VALUES-FORM with CLAUSES. Unlike
MATCH, CLAUSES has to be have the form of (PATTERNS . BODY), where
MATCH, CLAUSES have to have the form of (PATTERNS . BODY), where
PATTERNS is a list of patterns. The number of values that will be used
to match is determined by the maximum arity of PATTERNS among
CLAUSES.
to match is determined by the maximum arity of PATTERNS among CLAUSES.

Examples:

Expand Down
2 changes: 1 addition & 1 deletion fivepm.asd
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ Examples:
### Or Pattern
An or pattern matches a value that is matched with one of
PATTERNs. There is a restriction that every PATTERN of PATTERNs must
PATTERNs. There is a restriction that every pattern of PATTERNs must
have same set of variables.
Examples:
Expand Down
5 changes: 2 additions & 3 deletions src/match.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,9 @@ will be translated to

(defmacro match-values (values-form &body clauses)
"Matches the multiple values of VALUES-FORM with CLAUSES. Unlike
MATCH, CLAUSES has to be have the form of (PATTERNS . BODY), where
MATCH, CLAUSES have to have the form of (PATTERNS . BODY), where
PATTERNS is a list of patterns. The number of values that will be used
to match is determined by the maximum arity of PATTERNS among
CLAUSES.
to match is determined by the maximum arity of PATTERNS among CLAUSES.
Examples:
Expand Down
8 changes: 8 additions & 0 deletions src/pattern.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,14 @@ Examples:
(when args
`(cons ,(car args) (list ,@(cdr args)))))

(defpattern list* (arg &rest args)
`(cons ,arg
,(cond ((null args))
((= (length args) 1)
(car args))
(t
`(list* ,(car args) ,@(cdr args))))))

;;;
;;; Pattern Specifier Parser
;;;
Expand Down

0 comments on commit 3e46aab

Please sign in to comment.