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

define



I didn't want to make any changes to the report as fundamental as this.
A change to DEFINE also seems infeasible given how constroversial the
topic is and always has been.  I am trying to sidestep controversies
right now, so that I can get something done.  Maybe in next year's
revision (??) we can address this question.

As we agreed at Brandeis, few of us wholeheartedly like internal
definitions, but they should be described ("nonessentially") because
S&ICP uses them.  This was a difficult compromise for us to arrive at,
and I think it would be much too painful at this point to retract it.
And now we have another reason to leave them in, which is compatibility
with the RRRS.

T originally had the semantics that you prefer for DEFINE (although
definitions aren't "globally" effective, they're scoped to the innermost
lexical contour which is willing to accept it).  Many users found it to
be a very nice feature, for the same reasons you do.  However, I have
recommended to the current T implementors that they remove the feature,
for several reasons:
  (a) It makes it more difficult for humans & programs to scan a file
      to find its definitions.
  (b) It's not always obvious which environment it is intended the
      definitions go in; like MIT Scheme, T has no notion of "top level."
  (c) It really confuses anyone who has ever seen S&ICP or MIT Scheme.
The old meaning will be retained in T, probably under some other name
(or anonymously, since T has anonymous special form types).  Kent and
others still stand by the old meaning.

Here is how I think I would put the functionality that "global define"
provides into a language like Scheme.  (A better language than Scheme
might do it better.)  Invent a special form (or macro) called something
like EXPORT or PROVIDE or MODULE which works as follows:

  (provide <var1> <var2> ...)

is equivalent to

  (lambda (<temp>)
    (case <temp>
      ((<var1>) <var1>)
      ((<var2>) <var2>)
      ...
      (else <error>)))

where <temp> is a variable different from <var1>, <var2>, ....

Then instead of

  (let ((state ...))
    (define-global reader ...)
    (define-global writer ...)
    ...)
  
you can write

  (define i/o-system
    (letrec ((state ...)
	     (reader ...)
	     (writer ...)
	     ...)
      (provide reader writer ...)))
  
  (define reader (i/o-system 'reader))
  (define writer (i/o-system 'writer))
  ...

The PROVIDE special form would be useful for many other applications as
well (e.g. object-oriented programming).

If this is too verbose for you, I think other kinds of macros could
almost as easily be designed which like the above raise no new semantic
questions.


- Jonathan