[Openmcl-devel] matching patterns

Taoufik Dachraoui dachraoui.taoufik at gmail.com
Wed Oct 3 12:21:51 PDT 2012


I do not know Fare-matcher but the matcher I wrote matches types
expressions and is recursive

for example:
; the pattern (:or ((:type number) . this) _) matches a list of numbers
(match '(1 2 3)
   ((:or ((:type number) . this) _) 'ok))

also, the keyword this will match the rest of the expression using the
current pattern

Alos, it is possible to bind variables to sub-expression

(match '(a 2) ((:x :y) (list x y)) -> (a 2)

and you can add types:

(match '(a 2) (((:var x (:type symbol)) (:var y (:type integer))) (list x
y)) -> (a 2)

Another feature is that you can embed another matcher, for example:

(match '(A (2 3 4) A)
    ((_ (:var ints (:match (:or ((:type number) . this) _))) _)
       ints))
-> (2 3 4)

where _ matches any term

I found that the variables, the self reference and the embedded match adds
a lot of power
the the pattern matching

Another, we can define member? as follows:

 (defun member? (x e) (match e ((:or (:var r (x . _)) (_ . this)) r)))


I do not know if Fare-match has all this features, but I will try it

Kind regards
Taoufik

On Wed, Oct 3, 2012 at 8:47 PM, Robert Goldman <rpgoldman at sift.info> wrote:

> I don't mean to discourage you from doing this, if you like, but Faré
> already offers his Fare-matcher library for this purpose.
>
> cheers,
> r
> _______________________________________________
> Openmcl-devel mailing list
> Openmcl-devel at clozure.com
> http://clozure.com/mailman/listinfo/openmcl-devel
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.clozure.com/pipermail/openmcl-devel/attachments/20121003/61b05e74/attachment.htm>


More information about the Openmcl-devel mailing list