From: Christophe Turle
Subject: need list pattern-matching advice
Date: 
Message-ID: <41f7fc12$0$16618$636a15ce@news.free.fr>
Hi all,

Always doing list pattern matching with Lisp over and over, so i think it's 
time Lisp do it for me ;-)

I checked some pattern matcher but each time it appears that variables are 
mixed with the pattern. i find it difficult to read them and to extend the 
matcher.

So the idea is to separate pattern from the references (here accessed via 
accessors)
The goal was readability and declarativity.

;; used in stml an sexp html
(def-type element
  :pattern (list
             (a symbol)
             (spliced (serie (a keyword) (a symbol)))
             (spliced (serie (or (a string) (a element)))) )
  :accessors (element-tag     (the symbol)
              element-avs     (first serie)
              element-content (second serie) ))

so after i can :

((lambda (x)
   (print (element-tag x))
   (print (element-avs x))
   (print (element-content x)) )
 '(img :src "picture.jpg" :width "400" :height "400" "really " (p "strange 
?")) )
=>
img
(:src "picture.jpg" :width "400" :height "400")
("really " (p "strange ?"))


Similar functions for anonymous pattern matching should also be implemented.


I have started implementation :

(make-accessor '(list toto (serie (a attr) (a value)) tata) '(the serie))
=> (lambda (x) (identity (nth 1 x)))


any comments before going into the wall or re-inventing the wheel ;) ?

Is there an implementation/theory somewhere with a similar idea ?


-- 
___________________________________________________________
Christophe Turle.
sava preview http://perso.wanadoo.fr/turle/lisp/sava.html
(format nil ยทยทยท@~a.~a" 'c.turle 'wanadoo 'fr) 
From: Marco Antoniotti
Subject: Re: need list pattern-matching advice
Date: 
Message-ID: <1adKd.4$fp1.14142@typhoon.nyu.edu>
You may have a look at CL-UNIFICATION (shameless plug) in 
common-lisp.net.  It seems it will do all you need and more.  Comments 
and bug reports welcome.

Cheers

Marco




Christophe Turle wrote:
> Hi all,
> 
> Always doing list pattern matching with Lisp over and over, so i think it's 
> time Lisp do it for me ;-)
> 
> I checked some pattern matcher but each time it appears that variables are 
> mixed with the pattern. i find it difficult to read them and to extend the 
> matcher.
> 
> So the idea is to separate pattern from the references (here accessed via 
> accessors)
> The goal was readability and declarativity.
> 
> ;; used in stml an sexp html
> (def-type element
>   :pattern (list
>              (a symbol)
>              (spliced (serie (a keyword) (a symbol)))
>              (spliced (serie (or (a string) (a element)))) )
>   :accessors (element-tag     (the symbol)
>               element-avs     (first serie)
>               element-content (second serie) ))
> 
> so after i can :
> 
> ((lambda (x)
>    (print (element-tag x))
>    (print (element-avs x))
>    (print (element-content x)) )
>  '(img :src "picture.jpg" :width "400" :height "400" "really " (p "strange 
> ?")) )
> =>
> img
> (:src "picture.jpg" :width "400" :height "400")
> ("really " (p "strange ?"))
> 
> 
> Similar functions for anonymous pattern matching should also be implemented.
> 
> 
> I have started implementation :
> 
> (make-accessor '(list toto (serie (a attr) (a value)) tata) '(the serie))
> => (lambda (x) (identity (nth 1 x)))
> 
> 
> any comments before going into the wall or re-inventing the wheel ;) ?
> 
> Is there an implementation/theory somewhere with a similar idea ?


(unify:matching