[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: records

From: David Van Horn
Subject: Re: records
Date: Sun, 28 Mar 2004 13:30:49 -0500
User-agent: Mozilla/5.0 (X11; U; SunOS sun4u; en-US; rv:1.6b) Gecko/20031206 Thunderbird/0.4

Ian Zimmerman wrote:
Instead, I itch to write

(let ((foo-rtd (make-record-type "foo" 'bar 'baz)))
  (define foo? (record-predicate foo-rtd))

but this of course doesn't work because the define is local.

This is actually a Scheme FAQ:

   4.9 Is there a way to define top-level closures?

What is the idiomatic way to do this?

You could use a macro:

   (define-syntax define-with
     (syntax-rules ()
       ((define-with ((i1 v1) ...) (i2 v2) ...)
          (define i2 #f) ...
          (let ((i1 v1) ...)
            (set! i2 v2) ...)))))

Allowing you to write:

   (define-with ((foo-rtd (make-record-type "foo" 'bar 'baz)))
     (foo? (record-predicate foo-rtd))


reply via email to

[Prev in Thread] Current Thread [Next in Thread]