Skip to content

Commit 4753f3f

Browse files
committed
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.
1 parent e3eea9a commit 4753f3f

File tree

4 files changed

+26
-5
lines changed

4 files changed

+26
-5
lines changed

doc/lispref/elisp.texi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,7 @@ Programming Types
316316
* Primitive Function Type:: A function written in C, callable from Lisp.
317317
* Byte-Code Type:: A function written in Lisp, then compiled.
318318
* Record Type:: Compound objects with programmer-defined types.
319+
* Type Descriptors:: Objects holding information about types.
319320
* Autoload Type:: A type used for automatically loading seldom-used
320321
functions.
321322
* Finalizer Type:: Runs code when no longer reachable.

doc/lispref/objects.texi

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ latter are unique to Emacs Lisp.
156156
* Primitive Function Type:: A function written in C, callable from Lisp.
157157
* Byte-Code Type:: A function written in Lisp, then compiled.
158158
* Record Type:: Compound objects with programmer-defined types.
159+
* Type Descriptors:: Objects holding information about types.
159160
* Autoload Type:: A type used for automatically loading seldom-used
160161
functions.
161162
* Finalizer Type:: Runs code when no longer reachable.
@@ -1359,6 +1360,18 @@ types that are not built into Emacs.
13591360

13601361
@xref{Records}, for functions that work with records.
13611362

1363+
@node Type Descriptors
1364+
@subsection Type Descriptors
1365+
1366+
A @dfn{type decriptor} is a @code{record} which holds information
1367+
about 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}
1369+
objects. No other type descriptor slot is used by Emacs; they are
1370+
free for use by Lisp extensions.
1371+
1372+
An example of a type descriptor is any instance of
1373+
@code{cl-structure-class}.
1374+
13621375
@node Autoload Type
13631376
@subsection Autoload Type
13641377

@@ -2037,7 +2050,8 @@ This function returns a symbol naming the primitive type of
20372050
@code{marker}, @code{mutex}, @code{overlay}, @code{process},
20382051
@code{string}, @code{subr}, @code{symbol}, @code{thread},
20392052
@code{vector}, @code{window}, or @code{window-configuration}.
2040-
However, if @var{object} is a record, its first slot is returned.
2053+
However, if @var{object} is a record, the type specified by its first
2054+
slot is returned; @ref{Records}.
20412055

20422056
@example
20432057
(type-of 1)

doc/lispref/records.texi

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ implementation records can have at most 4096 slots, whereas vectors
1919
can be much larger. Like arrays, records use zero-origin indexing:
2020
the first slot has index 0.
2121

22+
The type slot should be a symbol or a type descriptor. If it's a
23+
type descriptor, the symbol naming its type will be returned;
24+
@ref{Type Descriptors}. Any other kind of object is returned as-is.
25+
2226
The printed representation of records is @samp{#s} followed by a
2327
list specifying the contents. The first list element must be the
2428
record type. The following elements are the record slots.

src/alloc.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3411,8 +3411,9 @@ allocate_record (EMACS_INT count)
34113411

34123412
DEFUN ("make-record", Fmake_record, Smake_record, 3, 3, 0,
34133413
doc: /* Create a new record.
3414-
TYPE is its type as returned by `type-of'. SLOTS is the number of
3415-
non-type slots, each initialized to INIT. */)
3414+
TYPE is its type as returned by `type-of'; it should be either a
3415+
symbol or a type descriptor. SLOTS is the number of non-type slots,
3416+
each initialized to INIT. */)
34163417
(Lisp_Object type, Lisp_Object slots, Lisp_Object init)
34173418
{
34183419
CHECK_NATNUM (slots);
@@ -3427,8 +3428,9 @@ non-type slots, each initialized to INIT. */)
34273428

34283429
DEFUN ("record", Frecord, Srecord, 1, MANY, 0,
34293430
doc: /* Create a new record.
3430-
TYPE is its type as returned by `type-of'. SLOTS is used to
3431-
initialize the record slots with shallow copies of the arguments.
3431+
TYPE is its type as returned by `type-of'; it should be either a
3432+
symbol or a type descriptor. SLOTS is used to initialize the record
3433+
slots with shallow copies of the arguments.
34323434
usage: (record TYPE &rest SLOTS) */)
34333435
(ptrdiff_t nargs, Lisp_Object *args)
34343436
{

0 commit comments

Comments
 (0)