Re: pattern-matching in LISP?



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

.



Relevant Pages

  • Re: Pattern Matching in CASs
    ... computer algebra manipulation where the user can manipulate the algebra ... the ability to interface with Mathematica and Maxima, ... defined a pattern matcher for REDUCE that is similar to the ... more work to be at the level of the SMP and Mathematica libraries. ...
    (sci.math.symbolic)
  • Re: professional package use?
    ... Yet there are numerous open source Common Lisp ... Gives folks who maybe don't have the particular mentality ... > Not everything can, or ought, to be solved with libraries. ...
    (comp.lang.lisp)
  • Re: What are your favorite portable (or mostly portable) libraries
    ... I'm particulary interested in libraries that are ... > portable between many or all Common Lisp impls. ... cl-awk - Common Lisp package with the features of AWK and more. ... cl-sql-aodbc - CLSQL database backend, ...
    (comp.lang.lisp)
  • Re: Modernizing Common Lisp
    ... Since portability is just another variant of reusability, ... The good thing about Common Lisp and its ANSI standard is that it is ... Pick out _one_ Common Lisp implementation ... implementations, libraries, applications and services, or by buying ...
    (comp.lang.lisp)
  • Re: Bipedalism in different substrates
    ... >fun since I plucked the Thanksgivin turkey! ... You're supposed to use Algis as your straight man, ... >of colleges are starting to offer alumni association online hookups either ... >public libraries have the same tie ins, and I believe that there might even ...
    (sci.anthropology.paleo)