Suppose I have the following:
(define-type p3 x y z)
(define (with-cons c func) (func (car c) (cdr c))))
(define (with-p3 p func) (func (p3-x p) (p3-y p) (p3-z p)))
(define p (cons (make-p3 1 2 3) (make-p3 4 5 6)))
Now, ideally I want to write:
(destructure-bind (cons (p3 x1 y1 z1) (p3 x2 y2 z2)) (make-point3 (+ x1 x2) (+ y1 y2) (+ z1 z2)))
How can I do this with with-cons / with-p3? (It seems I can only go done one level of nesting).
Thanks!
On Mon, Jun 1, 2009 at 9:45 PM, David Rush kumoyuki@gmail.com wrote:
2009/6/2 lowly coder lowlycoder@huoyanjinjing.com:
are there any amcros that play well with destructuring bind of
define-type's
? I just want to check to see if there's a pre-existing solution before re-inventing my own.
I find myself writing way too much code of the form:
(define-type foo a b) (define-type bar c d)
(lambda (x) (let ((c (bar-c x) (d (bar-d x))) (let ((a (foo-a a) (b (foo-b b)) ...
This is the kind of thing where macros get over-used
(define (with-foo f body) (body (foo-a f) (foo-b f)))
david
GPG Public key at http://cyber-rush.org/drr/gpg-public-key.txt