Re: pattern-matching in LISP?



Chris Schumacher <kensu__@xxxxxxxxxxx> writes:

I noticed that in the functional language ML there is a way to break a
function's input into various forms in the function header.
For instance:
split(a::b::c) (where :: is ML's equivalent of cons)
This also allows an interesting kind of function overloading where you can
contain several function definitions in a single declaration, each keyed by
the format of the input.
I attempted to do something similar in LISP, using:
defun ( split (cons A B) )

But it didn't appear to work. Does LISP have pattern-matching capabilities
as well?

It's not built in per se, with some modest exceptions.

The reasons are subtle and varied, by the way. I don't recall this issue
coming up for a per se vote in any design forum I participated in, but I
suspect because people knew there were opinions all over the map on this,
and it would be better to leave to users to have competing packages. Here
are some issues that relate to that:

* Lisp allows for dynamic redefinition. Programs can construct and evaluate
and run new code dynamically at runtime, including redefining themselves.
If you have a definition that is in parts, there are issues of what part
gets redefined and what does not, etc.
(This issue comes up for DEFMETHOD, too, so the issue is not insurmountable.
But it's non-trivial and requires a lot of work to get the detailing right.
The CL standard was mostly constructed of things where people had already
done and long-tested such detailing and there as a well accepted result.
This is not such a case, so is not standardized.)

* Some of the issues are to do with the difference between static types
and dynamic types. You'd have to understand that these are different
in Lisp than in a static language, and that there are consequent
differences in what constitutes a match.

See my article http://www.nhplace.com/kent/PS/EQUAL.html for some
thoughts on this issue.

I'd be sad if it didn't, because I like LISP a lot more than ML. :)

Don't be too sad. Language extension in Lisp is not like building
your own kernel in Unix. Rather, it's a routine operation that is
done compatibly with other programs and routinely by ordinary users.

Incidentally, I bet it's easier to write as an extension to Lisp than
it would be to extend ML to accommodate many of the things Lisp has
that ML doesn't.

Give it a shot. I'm sure a lot of people here will help with ideas and
advice.
.



Relevant Pages

  • Re: Rolling out updates to a live CL server
    ... But I'm quite sure Common Lisp ... source file, I compile the source file and ship the .fasl to the ... Lisp can be redefined in such a way that the redefinition is seen by all ... Common Lisp Document Repository:http://cdr.eurolisp.org ...
    (comp.lang.lisp)
  • Re: Ada Popularity: Comparison of Ada/Charles with C++ STL (and Perl)
    ... "Randy Brukardt" writes: ... > allowed redefinition of some of the operations ... the Ada given that is more checked or "safe" than in the Lisp examples. ... 'j' - a n t h o n y at romeo/charley/november com ...
    (comp.lang.ada)