diff options
author | Lars Brinkhoff <lars@nocrew.org> | 2017-03-14 13:52:40 +0100 |
---|---|---|
committer | Lars Brinkhoff <lars@nocrew.org> | 2017-04-04 08:23:46 +0200 |
commit | 056548283884d61b1b9637c3e56855ce3a17274d (patch) | |
tree | 80f208b179e4f075dbf4388cea65c98572bd792e /doc/misc/cl.texi | |
parent | a2c33430292c79ac520100b1d0e8e7c04dfe426a (diff) | |
download | emacs-056548283884d61b1b9637c3e56855ce3a17274d.tar.gz |
Make cl-defstruct use records.
* lisp/emacs-lisp/cl-extra.el (cl--describe-class)
(cl--describe-class-slots): Use the new `type-of'.
* lisp/emacs-lisp/cl-generic.el (cl--generic-struct-tag): Use type-of.
(cl--generic-struct-specializers): Adjust to new tag.
* lisp/emacs-lisp/cl-macs.el (cl-defstruct): When type is nil, use records.
Use the type symbol as the tag. Use copy-record to copy structs.
(cl--defstruct-predicate): New function.
(cl--pcase-mutually-exclusive-p): Use it.
(cl-struct-sequence-type): Can now return `record'.
* lisp/emacs-lisp/cl-preloaded.el (cl--make-slot-desc): Adjust ad-hoc
code to new format.
(cl--struct-register-child): Work with records.
(cl-struct-define): Don't touch the tag's symbol-value and
symbol-function slots when we use the type as tag.
* lisp/emacs-lisp/cl-print.el (cl-print-object): Adjust to new tag.
* test/lisp/emacs-lisp/cl-lib-tests.el (cl-lib-defstruct-record):
New test.
* doc/lispref/records.texi, doc/misc/cl.texi: Update for records.
Diffstat (limited to 'doc/misc/cl.texi')
-rw-r--r-- | doc/misc/cl.texi | 51 |
1 files changed, 25 insertions, 26 deletions
diff --git a/doc/misc/cl.texi b/doc/misc/cl.texi index 079f534168c..2339d576319 100644 --- a/doc/misc/cl.texi +++ b/doc/misc/cl.texi @@ -4012,10 +4012,7 @@ Given a @code{person}, @code{(copy-person @var{p})} makes a new object of the same type whose slots are @code{eq} to those of @var{p}. Given any Lisp object @var{x}, @code{(person-p @var{x})} returns -true if @var{x} looks like a @code{person}, and false otherwise. (Again, -in Common Lisp this predicate would be exact; in Emacs Lisp the -best it can do is verify that @var{x} is a vector of the correct -length that starts with the correct tag symbol.) +true if @var{x} is a @code{person}, and false otherwise. Accessors like @code{person-name} normally check their arguments (effectively using @code{person-p}) and signal an error if the @@ -4221,16 +4218,16 @@ allow for such a feature, so this package simply ignores @code{:print-function}. @item :type -The argument should be one of the symbols @code{vector} or @code{list}. -This tells which underlying Lisp data type should be used to implement -the new structure type. Vectors are used by default, but -@code{(:type list)} will cause structure objects to be stored as -lists instead. +The argument should be one of the symbols @code{vector} or +@code{list}. This tells which underlying Lisp data type should be +used to implement the new structure type. Records are used by +default, but @code{(:type vector)} will cause structure objects to be +stored as vectors and @code{(:type list)} lists instead. -The vector representation for structure objects has the advantage -that all structure slots can be accessed quickly, although creating -vectors is a bit slower in Emacs Lisp. Lists are easier to create, -but take a relatively long time accessing the later slots. +The record and vector representations for structure objects have the +advantage that all structure slots can be accessed quickly, although +creating them are a bit slower in Emacs Lisp. Lists are easier to +create, but take a relatively long time accessing the later slots. @item :named This option, which takes no arguments, causes a characteristic ``tag'' @@ -4239,21 +4236,24 @@ symbol to be stored at the front of the structure object. Using structure type stored as plain vectors or lists with no identifying features. -The default, if you don't specify @code{:type} explicitly, is to -use named vectors. Therefore, @code{:named} is only useful in -conjunction with @code{:type}. +The default, if you don't specify @code{:type} explicitly, is to use +records, which are always tagged. Therefore, @code{:named} is only +useful in conjunction with @code{:type}. @example (cl-defstruct (person1) name age sex) (cl-defstruct (person2 (:type list) :named) name age sex) (cl-defstruct (person3 (:type list)) name age sex) +(cl-defstruct (person4 (:type vector)) name age sex) (setq p1 (make-person1)) - @result{} [cl-struct-person1 nil nil nil] + @result{} #s(person1 nil nil nil) (setq p2 (make-person2)) @result{} (person2 nil nil nil) (setq p3 (make-person3)) @result{} (nil nil nil) +(setq p4 (make-person4)) + @result{} [nil nil nil] (person1-p p1) @result{} t @@ -4293,9 +4293,9 @@ introspection functions. @defun cl-struct-sequence-type struct-type This function returns the underlying data structure for -@code{struct-type}, which is a symbol. It returns @code{vector} or -@code{list}, or @code{nil} if @code{struct-type} is not actually a -structure. +@code{struct-type}, which is a symbol. It returns @code{record}, +@code{vector} or @code{list}, or @code{nil} if @code{struct-type} is +not actually a structure. @end defun @defun cl-struct-slot-info struct-type @@ -4562,9 +4562,8 @@ set down in Steele's book. The variable @code{cl--gensym-counter} starts out with zero. -The @code{cl-defstruct} facility is compatible, except that structures -are of type @code{:type vector :named} by default rather than some -special, distinct type. Also, the @code{:type} slot option is ignored. +The @code{cl-defstruct} facility is compatible, except that the +@code{:type} slot option is ignored. The second argument of @code{cl-check-type} is treated differently. @@ -4713,9 +4712,9 @@ Lisp. Rational numbers and complex numbers are not present, nor are large integers (all integers are ``fixnums''). All arrays are one-dimensional. There are no readtables or pathnames; streams are a set of existing data types rather than a new data -type of their own. Hash tables, random-states, structures, and -packages (obarrays) are built from Lisp vectors or lists rather -than being distinct types. +type of their own. Hash tables, random-states, and packages +(obarrays) are built from Lisp vectors or lists rather than being +distinct types. @item The Common Lisp Object System (CLOS) is not implemented, |