need list pattern-matching advice

From: Christophe Turle (cturle_at_nospam.com)
Date: 01/26/05


Date: Wed, 26 Jan 2005 21:22:40 +0100

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.~a" 'c.turle 'wanadoo 'fr) 


Relevant Pages

  • Re: dynamic vs. static: the age-old debate
    ... How is it possible to write something in a language that does not ... only Mathematica's pattern matcher and the FreeQ ... The core of the integrator consists of four "rules". ...
    (comp.lang.misc)
  • [Expect] what if expression is cut in two by buffers end?
    ... also does not match the pattern. ... While reading output, more than 2000 bytes can force earlier bytes to be ... excessively large values can slow down the pattern matcher.) ... Maybe the mechanism of flushing the "earlier" bytes is not exactly what I ...
    (comp.lang.tcl)
  • Re: Does ANSI Common Lisp have pattern matching?
    ... I think decent pattern matching would be a welcome addition to the next ... I feel that a pattern matcher needs to ... partially evaluating the pattern matcher at compile time ...
    (comp.lang.lisp)
  • Re: Does ANSI Common Lisp have pattern matching?
    ... I end up writing a pattern matcher. ... None are as common as any of the other FPLs with pattern matching built in. ... he thinks about what should be in lisp, a language that he doesn't ...
    (comp.lang.lisp)