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

Re: declare in with-slots



    Date: Wed, 3 Aug 88 07:10:42 PDT
    From: piazza%lisp.DEC@decwrl.dec.com (Jeffrey Piazza)

    As to the suggested patch:  No, it won't really work.  Declare's are pretty
    much the province of special forms, and with-slots et al won't, in general, be
    able to parse the declare's, let alone interpret them correctly.  For example,
    a common extension to declare allows:

    (deftype t-terminated-list () '(or cons (member t)))

    (with-slots (x y z) <instance>
      (declare (t-terminated-list y))
      ...)

This declaration is clearly illegal according to CLtL.  Page 158,
paragraph 4 says:

  (<type> <var1> ...) is an abbreciation for (TYPE <type> <var1> ...)
  provided <type> is one of the types appearing in Table 4-1.

The reason this extension is a bad idea transcends with-slots and
friends of course.  No portable program analyzing program can analyze
code that uses this extension.

But, if a given implementation does in fact make this extension, it
could just smarten up its with-slots (or symbol-macrolet) implementation
to understand this case.

    While you're thinking about this, consider what would happen if Common Lisp
    were extended to allow:

    (with-slots (x y z) <instance>
      ...
      (locally (declare (fixnum y))
	...)
      ...)

    [CL doesn't currently allow this, but there's some sentiment to make this
    extension.]  Now with-slots would have to parse the entire body to get this
    right.

As would a large number of other forms that could be affected by this
change.  Putting the declare mechanism inside of symbol-macrolet, might
be percieved to "solve" this problem.  It seems to me that the real
problem with this case would be profusion of declaration hair though.
 
    What's the point of symbol-macrolet, then, if not to be the form which says
    "pretend foo is a variable, even though it's not"?  You're suggesting that only
    with-slots wants to play "let's pretend," and that there's some different roles
    that symbol-macrolet fills?  I doubt it...

This code from Jim Kempf shows how I was intending to have with-slots
expand, and shows clearly why I didn't think symbol-macrolet was the
place to support this.  Of course it is just as easy to put this in
symbol-macrolet as far as I am concerned.

    The expansion of with-slots would be something like:

	    (symbol-macrolet
	      ( (x (the fixnum (slot-value 'x obj)))
		(y (the fixnum (slot-value 'y obj)))
		(z (the fixnum (slot-value 'z obj)))
	      )
	      (locally
		<any other declarations>

		...
	      )
	    
-------