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

macros expanding into definitions



I'm not sure that I agree with what seems to be a growing consensus on
internal defines - i.e. (from Marc Feely)

    1) All internally defined variables are put in an implicit let at the head
    of the corresponding body.
    2) The initial binding is to an unspecified value.
    3) The internal defines are simply replaced with set!'s.

    In addition, the report should say that it is an error to reference or
    set! a variable before the definition has been evaluated.  The
    following is thus an error:


The initial (and I thought primary) motivation for all this was to
make internal defines consistent with top-level defines. The above
rules do not do this. For example, the above disallows:

  (define x 0)
  (define (foo)
    (set! x 1)
    (define x 2))
  (foo)
  x
 
This does not seem consistent to me with the top-level behavior of:

  (define x 0)
  (set! x 1)
  (define x 2)
  x

I think that naive users may expect the first set of expressions to be
allowed and to print 2 like the second set. It also seems weird to me
that if you remove the internal define in the definition of foo that
it becomes legal. I think that naive users would have trouble with the
fact that adding a define makes a variable unassigned.

I'm not saying that the semantics of internal define should be such
that the first set of expressions means the same as the second set
(and obviously neither would any of the people who have heretofor
spoken on this subject) but I just don't see that the semantics that
people have presented for internal defines is particularly consistent
with top-level defines.