<div>Hi</div><div><br></div><div>I renamed the macro with-match-destruc to destructuring-match because</div><div>it is very close to the CL macro destructuring-bind with 2 differences:</div><div><br></div><div>1. addition of types</div>
<div>2. the macro returns nil if there is no match; this property</div><div>allow us to match a sequence against a list of pattern alternatives.</div><div><br></div><div>I created a macro cond-match that mimics the cond macro</div>
<div>and can be used as follows:</div><div><br></div><div>? (cond-match (2 3 4)</div><div>    ((a b (:type c 'symbol)) (list (+ a b) c))</div><div>    ((a b (:type c 'number)) (list (+ a b c))))</div><div>;Compiler warnings :</div>
<div>;   In an anonymous lambda form: Unused lexical variable #:G3852</div><div>;   In an anonymous lambda form: Unused lexical variable #:G3859</div><div>(9)</div><div><br></div><div>||#</div><div><br></div><div>(defmacro cond-match (seq &rest conds)</div>
<div>  (let ((x (gensym)))</div><div>    (cond </div><div>      ((null conds) nil)</div><div>      (t</div><div>       `(let ((,x (destructuring-match ,(caar conds) ',seq</div><div><span class="Apple-tab-span" style="white-space:pre">              </span>    ,@(cdar conds))))</div>
<div><span class="Apple-tab-span" style="white-space:pre">      </span> (if (not (null ,x)) ,x</div><div><span class="Apple-tab-span" style="white-space:pre">      </span>     (cond-match ,seq ,@(cdr conds))))))))</div><div><br></div>
<div>Kind regards</div><div>Taoufik</div><div><br></div><br><div class="gmail_quote">On Mon, Dec 6, 2010 at 11:38 PM, Daniel Weinreb <span dir="ltr"><<a href="mailto:dlw@itasoftware.com">dlw@itasoftware.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">


  

<div bgcolor="#ffffff" text="#000000">
Greg,<br>
<br>
This may be of no importance, but: unification is<br>
a very powerful mechanism.  If one is using<br>
cl-unification to do simple things like<br>
what defmacro does, is it reasonably fast?<br>
<br>
-- Dan<br>
<br>
Greg Pfeil wrote:
<blockquote type="cite"><div><div></div><div class="h5">
  <pre>On 4 Dec 2010, at 8:02, Taoufik Dachraoui wrote:

  </pre>
  <blockquote type="cite">
    <pre>Hello

I wrote a matching pattern function and would like to share in order
to improve it (remove the compiler warnings for example, see below).

I started with the destruc function found in onLisp book by Paul Graham.
    </pre>
  </blockquote>
  <pre>I don't recall if it has any type restrictions, but I tend to use CL Unification (<a href="http://common-lisp.net/project/cl-unification/" target="_blank">http://common-lisp.net/project/cl-unification/</a>) for pattern matching stuff.

  </pre>
  <blockquote type="cite">
    <pre>Any matching symbol x can be typed  and must be of the form (:type x #'name)
where name is a boolean function with one argument (eg. numberp, consp, symbolp, 
atom, ...)
    </pre>
  </blockquote>
  </div></div><pre>Why not have the form be (:type var typename), like (:type x '(integer 0 9))? Then you get much finer control without having to define unary functions for every type you care about. Should be able to just replace (funcall ,(third pat) (car ,seq)) with (typep (car ,seq) ,(third pat)) and you're golden.
_______________________________________________
Openmcl-devel mailing list
<a href="mailto:Openmcl-devel@clozure.com" target="_blank">Openmcl-devel@clozure.com</a>
<a href="http://clozure.com/mailman/listinfo/openmcl-devel" target="_blank">http://clozure.com/mailman/listinfo/openmcl-devel</a>
  </pre>
</blockquote>
</div>

</blockquote></div><br>