aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrea Corallo2024-11-14 00:20:13 +0100
committerAndrea Corallo2024-11-21 15:38:15 +0100
commit59b3eae481d59d901ff64de1a827d3dd656a4fc9 (patch)
tree877ddc1c6d45806068e2f8cea7ca4d11cf2055a3
parent83fc3cf53a4b54a4ec3bf464cfea97f74522cd8d (diff)
downloademacs-59b3eae481d59d901ff64de1a827d3dd656a4fc9.tar.gz
emacs-59b3eae481d59d901ff64de1a827d3dd656a4fc9.zip
; Introduce type specifiers to the elisp manual (bug#73626)
* doc/lispref/objects.texi (Programming Types): Add 'Type Specifiers' entry. (Type Specifiers): Add node. * doc/lispref/functions.texi (Declare Form): Add 'Type Specifiers' reference.
-rw-r--r--doc/lispref/functions.texi9
-rw-r--r--doc/lispref/objects.texi87
2 files changed, 92 insertions, 4 deletions
diff --git a/doc/lispref/functions.texi b/doc/lispref/functions.texi
index 7fb9fb37c0a..4ffa3d7ead4 100644
--- a/doc/lispref/functions.texi
+++ b/doc/lispref/functions.texi
@@ -2733,10 +2733,11 @@ native compiler (@pxref{Native Compilation}) for improving code
2733generation and for deriving more precisely the type of other functions 2733generation and for deriving more precisely the type of other functions
2734without type declaration. 2734without type declaration.
2735 2735
2736@var{type} is a type specifier in the form @w{@code{(function 2736@var{type} is a @dfn{type specifier} (@pxref{Type Specifiers}) in the
2737(ARG-1-TYPE ... ARG-N-TYPE) RETURN-TYPE)}}. Argument types can be 2737form @w{@code{(function (@var{arg-1-type} ... @var{arg-n-type})
2738interleaved with symbols @code{&optional} and @code{&rest} to match the 2738RETURN-TYPE)}}. Argument types can be interleaved with symbols
2739function's arguments (@pxref{Argument List}). 2739@code{&optional} and @code{&rest} to match the function's arguments
2740(@pxref{Argument List}).
2740 2741
2741@var{function} if present should be the name of function being defined. 2742@var{function} if present should be the name of function being defined.
2742 2743
diff --git a/doc/lispref/objects.texi b/doc/lispref/objects.texi
index 34ea7cf4996..d847f438e0f 100644
--- a/doc/lispref/objects.texi
+++ b/doc/lispref/objects.texi
@@ -247,6 +247,7 @@ latter are unique to Emacs Lisp.
247* Closure Type:: A function written in Lisp. 247* Closure Type:: A function written in Lisp.
248* Record Type:: Compound objects with programmer-defined types. 248* Record Type:: Compound objects with programmer-defined types.
249* Type Descriptors:: Objects holding information about types. 249* Type Descriptors:: Objects holding information about types.
250* Type Specifiers:: Expressions which describe types.
250* Autoload Type:: A type used for automatically loading seldom-used 251* Autoload Type:: A type used for automatically loading seldom-used
251 functions. 252 functions.
252* Finalizer Type:: Runs code when no longer reachable. 253* Finalizer Type:: Runs code when no longer reachable.
@@ -1499,6 +1500,92 @@ free for use by Lisp extensions.
1499An example of a type descriptor is any instance of 1500An example of a type descriptor is any instance of
1500@code{cl-structure-class}. 1501@code{cl-structure-class}.
1501 1502
1503@node Type Specifiers
1504@subsection Type Specifiers
1505@cindex type specifier
1506
1507A type specifier is an expression that denotes a type. A type
1508represents a set of possible values. Type specifiers can be classified
1509in primitives and compounds.
1510
1511Type specifiers are in use for several purposes including: documenting
1512function interfaces through declaration (@pxref{Declare Form}),
1513specifying structure slot values (@pxref{Structures,,, cl, Common Lisp
1514Extensions for GNU Emacs Lisp}), type-checking through @code{cl-the}
1515(@pxref{Declarations,,, cl, Common Lisp Extensions for GNU Emacs Lisp})
1516and others.
1517
1518@table @asis
1519@item Primitive type specifiers
1520Primitive types specifiers are the basic types (i.e.@: not composed by other
1521type specifiers).
1522
1523Built-in primitive types (like @code{integer}, @code{float},
1524@code{string} etc) are listed in @ref{Type Hierarchy}.
1525
1526@item Compound type specifiers
1527Compound types serve the purpose of defining more complex or precise
1528type specifications by combining or modifying simpler types.
1529
1530List of compound type specifiers:
1531
1532@table @code
1533@item (or @var{type-1} .. @var{type-n})
1534The @code{or} type specifier describes a type that satisfies at least
1535one of the given types.
1536
1537@item (and @var{type-1} .. @var{type-n})
1538Similarly the @code{and} type specifier describes a type that satisfies
1539all the given types.
1540
1541@item (not @var{type})
1542The @code{not} type specifier defines any type except the specified one.
1543
1544@item (member @var{value-1} .. @var{value-n})
1545The @code{member} type specifier allows to specify a type that includes
1546only the explicitly listed values.
1547
1548@item (function (@var{arg-1-type} ... @var{arg-n-type}) @var{return-type})
1549The @code{function} type specifier is used to describe the argument
1550types and return type of a function. Argument types can be interleaved
1551with symbols @code{&optional} and @code{&rest} to match the function's
1552arguments (@pxref{Argument List}).
1553
1554The following is to represent a function with: a first parameter of type
1555@code{symbol}, a second optional parameter of type @code{float} and
1556returning an @code{integer}:
1557@example
1558(function (symbol &optional float) integer)
1559@end example
1560
1561@item (integer @var{lower-bound} @var{upper-bound})
1562
1563@code{integer} can be used as well as a compound type specifier to
1564define a subset of integers by specifying a range. This allows to
1565precisely control which integers are valid for a given type.
1566
1567@var{lower-bound} is the minimum integer value in the range and
1568@var{upper-bound} the maximum. It is possible to use @code{*} to
1569indicate no lower or uper limit.
1570
1571The following represents all integers from -10 to 10.
1572@example
1573(integer -10 10)
1574@end example
1575
1576The following represents 10.
1577@example
1578(integer 10 10)
1579@end example
1580
1581The following represents all integers from negative infinity to 10.
1582@example
1583(integer * 10)
1584@end example
1585
1586@end table
1587@end table
1588
1502@node Autoload Type 1589@node Autoload Type
1503@subsection Autoload Type 1590@subsection Autoload Type
1504 1591