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?'


Keith Wright <kwright@tiac.net> writes:

> Let's think about this for a while.  My first reaction is to object.
> 
> > From: Mikael Djurfeldt <mdj@nada.kth.se>
> > 
> > I'd like to add the following argument:
> > 
> > * If `defined?' is a special form, it is easier for a compiler or a
> >   macro expander to expand conditionals testing for existence of a
> >   binding at compilation/macro expansion time.  `defined?' could, in
> >   this respect, be used for conditional compilation.
> 
> I would like to see this worked out in more detail before I endorse it.
> In particular, conditional compilation should be based on the values
> of well-defined variables which are known at compile time, not on
> whether or not some identifer happens to already have a definition.
> How would it get a definition other than by being part of the
> program text, possibly as a result of conditional compilation?

It could be a symbol supplied by the system.  This is one common use
of `defined?'.  You want to test if some binding is available in this
interpreter/version.

It can be used in a way similar to the autoconf/#ifdef combination.

One strong argument in favour of special-form defined?, in this
respect, is compatibility with SCM.

> > In fact, I think this is such a good suggestion that I will do this
> > within a week from now, unless someone stops me.
> 
> I can't stop you, but I think flip-flopping back and forth is the
> worst possible outcome.  Before changing it back, it would be good
> to know who changed it to what it is, and why they did it.

Marius was experimenting with something called the "freezer" in
November 1996.  He discovered that `defined?' was a memoizing macro
which caused problems in the "freezer" context.  Then there was a
short discussion between Jim, Marius and me.

We had a bug, and the question was what to do about it.  The option
was whether to convert `define?' into an acro or a procedure.  There
were no particularly strong arguments raised in the discussion.  Jim
thought that functions are generally more consistent and easier to
understand.  Marius pointed out that the old `defined?' didn't respect
the expand/eval phase distinction.  I talked about implementation
issues and hadn't much more to say.

In retrospect I'd like to have considered the following things:

* Compatibility with SCM.  It is not very good that SCM has a special
  form `defined?' and Guile a procedure `defined?'.

* The procedure `defined?' is a purely eval-phase thing.  It is not
  inconsistent to have a purely expand-phase special form
  `defined?'---the macro expander is aware of what bindings are
  available.  It could in fact be useful, e.g. for conditional
  compilation.

* The special form `defined?' is more "pure" than the procedure.
  In R4RS Scheme, there was nothing in the language which said that
  variable names were symbols.  This made it easier to treat Scheme as
  other block-oriented programming languages, like Pascal.  In R5RS
  Scheme we get a connection between symbols and variables through
  `eval'.

* We can add a "dirty" `bound?' for people with blasphemous
  tendencies.  :)  In this way, we can get the best of both worlds,
  one expansion-phase construct and one eval-phase...

* The special form `defined?' fits nicely in the family
  define/undefine/defined?, as Roland pointed out.

/mdj