Thanks David,<br><br>  I actually ended up ending up a generic macro destructurer like the one you have above (except it's not hard coded to anything, it looks at the first elem of the list (whether it's a cons, a p3, a ...) then figures out how to destructure it based on that. Fairly ugly macro, but elegant to use.<br>
<br><div class="gmail_quote">On Tue, Jun 2, 2009 at 5:36 AM, David St-Hilaire <span dir="ltr"><<a href="mailto:sthilaid@iro.umontreal.ca">sthilaid@iro.umontreal.ca</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div class="im">lowly coder wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Suppose I have the following:<br>
<br>
(define-type p3 x y z)<br>
<br>
(define (with-cons c func) (func (car c) (cdr c))))<br>
<br>
(define (with-p3 p func) (func (p3-x p) (p3-y p) (p3-z p)))<br>
<br>
(define p (cons (make-p3 1 2 3) (make-p3 4 5 6)))<br>
<br>
Now, ideally I want to write:<br>
<br>
(destructure-bind (cons (p3 x1 y1 z1) (p3 x2 y2 z2))<br>
  (make-point3 (+ x1 x2) (+ y1 y2) (+ z1 z2)))<br>
<br>
How can I do this with with-cons / with-p3? (It seems I can only go done one level of nesting).<br>
</blockquote></div>
I think you might want to investigate time into using an object system with generic functions... Gambit's define-type is juste a raw data container with not much meat around it...<br>
<br>
That said, if the usage your mentionning is just want you want to do, then you can hardcode the macro for pairs of p3 objects:<br>
<br>
(define-macro (destructure-bind pair-p3 . body)<br>
   (let ((arg (gensym 'arg))<br>
     (p1 (gensym 'p1))<br>
     (p2 (gensym 'p2)))<br>
     `(let* ((,arg ,pair-p3)<br>
         (,p1 (car ,arg))<br>
         (,p2 (cdr ,arg))<br>
         (x1 (p3-x ,p1))<br>
         (y1 (p3-y ,p1))<br>
         (z1 (p3-z ,p1))<br>
         (x2 (p3-x ,p2))<br>
         (y2 (p3-y ,p2))<br>
         (z2 (p3-z ,p2)))<br>
    ,@body)))<br>
<br>
> (destructure-bind (cons (make-p3 1 2 3) (make-p3 4 5 6))<br>
           (make-p3 (+ x1 x2) (+ y1 y2) (+ z1 z2)))<br>
<br>
#<p3 #6 x: 5 y: 7 z: 9><br>
<br>
I hope it can help you...<br><font color="#888888">
<br>
David<br>
</font></blockquote></div><br>