need list pattern-matching advice
From: Christophe Turle (cturle_at_nospam.com)
Date: 01/26/05
- Next message: David Sletten: "Re: Comments requested on noob code"
- Previous message: Peter Seibel: "Re: Comments requested on noob code"
- Next in thread: Marco Antoniotti: "Re: need list pattern-matching advice"
- Reply: Marco Antoniotti: "Re: need list pattern-matching advice"
- Maybe reply: Christophe Turle: "Re: need list pattern-matching advice"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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)
- Next message: David Sletten: "Re: Comments requested on noob code"
- Previous message: Peter Seibel: "Re: Comments requested on noob code"
- Next in thread: Marco Antoniotti: "Re: need list pattern-matching advice"
- Reply: Marco Antoniotti: "Re: need list pattern-matching advice"
- Maybe reply: Christophe Turle: "Re: need list pattern-matching advice"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|