Re: pattern-matching in LISP?
- From: Matthias Benkard <mulkiatsch@xxxxxxxxx>
- Date: 29 Apr 2007 01:33:06 -0700
Hi,
But it didn't appear to work. Does LISP have pattern-matching capabilities
as well?
I certainly don't want to keep you from having some fun implementing
your own pattern matcher in Common Lisp, but there are some libraries
readily available that you might be interested in.
First, there is CL-Unification: http://common-lisp.net/project/cl-unification/
CL-USER> (unify:match-case ('(1 2 3 4))
((?x ?y . ?z) (values 'yes (+ x y) z))
(?x (values 'no x)))
YES
3
(3 4)
CL-USER> (unify:match-case ('(1))
((?x ?y . ?z) (values 'yes (+ x y) z))
(?x (values 'no x)))
NO
(1)
Second, Faré Ridaeu's matching library, fare-matcher: http://www.cliki.net/fare-matcher
CL-USER> (fare-matcher:match '(1 2 3 4)
((list* x y z) (values 'yes (+ x y) z))
(x (values 'no x)))
YES
3
(3 4)
CL-USER> (fare-matcher:match '(1)
((list* x y z) (values 'yes (+ x y) z))
(x (values 'no x)))
NO
(1)
Third, the pattern matcher included in the ARNESI library:
http://common-lisp.net/project/bese/arnesi.html
CL-USER> (arnesi:match-case '(1 2 3 4)
((:list* x y z) (values 'yes (+ x y) z))
(x (values 'no x)))
YES
3
(3 4)
CL-USER> (arnesi:match-case '(1)
((:list* x y z) (values 'yes (+ x y) z))
(x (values 'no x)))
NO
(1)
Finally, I just stumbled upon MCPat, but I don't really know what
exactly it's supposed to be and how to use it: http://www.sfmishras.com/smishra/mcpat/
As I haven't actually used any of these libraries, I can't make a
recommendation. Just choose the one which looks the nicest to you or
whatever. :)
Bye-bye,
Matthias
.
- References:
- pattern-matching in LISP?
- From: Chris Schumacher
- pattern-matching in LISP?
- Prev by Date: like linj
- Next by Date: Re: What are the domains that lisp doesn't fit int?
- Previous by thread: Re: pattern-matching in LISP?
- Next by thread: Re: pattern-matching in LISP?
- Index(es):
Relevant Pages
|