[Openmcl-devel] matching patterns
Taoufik Dachraoui
dachraoui.taoufik at gmail.com
Wed Oct 3 13:15:28 PDT 2012
I checked Fare-match and did the following comparisons:
examples from file
https://github.com/ebzzry/fare-matcher/blob/master/matcher.lisp
1. (ifmatch (cons * (cons x y)) '(1 (2 3) 4) (list x y)) :result ((2 3) (4)
*** (match '(1 (2 3) 4) ((_ . (:x . :y)) (list x y))) :result ((2 3) (4))
2. (ifmatch (like-when (cons x y) (eql x y)) '(2 . 2) x) :result 2
*** (match '(2 . 2) ((:x . :x) x)) :result 2
3. (ifmatch (and (cons x y) (when (eql x y))) '(2 . 2) x) :result 2
*** (match '(2 . 2) ((:x . :x) x)) :result 2
same as 2. I do not see the difference
4. (ifmatch (and (cons a 1) (cons 2 b)) '(2 . 1) (list a b)) :result (2 1)
*** (match '(2 . 1) ((:and (2 . :b) (:a . 1)) (list a b))) :result (2 1)
5. (ifmatch (list a b) '(1 2) (list b a)) :result (2 1)
*** (match '(1 2) ((:a :b) (list b a))) :result (2 1)
6. ((ifmatch (list* a b c) '(1 2 3 4) (list a b c)) :result (1 2 (3 4))
*** (match '(1 2 3 4) ((:a :b . :c) (list a b c))) :result (1 2 (3 4))
7. (ifmatch (and x (cons (of-type integer) *)) '(2) x) :result (2)
*** (match '(2) ((:var x ((:type integer))) x)) :result (2)
8. ((let ((res 2))
(ifmatch (cons 'reply (cons (value (+ 1 res)) (cons msg 'nil)))
'(reply 3 foo) (list res msg)))
:result '(2 FOO))
9. ((let ((res 2))
(ifmatch (list 'reply (value (+ 1 res)) msg) '(reply 3 foo)
(list res msg)))
:result '(2 FOO))
*** ?
10. ((my-length '(1 2 3)) :result 3)))
*** ?
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/b71223ff/attachment.htm>
More information about the Openmcl-devel
mailing list