[plt-scheme] #<undefined>

From: David Feuer (dfeuer at techhouse.org)
Date: Sat Jun 22 23:43:57 EDT 2002

On Sat, 22 Jun 2002, Matthew Flatt wrote:

> At Sat, 22 Jun 2002 22:11:54 -0400 (EDT), David Feuer wrote:
> > Would it be feasable to have something more useful than #<undefined>?
> Yes. DrScheme's Intermdiate Student language, for example, raises an
> exception when an uninitialized variable is accessed.

Raising an exception is what I was thinking of as a true letrec, though
that may not have been the best terminology.  I'm guessing you don't do it
for efficiency reasons.  See below.

> > I'm kind of curious how you
> > decided to use #<undefined>, rather than an optimized true letrec.
> I'm not sure what you mean.
> Perhaps you mean that a `letrec' binding immediate procedure
> expressions should directly generate a set of recursive closures
> (without using #<undefined> at any point). MzScheme certainly does
> that.

Yes, it should.  What I meant was why it uses #<undefined> rather than an
exception as the fallback.  Certainly it is more efficient, but it seems
also to have great potential for letting errors slip through.

What I meant by making #<undefined> more useful was encoding useful
information within it, such as the letrec variable that it was bound to,
and optionally even enough info to make a backtrace.  This way, if you

(letrec ((a
	(null? a)))

a would be bound initially to something like #<undefined a 33>
and asking if a is null will get a nice error message like

null? (line 34):
Attempted to access uninitialized letrec variable 'a' bound on line 33.

rather than silently returning false as in the current DrScheme.

Details are imaginary, but I think you should be able to get my drift now.

Even if not all primitives checked for undefinedness (null? may not be the
best example), at least the ones that can do so for free (car, cdr, +, -,
etc.)  can give more useful information to track down the error.  I would
expect this to be more efficient than an exception-raising letrec, but
have a better chance of giving a meaningful error message than the current
version.  Just a thought...


Posted on the users mailing list.