This is the mail archive of the guile@cygnus.com mailing list for the guile project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Reintroducing old `defined?' (was Re: Testing availabilty of a procedure)


Mikael Djurfeldt <mdj@nada.kth.se> writes:

> Marius Vollmer <mvo@zagadka.ping.de> writes:
> 
> > Is this what we want?  Or should it check local bindings as well (for
> > the benefit of macros)?
> 
> My opinion: If `defined?' is a special form it can and should check
> local bindings as well.

Agreed.

> Not.  (Motivation: `defined?' is sometimes used in situations where
> the set of available bindings change.)

I agree about the semanticas, but not about the performance.  I think
it should be memoizing when it finds a local binding.  That is, it
memoizes to `#t' when the symbol is found in the inner frames of the
lexical environment, but it memoizes to some code that does the lookup
each time when the symbol is not found or is found in the top-level
environment.

For example

    (let ((foo 42))
      (if (defined? foo) foo #f))

should memoize to

    (let ((foo 42))
      (if #t foo #f))

The compiler can then do its thing, as you explain below.  The
assumtion here is that the set of local bindings does not change.  I'm
not sure if there isn't some obscure

But this:

    (define (the-answer)
      (if (defined? foo) foo #f))

should memoize into something like

    (define (the-answer)
      (if (module-defined? (the-lexical-module) 'foo) foo #f))


and (the-lexical-module) would be a special form that returns whatever
module was the (current-module) when the (define ...) form was
evaluated. [Do we have such a thing?]

> When a module is compiled, it is determined which bindings are
> available.  Therefore the macro `defined?' can safely be expanded into
> a boolean constant, which is easy for the compiler to treat in a
> standard way.

Hmm, I think this contradicts your don't-memoize opinion above,
doesn't it?

> This means that the compiler needs no special knowledge.

I think it needs special knowledge of `defined?' anyway because
`defined?' is not a simple macro that expands into self-contained
Scheme code.  The module/environment thing at compile-time is probably
very different from the one used for the interpreter.  The compiler
write should not be constrained to use the same representation for
environments as the interpreter.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]