aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLars Brinkhoff2017-04-05 08:42:25 +0200
committerLars Brinkhoff2017-04-06 20:30:28 +0200
commit4753f3f0af33c5defe3a340f82265db6a6863030 (patch)
treead48b75c21ba2c822904971bf4909ba0626f4014
parente3eea9a4b449c87a3bb022098a9e6f1bda805cb3 (diff)
downloademacs-4753f3f0af33c5defe3a340f82265db6a6863030.tar.gz
emacs-4753f3f0af33c5defe3a340f82265db6a6863030.zip
Update documentation for type semantics of records.
* objects.texi (Record Type): improve description of what `type-of' returns for records. (Type Descriptors): new section. * elisp.texi: reference it. * records.texi (Records): reference it. Document behaviour when type slot is a record. * alloc.c (Fmake_record, Frecord): mention type desciptors.
-rw-r--r--doc/lispref/elisp.texi1
-rw-r--r--doc/lispref/objects.texi16
-rw-r--r--doc/lispref/records.texi4
-rw-r--r--src/alloc.c10
4 files changed, 26 insertions, 5 deletions
diff --git a/doc/lispref/elisp.texi b/doc/lispref/elisp.texi
index 3a348aae98e..bff3112d73b 100644
--- a/doc/lispref/elisp.texi
+++ b/doc/lispref/elisp.texi
@@ -316,6 +316,7 @@ Programming Types
316* Primitive Function Type:: A function written in C, callable from Lisp. 316* Primitive Function Type:: A function written in C, callable from Lisp.
317* Byte-Code Type:: A function written in Lisp, then compiled. 317* Byte-Code Type:: A function written in Lisp, then compiled.
318* Record Type:: Compound objects with programmer-defined types. 318* Record Type:: Compound objects with programmer-defined types.
319* Type Descriptors:: Objects holding information about types.
319* Autoload Type:: A type used for automatically loading seldom-used 320* Autoload Type:: A type used for automatically loading seldom-used
320 functions. 321 functions.
321* Finalizer Type:: Runs code when no longer reachable. 322* Finalizer Type:: Runs code when no longer reachable.
diff --git a/doc/lispref/objects.texi b/doc/lispref/objects.texi
index 90cafbef642..cc9320987f2 100644
--- a/doc/lispref/objects.texi
+++ b/doc/lispref/objects.texi
@@ -156,6 +156,7 @@ latter are unique to Emacs Lisp.
156* Primitive Function Type:: A function written in C, callable from Lisp. 156* Primitive Function Type:: A function written in C, callable from Lisp.
157* Byte-Code Type:: A function written in Lisp, then compiled. 157* Byte-Code Type:: A function written in Lisp, then compiled.
158* Record Type:: Compound objects with programmer-defined types. 158* Record Type:: Compound objects with programmer-defined types.
159* Type Descriptors:: Objects holding information about types.
159* Autoload Type:: A type used for automatically loading seldom-used 160* Autoload Type:: A type used for automatically loading seldom-used
160 functions. 161 functions.
161* Finalizer Type:: Runs code when no longer reachable. 162* Finalizer Type:: Runs code when no longer reachable.
@@ -1359,6 +1360,18 @@ types that are not built into Emacs.
1359 1360
1360 @xref{Records}, for functions that work with records. 1361 @xref{Records}, for functions that work with records.
1361 1362
1363@node Type Descriptors
1364@subsection Type Descriptors
1365
1366 A @dfn{type decriptor} is a @code{record} which holds information
1367about a type. Slot 1 in the record must be a symbol naming the type.
1368@code{type-of} relies on this to return the type of @code{record}
1369objects. No other type descriptor slot is used by Emacs; they are
1370free for use by Lisp extensions.
1371
1372An example of a type descriptor is any instance of
1373@code{cl-structure-class}.
1374
1362@node Autoload Type 1375@node Autoload Type
1363@subsection Autoload Type 1376@subsection Autoload Type
1364 1377
@@ -2037,7 +2050,8 @@ This function returns a symbol naming the primitive type of
2037@code{marker}, @code{mutex}, @code{overlay}, @code{process}, 2050@code{marker}, @code{mutex}, @code{overlay}, @code{process},
2038@code{string}, @code{subr}, @code{symbol}, @code{thread}, 2051@code{string}, @code{subr}, @code{symbol}, @code{thread},
2039@code{vector}, @code{window}, or @code{window-configuration}. 2052@code{vector}, @code{window}, or @code{window-configuration}.
2040However, if @var{object} is a record, its first slot is returned. 2053However, if @var{object} is a record, the type specified by its first
2054slot is returned; @ref{Records}.
2041 2055
2042@example 2056@example
2043(type-of 1) 2057(type-of 1)
diff --git a/doc/lispref/records.texi b/doc/lispref/records.texi
index a6c560cbcb9..a924bafbb96 100644
--- a/doc/lispref/records.texi
+++ b/doc/lispref/records.texi
@@ -19,6 +19,10 @@ implementation records can have at most 4096 slots, whereas vectors
19can be much larger. Like arrays, records use zero-origin indexing: 19can be much larger. Like arrays, records use zero-origin indexing:
20the first slot has index 0. 20the first slot has index 0.
21 21
22 The type slot should be a symbol or a type descriptor. If it's a
23type descriptor, the symbol naming its type will be returned;
24@ref{Type Descriptors}. Any other kind of object is returned as-is.
25
22 The printed representation of records is @samp{#s} followed by a 26 The printed representation of records is @samp{#s} followed by a
23list specifying the contents. The first list element must be the 27list specifying the contents. The first list element must be the
24record type. The following elements are the record slots. 28record type. The following elements are the record slots.
diff --git a/src/alloc.c b/src/alloc.c
index a58824fb0f3..fad84b8a0b3 100644
--- a/src/alloc.c
+++ b/src/alloc.c
@@ -3411,8 +3411,9 @@ allocate_record (EMACS_INT count)
3411 3411
3412DEFUN ("make-record", Fmake_record, Smake_record, 3, 3, 0, 3412DEFUN ("make-record", Fmake_record, Smake_record, 3, 3, 0,
3413 doc: /* Create a new record. 3413 doc: /* Create a new record.
3414TYPE is its type as returned by `type-of'. SLOTS is the number of 3414TYPE is its type as returned by `type-of'; it should be either a
3415non-type slots, each initialized to INIT. */) 3415symbol or a type descriptor. SLOTS is the number of non-type slots,
3416each initialized to INIT. */)
3416 (Lisp_Object type, Lisp_Object slots, Lisp_Object init) 3417 (Lisp_Object type, Lisp_Object slots, Lisp_Object init)
3417{ 3418{
3418 CHECK_NATNUM (slots); 3419 CHECK_NATNUM (slots);
@@ -3427,8 +3428,9 @@ non-type slots, each initialized to INIT. */)
3427 3428
3428DEFUN ("record", Frecord, Srecord, 1, MANY, 0, 3429DEFUN ("record", Frecord, Srecord, 1, MANY, 0,
3429 doc: /* Create a new record. 3430 doc: /* Create a new record.
3430TYPE is its type as returned by `type-of'. SLOTS is used to 3431TYPE is its type as returned by `type-of'; it should be either a
3431initialize the record slots with shallow copies of the arguments. 3432symbol or a type descriptor. SLOTS is used to initialize the record
3433slots with shallow copies of the arguments.
3432usage: (record TYPE &rest SLOTS) */) 3434usage: (record TYPE &rest SLOTS) */)
3433 (ptrdiff_t nargs, Lisp_Object *args) 3435 (ptrdiff_t nargs, Lisp_Object *args)
3434{ 3436{