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

Re Scope and declarations



Sorry I wasn't specific enough in my last query.  Therefore, I'll start from
scratch.  The point that bothers me is the one made on page 155 of CLtL.
As I understand things,
  (setq x 5)

  (defun foo (x)
    (declare (unspecial x))
    (let((x (1+ x)))
      (declare (special x))
      x)

  (print (foo 0))
outputs 6, not 1.  The declare in the let form prevades the preset expression
so that the expression (1+ x) assumes the current global binding of x outside
outside the let.  I can understand that this will often be the right thing and
require less writing.  I also understand that if I want to grab the lexical x
that I could change the let to start
  (let((x (let()(declare (unspecial x)) (1+ x))))
which I suppose works.  (Does it?)  However, if the let is produced by a
macro, there is no way to achieve this effect unless the macro can enumerate
the scope of the expression that it uses for the preset.  Since the preset
may be passed into the macro, I don't think it can recover in any graceful
way unless you think that
  (let((g exp))
    (let((x g))
      (declare (special x)) etc))
where g is a gensym, is graceful.

Another problem with declares prevading presets is that the following are
not equivelent:
  (let((v1 e1) (v2 e2)) (declare (something-about v1 v2)) body...)

  ((lambda(v1 v2) (declare (something-about v1 v2)) body...) e1 e2)
Further, I think the proposed standard is incompatible with virtually all
other LISP implementations.  I don't think that this is a good idea for CL.
Any comments and clarifications as to all of this would be appreciated.
	Jeff