Gallagher@GILGAMESH.CS.UMASS.EDU (Kevin Gallagher) (04/18/91)
From: Gregor Kiczales <Gregor@parc.xerox.com> (via barmar@think.com) Date: Mon, 15 Apr 1991 09:37:22 -0700 The MOP spec does not require SLOT-VALUE to work on structures. This requirement was dropped in the final version because some people were concerned that it interfered with efficient structure implementations. I am very disappointed to see this. For several *years* the standard answer to the question ``How do I access an arbitrary slot in a structure instance?'' has been ``Use SLOT-VALUE (when CLOS is available).'' This question is asked almost monthly on the various lisp mailing lists and newsgroups. Providing this capability does not prevent efficient structure implementations. All that is required is to maintain declarative information about the implemenation of the structure. Most lisps already save this information anyway for the benefit of functions like describe and inspect. The defstruct generated slot access functions can still use whatever implementation tricks you like. In addition, it is not possible to implement this capability in Common Lisp. Many Common Lisp solutions have been proposed, however none of them are completely general. Kevin Gallagher Gallagher@cs.umass.edu P.S. I have a set of implementation specific structure slot access utilities for each lisp that I use, as I'm sure many other people do as well. I can certainly define SLOT-VALUE-USING-CLASS in terms of these, but this is less than optimal.
Gregor@parc.xerox.com (Gregor Kiczales) (04/18/91)
Date: Wed, 17 Apr 1991 15:06:02 PDT From: Kevin Gallagher <Gallagher@gilgamesh.cs.umass.edu> From: Gregor Kiczales <Gregor@parc.xerox.com> (via barmar@think.com) Date: Mon, 15 Apr 1991 09:37:22 -0700 The MOP spec does not require SLOT-VALUE to work on structures. This requirement was dropped in the final version because some people were concerned that it interfered with efficient structure implementations. I am very disappointed to see this. For several *years* the standard answer to the question ``How do I access an arbitrary slot in a structure instance?'' has been ``Use SLOT-VALUE (when CLOS is available).'' This question is asked almost monthly on the various lisp mailing lists and newsgroups. Providing this capability does not prevent efficient structure implementations. All that is required is to maintain declarative information about the implemenation of the structure. I agree with you, but some vendors were concerned that it would cause performance problems. At this point, the best route is for customer requests to cause vendors to provide this functionality. As I said before, the MOP document makes it clear how to provide the functionality, it just doesn't specify it. So, there is an open hole waiting for vendors to fill.
jonl%kuwait@LUCID.COM (Jon L White) (04/18/91)
[I suspect this question will continue to come up on this list for some time; hence I will take the time here to outline what I think the main concerns are for retaining the historic "lean" definition for DEFSTRUCT, even in the face of the addition of CLOS.] re: For several *years* the standard answer to the question ``How do I access an arbitrary slot in a structure instance?'' has been ``Use SLOT-VALUE (when CLOS is available).'' You forgot the part about STANDARD-CLASS, whose default behaviour is to retain the "meta" information in the image; i.e., convert over from use of DEFSTRUCT to use of DEFCLASS. re: All that is required is to maintain declarative information about the implemenation of the structure. Most lisps already save this information anyway for the benefit of functions like describe and inspect. It certainly has never been in the Common Lisp contract that the Lisp must "save" this information. Delivery applications typically DO NOT have this "meta" level information present, and work quite well without it. In the same way that DEFMACRO's may be elided from the runtime environment, one may also elide DEFSTRUCT's (and DEFSUBST's and even probably most DEFTYPE's) -- without any additional "meta" level considerations -- typically by use of eval-when, defsystem, or what-not. Compare the "conventional computer languages" world [my apologies for invoking the "C" word here]; are the struct definitions parsed by the compiler "saved" in the A.OUT for, say, hello-world? The forces that Gregor referred to surely lie in the realm of an existing body of DEFSTRUCT users who cannot continue their "lean and mean" applications if the addition of CLOS to the language requires DEFSTRUCT to become a heavyweight. [Yes it would still be a "heavyweight" even if some vendor invested the energy to figure out some *non-standard* interface to delete all the meta realm after having built up the images by "saving" it.] The issue is one of defaults -- and for persons like yourself, switching to DEFCLASS is probably much easier than requiring all the industrial-strength applications to (1) switch to the non-existent vendors who are already selling this sort of structure-class shakedown, and (2) reconfigure all their defstruct code to make use of the proprietary extensions that do the shakedown. -- JonL -- P.S. A more productive avenue of lobbying in this case might be to get the vendors to continue waleing away at SLOT-VALUE optimizations.
harrisr@CS.RPI.EDU (Richard Harris) (04/18/91)
The file structure.lisp implements structure-classes for PCL. I have put it in the pcl directory on arisia.xerox.com. I have tested it in Lucid 3.0 and akcl 530. For other ports of PCL, the following functions remain to be implemented: Low level functions for structures Functions on arbitrary objects structurep structure-instance-p ; excludes std-instance structure-type Functions on symbols naming structures structure-type-p ; Excludes structures types created with the :type option structure-type-included-type-name structure-type-slot-description-list ; all slots, not just direct slots Functions on slot-descriptions (returned by the function above) structure-slotd-name [symbol] structure-slotd-reader [symbol] structure-slotd-writer [symbol or list or null] If you implement these low level functions for your lisp, please send me a copy. Here is a sample session: > (compile-file "structure") ... > (load "structure") ... > (in-package 'pcl) #<Package "PCL" AB641E> > (defstruct z a) Z > (setq z1 (make-z :a 1)) #S(Z A 1) > (slot-value z1 'a) 1 > (setf (slot-value z1 'a) 2) 2 > (z-a z1) 2 > (class-of z1) #<Structure-Class Z 67337736> > (find-class 'z) #<Structure-Class Z 67337736> > (pprint (macroexpand '(defmethod x ((self z)) (slot-value self 'a)))) (COMPILER-LET ((SYSTEM:*COMPILER-MESSAGE-STRING* (OR SYSTEM:*COMPILER-MESSAGE-STRING* "Defmethod X (Z)"))) (EVAL-WHEN (COMPILE LOAD EVAL) (LOAD-DEFMETHOD 'STANDARD-METHOD 'X 'NIL (LIST 'Z) '(SELF) 'NIL 'NIL 'NIL #'(LAMBDA (SELF) (DECLARE (CLASS SELF Z)) (PROGN SELF) (BLOCK X (Z-A SELF)))))) > (defmethod x ((self z)) (slot-value self 'a)) #<Standard-Method X (Z) 74475406> > (defmethod x (self) self) #<Standard-Method X (T) 65775016> > > (x 'a) A > (x z1) 2 > ------- Richard Harris
jeff@aiai.edinburgh.ac.uk (Jeff Dalton) (04/18/91)
> [I suspect this question will continue to come up on this list for some > time; hence I will take the time here to outline what I think the main > concerns are for retaining the historic "lean" definition for DEFSTRUCT, > even in the face of the addition of CLOS.] I don't particularly care whether SLOT-VALUE works with structures. Indeed, I think SLOT-VALUE is in some ways a step backwards, like using symbols for variables. However, I would like to be able to (1) find out what slots there are and (2) get the accessors and setters for the slots. This sort of thing comes up very often, for one reason or another, and people have resorted to writing macros that sit on top of DEFSTRUCT and record the necessary information. I've done this myself a couple of times too. Implementations have this information at some point and then perhaps get rid of it. I can accept the point that Common Lisp has enough problems with image size without adding another. A possible low impact solution might be to add a DEFSTRUCT option that specifies whether the "meta" information is required at run-time. > re: For several *years* the standard answer to the question ``How do I > access an arbitrary slot in a structure instance?'' has been > ``Use SLOT-VALUE (when CLOS is available).'' > > You forgot the part about STANDARD-CLASS, whose default behaviour > is to retain the "meta" information in the image; i.e., convert > over from use of DEFSTRUCT to use of DEFCLASS. STANDARD-CLASS brings a lot of other stuff with it that one may not want. > Compare the "conventional computer languages" world [my apologies for > invoking the "C" word here]; are the struct definitions parsed by the > compiler "saved" in the A.OUT for, say, hello-world? The symbol table is typicaly there, unless you "strip" it. Files compiled for symbolic debugging (-g) have structure information. In any case, there are many things C structs don't have. For example, they don't have a printed representation. That C structs lack something isn't much of an argument for having the same lack in CL. -- Jeff