578 |
|
|
579 |
@node Composite Types |
@node Composite Types |
580 |
@subsection Composite Types |
@subsection Composite Types |
581 |
|
@cindex arguments (of composite type) |
582 |
|
|
583 |
When none of the simple types is appropriate, you can use composite |
When none of the simple types is appropriate, you can use composite |
584 |
types, which build new types from other types. Here are several ways of |
types, which build new types from other types or from specified data. |
585 |
doing that: |
The specified types or data are called the @dfn{arguments} of the |
586 |
|
composite type. The composite type normally looks like this: |
|
@table @code |
|
|
@item (restricted-sexp :match-alternatives @var{criteria}) |
|
|
The value may be any Lisp object that satisfies one of @var{criteria}. |
|
|
@var{criteria} should be a list, and each element should be |
|
|
one of these possibilities: |
|
|
|
|
|
@itemize @bullet |
|
|
@item |
|
|
A predicate---that is, a function of one argument that has no side |
|
|
effects, and returns either @code{nil} or non-@code{nil} according to |
|
|
the argument. Using a predicate in the list says that objects for which |
|
|
the predicate returns non-@code{nil} are acceptable. |
|
|
|
|
|
@item |
|
|
A quoted constant---that is, @code{'@var{object}}. This sort of element |
|
|
in the list says that @var{object} itself is an acceptable value. |
|
|
@end itemize |
|
|
|
|
|
For example, |
|
587 |
|
|
588 |
@example |
@example |
589 |
(restricted-sexp :match-alternatives |
(@var{constructor} @var{arguments}@dots{}) |
|
(integerp 't 'nil)) |
|
590 |
@end example |
@end example |
591 |
|
|
592 |
@noindent |
@noindent |
593 |
allows integers, @code{t} and @code{nil} as legitimate values. |
but you can also add keyword-value pairs before the arguments, like |
594 |
|
this: |
595 |
|
|
596 |
The customization buffer shows all legitimate values using their read |
@example |
597 |
syntax, and the user edits them textually. |
(@var{constructor} @r{@{}@var{keyword} @var{value}@r{@}}@dots{} @var{arguments}@dots{}) |
598 |
|
@end example |
599 |
|
|
600 |
|
Here is a table of constructors and how to use them to write |
601 |
|
composite types: |
602 |
|
|
603 |
|
@table @code |
604 |
@item (cons @var{car-type} @var{cdr-type}) |
@item (cons @var{car-type} @var{cdr-type}) |
605 |
The value must be a cons cell, its @sc{car} must fit @var{car-type}, and |
The value must be a cons cell, its @sc{car} must fit @var{car-type}, and |
606 |
its @sc{cdr} must fit @var{cdr-type}. For example, @code{(cons string |
its @sc{cdr} must fit @var{cdr-type}. For example, @code{(cons string |
748 |
@var{element-type}. This appears in the customization buffer as a |
@var{element-type}. This appears in the customization buffer as a |
749 |
list of elements, with @samp{[INS]} and @samp{[DEL]} buttons for adding |
list of elements, with @samp{[INS]} and @samp{[DEL]} buttons for adding |
750 |
more elements or removing elements. |
more elements or removing elements. |
751 |
|
|
752 |
|
@item (restricted-sexp :match-alternatives @var{criteria}) |
753 |
|
This is the most general composite type construct. The value may be |
754 |
|
any Lisp object that satisfies one of @var{criteria}. @var{criteria} |
755 |
|
should be a list, and each element should be one of these |
756 |
|
possibilities: |
757 |
|
|
758 |
|
@itemize @bullet |
759 |
|
@item |
760 |
|
A predicate---that is, a function of one argument that has no side |
761 |
|
effects, and returns either @code{nil} or non-@code{nil} according to |
762 |
|
the argument. Using a predicate in the list says that objects for which |
763 |
|
the predicate returns non-@code{nil} are acceptable. |
764 |
|
|
765 |
|
@item |
766 |
|
A quoted constant---that is, @code{'@var{object}}. This sort of element |
767 |
|
in the list says that @var{object} itself is an acceptable value. |
768 |
|
@end itemize |
769 |
|
|
770 |
|
For example, |
771 |
|
|
772 |
|
@example |
773 |
|
(restricted-sexp :match-alternatives |
774 |
|
(integerp 't 'nil)) |
775 |
|
@end example |
776 |
|
|
777 |
|
@noindent |
778 |
|
allows integers, @code{t} and @code{nil} as legitimate values. |
779 |
|
|
780 |
|
The customization buffer shows all legitimate values using their read |
781 |
|
syntax, and the user edits them textually. |
782 |
|
@end table |
783 |
|
|
784 |
|
Here is a table of the keywords you can use in keyword-value pairs |
785 |
|
in a composite type: |
786 |
|
|
787 |
|
@table @code |
788 |
|
@item :tag @var{tag} |
789 |
|
Use @var{tag} as the name of this alternative, for user communication |
790 |
|
purposes. This is useful for a type that appears inside of a |
791 |
|
@code{choice}. |
792 |
|
|
793 |
|
@item :match-alternatives @var{criteria} |
794 |
|
Use @var{criteria} to match possible values. This is used only in |
795 |
|
@code{restricted-sexp}. |
796 |
|
|
797 |
|
@item :args @var{argumentlist} |
798 |
|
Use the elements of @var{argumentlist} as the arguments of the type |
799 |
|
construct. For instance, @code{(const :args (foo))} is equivalent to |
800 |
|
@code{(const foo)}. You rarely need to write @code{:args} explicitly, |
801 |
|
because normally the arguments are recognized automatically as |
802 |
|
whatever follows the last keyword-value pair. |
803 |
@end table |
@end table |
804 |
|
|
805 |
@node Splicing into Lists |
@node Splicing into Lists |