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

:conc-name



    Date: Fri, 12 Apr 91 08:48:10 edt
    From: rick@maxai.den.mmc.com (Rick Duffy)

    Lisp question:

    I create a simple structure:

	(defstruct (a-simple-structure (:conc-name nil))
	  a-simple-slot)

	(setf a-simple-instance (make-a-simple-structure))


    Now, according to CLTL (pg 476: 19.5 Defstruct Options),
    it seems to me that I should be able to reference 
    a-simple-slot with (a-simple-slot a-simple-instance).

    Instead, I seem to need (nila-simple-slot a-simple-instance).

    Is this a bug, or am I simply missing something?

This works fine for me.  [Expansion of DEFSTRUCT below.]  Are you using
the right symbol named NIL?  Find out if

  (EQL 'NIL '())

is true in your package.  An easy way to get the wrong symbol is to say

  (IMPORT 'NIL) ;; That is, an empty list of symbols

in your package: this actually imports no symbols, rather than the
single symbol NIL.  You need to say

  (import '(NIL)) ;; That is, a list containing the symbol NIL.

or, better yet, use DEFPACKAGE to describe your package.  

You can also the the same problem if you USE a package which has had NIL
mis-exported:

  (EXPORT 'NIL)  ;; should be (EXPORT '(NIL)).

=================================================================

The annotated, abbreviated-for-legibility expansion of your DEFSTRUCT
from above; probably more than you ever really wanted to know:

;;; Make sure the entire definition gets loaded together:
(SYS:MULTIPLE-DEFINITION A-SIMPLE-STRUCTURE ZL:DEFSTRUCT

;;; Make compile-time update to the Lisp environment:
  (EVAL-WHEN (COMPILE)
    (CLOS-INTERNALS::ENSURE-DEFSTRUCT-1
      'A-SIMPLE-STRUCTURE
      [...]))  ;; You don't need to know the details.

;;; Make load-time update to the environment:
  (CLOS-INTERNALS::ENSURE-DEFSTRUCT 'A-SIMPLE-STRUCTURE [...])

;;; Define constructor:
  (DEFSUBST MAKE-A-SIMPLE-STRUCTURE (&KEY (#:A-SIMPLE-SLOT NIL #:G14456))
    ;; Make structure instance:
    (LET* ((#:INSTANCE (CLOS-INTERNALS::ALLOCATE-STRUCTURE-OBJECT [...])))
      ;; Initialize slot(s):
      (WHEN #:G14456
        (FUTURE-COMMON-LISP:SETF (CLOS-INTERNALS::%STRUCTURE-REF #:INSTANCE 0) 
		#:A-SIMPLE-SLOT))
      ;; Return the newly-constructed instance
      #:INSTANCE))

;;; Define copier:
  (DEFF COPY-A-SIMPLE-STRUCTURE #'CLOS-INTERNALS::%ALLOCATE-INSTANCE-COPY)

;;; Define predicate:
  (DEFSUBST A-SIMPLE-STRUCTURE-P (STRUCTURE)
	[...] )

;;; Define slot accessors:
  (PROGN

;;; Define slot reader A-SIMPLE-SLOT:
    (PROGN
;;; Make compile-time update to Lisp Language database, sort of like what DEFSUBST does: 
      (EVAL-WHEN (COMPILE)
        (FUTURE-COMMON-LISP:SETF
	      (CLOS-INTERNALS::FILE-DECLARATION 'A-SIMPLE-SLOT 'DEF)
;;; At compile time, the compiler expands a reference to (A-SIMPLE-SLOT foo)
;;; into (CLOS-INTERNALS::%STRUCTURE-REFERENCE foo 0):
		'#S(LT:INLINE-FORM [...]
		     :LAMBDA-LIST (#:G12774)
		     :BODY ((CLOS-INTERNALS::%STRUCTURE-REF #:G12774 0))
		     [...])))

;;; Note, by the way, that the (:CONC-NAME NIL) construction worked correctly.

;;; Make load-time function, so, for example, (MAPCAR #'A-SIMPLE-SLOT THINGS) works.
;;; At run time, #'A-SIMPLE-SLOT is a function which reads slot 0 of a structure
;;; [The function MAKE-DEFSTRUCT-STRUCTURE-OBJECT-READER returns the equivalent of
;;;  #'(LAMBDA (FOO) (CLOS-INTERNALS::%STRUCTURE-REFERENCE FOO 0))]:
      (DEFF A-SIMPLE-SLOT (CLOS-INTERNALS::MAKE-DEFSTRUCT-STRUCTURE-OBJECT-READER 0)))

;;; Do the same for (SETF A-SIMPLE-SLOT):
    (PROGN
      (EVAL-WHEN (COMPILE)
        (FUTURE-COMMON-LISP:SETF
	      (CLOS-INTERNALS::FILE-DECLARATION '(FUTURE-COMMON-LISP:SETF A-SIMPLE-SLOT) 'DEF)
		'#S(LT:INLINE-FORM [...])))
      (DEFF (FUTURE-COMMON-LISP:SETF A-SIMPLE-SLOT)
            (CLOS-INTERNALS::MAKE-DEFSTRUCT-STRUCTURE-OBJECT-WRITER 0)))

;;; Do the same for (LOCF A-SIMPLE-SLOT):
    (PROGN [...])))

:NAME
				   CLOS-INTERNALS::DEFSTRUCT-STRUCTURE-OBJECT-READ-0
				   :LAMBDA-LIST (#:G12774)
				   :BODY
				   ((CLOS-INTERNALS::%STRUCTURE-REF #:G12774 0))
				   :ENV NIL
				   :FORM
				   (CLOS-INTERNALS::%STRUCTURE-REF #:G12774 0)
				   :VARIABLES (#:G12774)
				   :VARNOTES (NIL)
				   :FREE-VARIABLES NIL
				   :FREE-BLOCKS NIL
				   :FREE-TAGS NIL
				   :FREE-FUNCTIONS
				   (CLOS-INTERNALS::%STRUCTURE-REF LOCALLY) :NAME
				   CLOS-INTERNALS::DEFSTRUCT-STRUCTURE-OBJECT-READ-0
				   :LAMBDA-LIST (#:G12774)
				   :BODY
				   ((CLOS-INTERNALS::%STRUCTURE-REF #:G12774 0))
				   :ENV NIL
				   :FORM
				   (CLOS-INTERNALS::%STRUCTURE-REF #:G12774 0)
				   :VARIABLES (#:G12774)
				   :VARNOTES (NIL)
				   :FREE-VARIABLES NIL
				   :FREE-BLOCKS NIL
				   :FREE-TAGS NIL
				   :FREE-FUNCTIONS
				   (CLOS-INTERNALS::%STRUCTURE-REF LOCALLY)