chicken-users
[Top][All Lists]
Advanced

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

Re: [Chicken-users] records


From: felix
Subject: Re: [Chicken-users] records
Date: Mon, 02 Sep 2002 23:10:44 +0200

Peter Keller wrote:
> 
> Hello,
> 
> Suppose I do this:
> 
> (define-record foo thing bar)
> 
> Now, when I make the record:
> (make-foo 0 0)
> 
> I *have* to pass some initializations into make-foo.
> 
> My question is, is that necessary? It makes it complicated when I want
> to make some foo objects, but don't yet know all of what is going to
> go into it (or even care if all of the fields are used, even).  Sure,
> I could construct all of the fields in some let binding before calling
> make-foo, but that is sort of annoying.
> 
> It would be nice if (make-foo) just returned an undefined record foo,
> and the compiler at run time can do a check to see if I'm referencing
> a method out of foo that I have not yet set!.
> 
> Well, that's the theory anyway, the run time checking could slow down the
> implementation of the record, if that is the case I suppose you could return
> the catchall #f during the lookup of an undefined method. It is the same thing
> when looking up a nonexistant hash key in a hash table.
> 
> The place I'm using this is a symbol object for a compiler I'm writing,
> specifically the typchecker. It turns out that the symbol has to contain
> all possible things that any object in the compiled language can be, but
> not all of them are important in any given situation. For now, I've recoded
> the symbol object as a message passing style object so I don't have to
> initialize all of the fields upon creation.
> 
> Comments?

`define-record' is a rather low-level mechanism. I agree with you
that extending the record later is somewhat tedious (I come upon
the same problem sometimes). I recommend using `define-record-type'
(SRFI-9) in that case, as it provides you with a constructor that
can be defined to accept only a subset of the init-values. Additionally,
it is rather portable. 
`define-record' is a simple and efficient mechanism (and should stay
that
way, if I may say so).


cheers,
felix




reply via email to

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