Eduardo Cavazos wrote:

 >> 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.

Tristan Ravitch wrote:

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

Eduardo Cavazos wrote:

Wow, this is very nice! I'm glad I asked! Thanks!

queue-empty? using bind is:

(define (queue-empty?* q)
  (bind (((&record L R P) q))
        (and (stream-null? L)
             (stream-null? R)
             (stream-null? P))))

Going further, and building on Tristan's 'bind', it's possible to have a macro that allows for the first syntax I hinted at. Here's a working definition of queue-empty? :

(def (queue-empty? (&record L R P))
  (and (stream-null? L)
       (stream-null? R)
       (stream-null? P)))

Another example; a procedure that reverses a two element list:

(def (swap (&list a b))
  (list b a))

'def' is:

(import (cynara bind))

(define-syntax def
  (lambda (stx)
    (syntax-case stx ()
      ((def (f p ...) body ...)
       (with-syntax (((x ...) (generate-temporaries (syntax (p ...)))))
          (syntax
           (define (f x ...)
             (bind ((p x) ...)
                   body
                   ...))))))))

Ed

Reply via email to