I don't quite have a destructuring define, but I did make a
destructuring bind macro.  You can check it out here:

  http://pages.cs.wisc.edu/~travitch/cynara.tar.gz

I'll put it in proper version controlled form eventually, perhaps when
I am happier with it.

It supports lists (and alists), hash tables, and records.  There is
also optional support for r6rs-clos.

It works a bit like you might expect (based on the metabang-bind
package from common lisp):

(bind (((&record fld1 fld2) (record-producing-form)))
  ;; body
)

There is also an alternate naming form:
(bind (((&record (fld1 as foo) fld2) (record-producing-form)))
  ;; body
)


Unfortunately, like most other things it lacks in documentation and polish.

On Fri, Sep 25, 2009 at 06:12:11PM -0500, Eduardo Cavazos wrote:
> Hello,
>
> My queue library has this record type:
>
>     (define-record-type queue (fields L R P))
>
> And if you look at the rest of the library, there's a whole lotta
> deconstructing going on. I.e.
>
> (define (queue-empty? q)
>     (let ((L (queue-L q))
>           (R (queue-R q))
>           (P (queue-P q)))
>       (and (stream-null? L)
>            (stream-null? R)
>            (stream-null? P))))
>
> I'd like for it to just be:
>
> (define (queue-empty? (record queue L R P))
>   (and (stream-null? L)
>        (stream-null? R)
>        (stream-null? P)))
>
> I.e. let 'define' do the deconstructing for me.
>
> It would be even more concise if there were literal syntax for records:
>
> (define (queue-empty? #queue(L R P))
>   (and (stream-null? L)
>        (stream-null? R)
>        (stream-null? P)))
>
> If anybody has something like this, lemme know!
>
> Of course, support for lists and vectors would be in order too. I.e.:
>
>     (lambda ((a b c)) ...)
>
> expects a list of three elements and
>
>     (lambda (#(a b c))
>
> expects a vector of three elements, etc.
>
> Ed

--
Tristan Ravitch
[email protected]
http://pages.cs.wisc.edu/~travitch

Attachment: pgpurhEbaHVJK.pgp
Description: PGP signature

Reply via email to