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>
<br>Thanks!<br><br><br><br><div class="gmail_quote">On Mon, Jun 1, 2009 at 9:45 PM, David Rush <span dir="ltr"><<a href="mailto:kumoyuki@gmail.com">kumoyuki@gmail.com</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;">
2009/6/2 lowly coder <<a href="mailto:lowlycoder@huoyanjinjing.com">lowlycoder@huoyanjinjing.com</a>>:<br>
<div><div></div><div class="h5">> are there any amcros that play well with destructuring bind of define-type's<br>
> ? I just want to check to see if there's a pre-existing solution before<br>
> re-inventing my own.<br>
><br>
> I find myself writing way too much code of the form:<br>
><br>
> (define-type foo a b)<br>
> (define-type bar c d)<br>
><br>
> (lambda (x)<br>
>   (let ((c (bar-c x) (d (bar-d x)))<br>
>     (let ((a (foo-a a) (b (foo-b b)) ...<br>
<br>
</div></div>This is the kind of thing where macros get over-used<br>
<br>
(define (with-foo f body) (body (foo-a f) (foo-b f)))<br>
<br>
david<br>
<font color="#888888">--<br>
GPG Public key at <a href="http://cyber-rush.org/drr/gpg-public-key.txt" target="_blank">http://cyber-rush.org/drr/gpg-public-key.txt</a><br>
</font></blockquote></div><br>