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

Re: [KAHLE@Aquinas.Think.COM: defstruct request for common lisp]



    Date: 1 Oct 87 17:25 PDT
    From: Pablo Ghenis <ghenis.pasa@xerox.com>

    What useful things could one do with the output of (structure-slots
    <structure-name>), given that the choice of slot to access cannot be
    gracefully deferred until run-time the way p-lists allow? I'm afraid
    that a "structure-slots" function wouldn't be all that valuable because
    of this deeper limitation of structures.

What limitation are you talking about?  Structure slot names are also
the names of functions, which can be FUNCALLed.  Thus, one could write

(defun show-structure-slots (structure)
  (dolist (slot (structure-slots (type-of structure)))
    (format t "~A: ~S" slot (funcall slot structure))))

You may have been thinking of Maclisp and Zetalisp defstruct, which
defined the accessors as macros, so they couldn't be FUNCALLed.  Common
Lisp fixed this.

                                                barmar