75 lines
9.5 KiB
HTML
75 lines
9.5 KiB
HTML
<!-- Common Lisp HyperSpec (TM), version 7.0 generated by Kent M. Pitman on Mon, 11-Apr-2005 2:31am EDT -->
|
|
<HTML>
|
|
<HEAD>
|
|
<TITLE>CLHS: Macro DEFTYPE</TITLE>
|
|
<LINK HREF="../Data/clhs.css" REL="stylesheet" TYPE="text/css" />
|
|
<META HTTP-EQUIV="Author" CONTENT="Kent M. Pitman">
|
|
<META HTTP-EQUIV="Organization" CONTENT="LispWorks Ltd.">
|
|
<LINK REL=TOP HREF="../Front/index.htm">
|
|
<LINK REL=COPYRIGHT HREF="../Front/Help.htm#Legal">
|
|
<LINK REL=DISCLAIMER HREF="../Front/Help.htm#Disclaimer">
|
|
<LINK REL=PREV HREF="f_coerce.htm">
|
|
<LINK REL=UP HREF="c_types_.htm">
|
|
<LINK REL=NEXT HREF="f_subtpp.htm">
|
|
</HEAD>
|
|
<BODY>
|
|
<H1><A REV=MADE HREF="http://www.lispworks.com/"><IMG WIDTH=80 HEIGHT=65 ALT="[LISPWORKS]" SRC="../Graphics/LWSmall.gif" ALIGN=Bottom></A><A REL=TOP HREF="../Front/index.htm"><IMG WIDTH=237 HEIGHT=65 ALT="[Common Lisp HyperSpec (TM)]" SRC="../Graphics/CLHS_Sm.gif" ALIGN=Bottom></A> <A REL=PREV HREF="f_coerce.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Previous]" SRC="../Graphics/Prev.gif" ALIGN=Bottom></A><A REL=UP HREF="c_types_.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Up]" SRC="../Graphics/Up.gif" ALIGN=Bottom></A><A REL=NEXT HREF="f_subtpp.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Next]" SRC="../Graphics/Next.gif" ALIGN=Bottom></A></H1>
|
|
|
|
<HR>
|
|
|
|
<A NAME="deftype"><I>Macro</I> <B>DEFTYPE</B></A> <P>
|
|
<P>
|
|
<P><B>Syntax:</B><P>
|
|
<P>
|
|
|
|
<B>deftype</B> <I>name lambda-list [[<I>declaration</I><B>*</B> | <I>documentation</I>]] <I>form</I><B>*</B></I> => <I>name</I><P>
|
|
<P>
|
|
<P><B>Arguments and Values:</B><P>
|
|
<P>
|
|
<I>name</I>---a <A REL=DEFINITION HREF="26_glo_s.htm#symbol"><I>symbol</I></A>. <P>
|
|
<I>lambda-list</I>---a <A REL=DEFINITION HREF="26_glo_d.htm#deftype_lambda_list"><I>deftype lambda list</I></A>. <P>
|
|
<I>declaration</I>---a <A REL=DEFINITION HREF="s_declar.htm#declare"><B>declare</B></A> <A REL=DEFINITION HREF="26_glo_e.htm#expression"><I>expression</I></A>; not evaluated. <P>
|
|
<I>documentation</I>---a <A REL=DEFINITION HREF="26_glo_s.htm#string"><I>string</I></A>; not evaluated. <P>
|
|
<I>form</I>---a <A REL=DEFINITION HREF="26_glo_f.htm#form"><I>form</I></A>. <P>
|
|
<P><B>Description:</B><P>
|
|
<P>
|
|
<A REL=DEFINITION HREF="#deftype"><B>deftype</B></A> defines a <A REL=DEFINITION HREF="26_glo_d.htm#derived_type_specifier"><I>derived type specifier</I></A> named <I>name</I>. <P>
|
|
The meaning of the new <A REL=DEFINITION HREF="26_glo_t.htm#type_specifier"><I>type specifier</I></A> is given in terms of a function which expands the <A REL=DEFINITION HREF="26_glo_t.htm#type_specifier"><I>type specifier</I></A> into another <A REL=DEFINITION HREF="26_glo_t.htm#type_specifier"><I>type specifier</I></A>, which itself will be expanded if it contains references to another <A REL=DEFINITION HREF="26_glo_d.htm#derived_type_specifier"><I>derived type specifier</I></A>. <P>
|
|
The newly defined <A REL=DEFINITION HREF="26_glo_t.htm#type_specifier"><I>type specifier</I></A> may be referenced as a list of the form <TT>(</TT><I>name</I><TT> </TT><I>arg</I>1<I></I><TT> </TT><I>arg</I>2<I></I><TT> ...)</TT>. The number of arguments must be appropriate to the <I>lambda-list</I>. If the new <A REL=DEFINITION HREF="26_glo_t.htm#type_specifier"><I>type specifier</I></A> takes no arguments, or if all of its arguments are optional, the <A REL=DEFINITION HREF="26_glo_t.htm#type_specifier"><I>type specifier</I></A> may be used as an <A REL=DEFINITION HREF="26_glo_a.htm#atomic_type_specifier"><I>atomic type specifier</I></A>. <P>
|
|
The <A REL=DEFINITION HREF="26_glo_a.htm#argument"><I>argument</I></A> <A REL=DEFINITION HREF="26_glo_e.htm#expression"><I>expressions</I></A> to the <A REL=DEFINITION HREF="26_glo_t.htm#type_specifier"><I>type specifier</I></A>, <I>arg1</I> ... <I>argn</I>, are not <I>evaluated</I>. Instead, these <A REL=DEFINITION HREF="26_glo_l.htm#literal"><I>literal</I></A> <A REL=DEFINITION HREF="26_glo_o.htm#object"><I>objects</I></A> become the <A REL=DEFINITION HREF="26_glo_o.htm#object"><I>objects</I></A> to which corresponding <A REL=DEFINITION HREF="26_glo_p.htm#parameter"><I>parameters</I></A> become <A REL=DEFINITION HREF="26_glo_b.htm#bound"><I>bound</I></A>. <P>
|
|
The body of the <A REL=DEFINITION HREF="#deftype"><B>deftype</B></A> <A REL=DEFINITION HREF="26_glo_f.htm#form"><I>form</I></A> (but not the <I>lambda-list</I>) is implicitly enclosed in a <A REL=DEFINITION HREF="26_glo_b.htm#block"><I>block</I></A> named <I>name</I>, and is evaluated as an <A REL=DEFINITION HREF="26_glo_i.htm#implicit_progn"><I>implicit progn</I></A>, returning a new <A REL=DEFINITION HREF="26_glo_t.htm#type_specifier"><I>type specifier</I></A>. <P>
|
|
The <A REL=DEFINITION HREF="26_glo_l.htm#lexical_environment"><I>lexical environment</I></A> of the body is the one which was current at the time the <A REL=DEFINITION HREF="#deftype"><B>deftype</B></A> form was evaluated, augmented by the <A REL=DEFINITION HREF="26_glo_v.htm#variable"><I>variables</I></A> in the <I>lambda-list</I>. <P>
|
|
Recursive expansion of the <A REL=DEFINITION HREF="26_glo_t.htm#type_specifier"><I>type specifier</I></A> returned as the expansion must terminate, including the expansion of <A REL=DEFINITION HREF="26_glo_t.htm#type_specifier"><I>type specifiers</I></A> which are nested within the expansion. <P>
|
|
The consequences are undefined if the result of fully expanding a <A REL=DEFINITION HREF="26_glo_t.htm#type_specifier"><I>type specifier</I></A> contains any circular structure, except within the <A REL=DEFINITION HREF="26_glo_o.htm#object"><I>objects</I></A> referred to by <A REL=DEFINITION HREF="t_member.htm#member"><B>member</B></A> and <A REL=DEFINITION HREF="t_eql.htm#eql"><B>eql</B></A> <A REL=DEFINITION HREF="26_glo_t.htm#type_specifier"><I>type specifiers</I></A>. <P>
|
|
<I>Documentation</I> is attached to <I>name</I> as a <A REL=DEFINITION HREF="26_glo_d.htm#documentation_string"><I>documentation string</I></A> of kind <A REL=DEFINITION HREF="a_type.htm#type"><B>type</B></A>. <P>
|
|
If a <A REL=DEFINITION HREF="#deftype"><B>deftype</B></A> <A REL=DEFINITION HREF="26_glo_f.htm#form"><I>form</I></A> appears as a <A REL=DEFINITION HREF="26_glo_t.htm#top_level_form"><I>top level form</I></A>, the <A REL=DEFINITION HREF="26_glo_c.htm#compiler"><I>compiler</I></A> must ensure that the <I>name</I> is recognized in subsequent <A REL=DEFINITION HREF="26_glo_t.htm#type"><I>type</I></A> declarations. The <A REL=DEFINITION HREF="26_glo_p.htm#programmer"><I>programmer</I></A> must ensure that the body of a <A REL=DEFINITION HREF="#deftype"><B>deftype</B></A> form can be <I>evaluated</I> at compile time if the <I>name</I> is referenced in subsequent <A REL=DEFINITION HREF="26_glo_t.htm#type"><I>type</I></A> declarations. If the expansion of a <A REL=DEFINITION HREF="26_glo_t.htm#type_specifier"><I>type specifier</I></A> is not defined fully at compile time (perhaps because it expands into an unknown <A REL=DEFINITION HREF="26_glo_t.htm#type_specifier"><I>type specifier</I></A> or a <B>satisfies</B> of a named <A REL=DEFINITION HREF="26_glo_f.htm#function"><I>function</I></A> that isn't defined in the compile-time environment), an <A REL=DEFINITION HREF="26_glo_i.htm#implementation"><I>implementation</I></A> may ignore any references to this <A REL=DEFINITION HREF="26_glo_t.htm#type"><I>type</I></A> in declarations and/or signal a warning. <P>
|
|
<P><B>Examples:</B><P>
|
|
|
|
<PRE>
|
|
(defun equidimensional (a)
|
|
(or (< (array-rank a) 2)
|
|
(apply #'= (array-dimensions a)))) => EQUIDIMENSIONAL
|
|
(deftype square-matrix (&optional type size)
|
|
`(and (array ,type (,size ,size))
|
|
(satisfies equidimensional))) => SQUARE-MATRIX
|
|
</PRE>
|
|
</TT> <P>
|
|
<P><B>Side Effects:</B> None.
|
|
<P>
|
|
<P><B>Affected By:</B> None.
|
|
<P>
|
|
<P><B>Exceptional Situations:</B> None.
|
|
<P>
|
|
<P><B>See Also:</B><P>
|
|
<P>
|
|
<A REL=DEFINITION HREF="s_declar.htm#declare"><B>declare</B></A>, <A REL=DEFINITION HREF="m_defmac.htm#defmacro"><B>defmacro</B></A>, <A REL=DEFINITION HREF="f_docume.htm#documentation"><B>documentation</B></A>, <A REL=CHILD HREF="04_bc.htm">Section 4.2.3 (Type Specifiers)</A>, <A REL=CHILD HREF="03_dk.htm">Section 3.4.11 (Syntactic Interaction of Documentation Strings and Declarations)</A> <P>
|
|
<P><B>Notes:</B> None.
|
|
<P>
|
|
<P>
|
|
<P><HR>The following <A REL=META HREF="../Front/X3J13Iss.htm">X3J13 cleanup issues</A>, <I>not part of the specification</I>, apply to this section:<P><UL><LI> <A REL=CHILD HREF="../Issues/iss059.htm">COMPILE-FILE-HANDLING-OF-TOP-LEVEL-FORMS:CLARIFY</A><LI> <A REL=CHILD HREF="../Issues/iss291.htm">RECURSIVE-DEFTYPE:EXPLICITLY-VAGUE</A><LI> <A REL=CHILD HREF="../Issues/iss104.htm">DEFINING-MACROS-NON-TOP-LEVEL:ALLOW</A><LI> <A REL=CHILD HREF="../Issues/iss161.htm">FLET-IMPLICIT-BLOCK:YES</A><LI> <A REL=CHILD HREF="../Issues/iss105.htm">DEFMACRO-BLOCK-SCOPE:EXCLUDES-BINDINGS</A><LI> <A REL=CHILD HREF="../Issues/iss097.htm">DECLS-AND-DOC</A><P></UL><HR>
|
|
|
|
<A REL=NAVIGATOR HREF="../Front/StartPts.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Starting Points]" SRC="../Graphics/StartPts.gif" ALIGN=Bottom></A><A REL=TOC HREF="../Front/Contents.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Contents]" SRC="../Graphics/Contents.gif" ALIGN=Bottom></A><A REL=INDEX HREF="../Front/X_Master.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Index]" SRC="../Graphics/Index.gif" ALIGN=Bottom></A><A REL=INDEX HREF="../Front/X_Symbol.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Symbols]" SRC="../Graphics/Symbols.gif" ALIGN=Bottom></A><A REL=GLOSSARY HREF="../Body/26_a.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Glossary]" SRC="../Graphics/Glossary.gif" ALIGN=Bottom></A><A HREF="../Front/X3J13Iss.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Issues]" SRC="../Graphics/Issues.gif" ALIGN=Bottom></A><BR>
|
|
|
|
<A REL=COPYRIGHT HREF="../Front/Help.htm#Legal"><I>Copyright 1996-2005, LispWorks Ltd. All rights reserved.</I></A><P>
|
|
</BODY>
|
|
</HTML>
|