Another example to match a binary tree I thought is important to show what can be done with match:<div><br></div><div>(match '(a ((b c) (d e))) ((:or (:type symbol) (this this)) 'ok))</div><div>OK</div><div><br></div>
<div><div>? (match '((a b) (c)) ((:or (:type symbol) (this (:lone this))) 'ok))</div><div>OK</div></div><div><br></div><div>where (:lone pattern) means that pattern is optional</div><div><br></div><div>we can use the following keywords: :or, :and, :not, :some, :all, :lone, :var, :type, :match and this</div>
<div><br></div><div>Taoufik</div><div><br></div><div><br><div class="gmail_quote">On Wed, Oct 3, 2012 at 10:15 PM, Taoufik Dachraoui <span dir="ltr"><<a href="mailto:dachraoui.taoufik@gmail.com" target="_blank">dachraoui.taoufik@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I checked Fare-match and did the following comparisons:<div><br></div><div>examples from file <a href="https://github.com/ebzzry/fare-matcher/blob/master/matcher.lisp" target="_blank">https://github.com/ebzzry/fare-matcher/blob/master/matcher.lisp</a></div>
<div><br></div><div><div>1. (ifmatch (cons * (cons x y)) '(1 (2 3) 4) (list x y)) :result ((2 3) (4)</div><div>*** (match '(1 (2 3) 4) ((_ . (:x . :y)) (list x y))) :result ((2 3) (4))</div><div>2. (ifmatch (like-when (cons x y) (eql x y)) '(2 . 2) x) :result 2</div>
<div>*** (match '(2 . 2) ((:x . :x) x)) :result 2</div><div>3. (ifmatch (and (cons x y) (when (eql x y))) '(2 . 2) x) :result 2</div><div>*** (match '(2 . 2) ((:x . :x) x)) :result 2</div><div> same as 2. I do not see the difference</div>
<div>4. (ifmatch (and (cons a 1) (cons 2 b)) '(2 . 1) (list a b)) :result (2 1)</div><div>*** (match '(2 . 1) ((:and (2 . :b) (:a . 1)) (list a b)))<span style="white-space:pre-wrap"> </span>:result (2 1)</div>
<div>5. (ifmatch (list a b) '(1 2) (list b a)) :result (2 1)</div><div>*** (match '(1 2) ((:a :b) (list b a))) :result (2 1)</div><div>6. ((ifmatch (list* a b c) '(1 2 3 4) (list a b c)) :result (1 2 (3 4))</div>
<div>*** (match '(1 2 3 4) ((:a :b . :c) (list a b<span style="white-space:pre-wrap"> </span>c))) :result (1<span style="white-space:pre-wrap"> </span>2 (3 4))</div><div>7. (ifmatch (and x (cons (of-type integer) *)) '(2) x) :result (2)</div>
<div>*** (match '(2) ((:var x ((:type<span style="white-space:pre-wrap"> </span>integer))) x))<span style="white-space:pre-wrap"> </span>:result<span style="white-space:pre-wrap"> </span>(2)</div>
<div>8. ((let ((res 2))</div><div> (ifmatch (cons 'reply (cons (value (+ 1 res)) (cons msg 'nil)))</div><div> '(reply 3 foo) (list res msg)))</div><div><span style="white-space:pre-wrap"> </span> :result '(2 FOO))</div>
<div>9. ((let ((res 2))</div><div> (ifmatch (list 'reply (value (+ 1 res)) msg) '(reply 3 foo)</div><div> (list res msg)))</div><div> :result '(2 FOO))</div><div>*** ?</div><div>10. ((my-length '(1 2 3)) :result 3)))</div>
<div>*** ?</div><div><br></div><div>Regards</div><span class="HOEnZb"><font color="#888888"><div>Taoufik</div><br></font></span><div class="gmail_quote"><div class="im">On Wed, Oct 3, 2012 at 8:47 PM, Robert Goldman <span dir="ltr"><<a href="mailto:rpgoldman@sift.info" target="_blank">rpgoldman@sift.info</a>></span> wrote:<br>
</div><div><div class="h5"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I don't mean to discourage you from doing this, if you like, but Faré<br>
already offers his Fare-matcher library for this purpose.<br>
<br>
cheers,<br>
<div><div>r<br>
_______________________________________________<br>
Openmcl-devel mailing list<br>
<a href="mailto:Openmcl-devel@clozure.com" target="_blank">Openmcl-devel@clozure.com</a><br>
<a href="http://clozure.com/mailman/listinfo/openmcl-devel" target="_blank">http://clozure.com/mailman/listinfo/openmcl-devel</a><br>
</div></div></blockquote></div></div></div><br></div>
</blockquote></div><br></div>