Re: 'defined?' behaves differently in SCM 4e1 and Guile 1.3a.pre2

Marius Vollmer (mvo@zagadka.ping.de)
25 Oct 1997 11:42:31 +0200

Jim Blandy <jimb@red-bean.com> writes:

> >This can't be deliberate decision, can it?
>
> A semi-deliberate decision, if I recall correctly.

Yep, I tried to do something reasonable, but failed, as it seems.

In the beginning, `defined?' was a memoizing macro. It was only
really evaluated the first time and then the result of that evaluation
(either `#t' or `#f') was substituted for the source expression.

I felt that this was wrong and proposed to change `defined?' into a
core syntactic form (an `acro', as it is called, I think). I should
have stopped there, but for reasons I can't recall completely, I then
went on and wanted to change `defined?' to a function.

You might want to read the thread titled

"defined?" wants to be an `acro' (and not a macro)

in the mailing list archive.

Ok now, `defined?' seems to be important for writing portable programs
(portable between SCM and Guile, that is) and we should therefore make
Guile's `defined?' compatible with SCM's.

SCM's `defined?` is now a acro, if I remember correctly.

> 1) DEFINED? should be a procedure, which takes an environment value
> (e.g., a module object) and a symbol, and tells you whether that
> symbol is bound in that environment. This is certainly a well-defined
> question.

I think

Function: module-defined? MODULE SYMBOL

does this already.

> 2) DEFINED? should be a core syntactic form --- not even a macro ---
> which is true if its operand, a symbol, is bound in the current
> environment. Thus:

Yes. But checking the lexical environment is not especially useful, I
think. Maybe macros can play some tricks with `defined?' and the
environment.

We should definitely use the lexical environment to find the
associated top-level environment. Right now, `defined?' checks the
current module, which is wrong (Yes, I wrote it myself...)

> I can't find the root of the original discussion, but I think we
> changed it because it implemented something bogus (e.g., always
> consulting the "top-level" environment). If anyone can remember,
> please let me know.

We changed it from a macro to an acro because the memoization was
bogus (and would fail with separate read/expand and eval, like in a
compiler). We changed it from a acro to a function because we thought
it didn't have to be syntax and functions are generally preferable to
syntax, given the choice.

But while implementing the function, I screwed it badly and made it
always look into the current module. To get the right environment,
`defined?' needs to be syntax.

> Is definition 1) above consistent with SCM's behavior?

I think 2) is.