My various dotfiles

chap-4.texi 100KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788
  1. @node Types and Classes, Data and Control Flow, Evaluation and Compilation, Top
  2. @chapter Types and Classes
  3. @menu
  4. * Introduction (Types and Classes)::
  5. * Types::
  6. * Classes::
  7. * Types and Classes Dictionary::
  8. @end menu
  9. @node Introduction (Types and Classes), Types, Types and Classes, Types and Classes
  10. @section Introduction
  11. @c including concept-type-intro
  12. A @i{type} is a (possibly infinite) set of @i{objects}.
  13. An @i{object} can belong to more than one @i{type}.
  14. @i{Types} are never explicitly represented as @i{objects} by @r{Common Lisp}.
  15. Instead, they are referred to indirectly by the use of @i{type specifiers},
  16. which are @i{objects} that denote @i{types}.
  17. New @i{types} can be defined using @b{deftype}, @b{defstruct},
  18. @b{defclass}, and @b{define-condition}.
  19. The @i{function} @b{typep}, a set membership test, is used to determine
  20. whether a given @i{object} is of a given @i{type}. The function
  21. @b{subtypep}, a subset test, is used to determine whether a
  22. given @i{type} is a @i{subtype} of another given @i{type}. The
  23. function @b{type-of} returns a particular @i{type} to
  24. which a given @i{object} belongs, even though that @i{object}
  25. must belong to one or more other @i{types} as well.
  26. (For example, every @i{object} is of @i{type} @b{t},
  27. but @b{type-of} always returns a @i{type specifier}
  28. for a @i{type} more specific than @b{t}.)
  29. @i{Objects}, not @i{variables}, have @i{types}.
  30. Normally, any @i{variable} can have any @i{object} as its @i{value}.
  31. It is possible to declare that a @i{variable} takes on only
  32. values of a given @i{type} by making an explicit @i{type declaration}.
  33. @i{Types} are arranged in a directed acyclic graph, except
  34. for the presence of equivalences.
  35. @i{Declarations} can be made about @i{types} using @b{declare},
  36. @b{proclaim}, @b{declaim}, or @b{the}.
  37. For more information about @i{declarations},
  38. see @ref{Declarations}.
  39. Among the fundamental @i{objects} of the object system are @i{classes}.
  40. A @i{class} determines the structure and behavior of a set of
  41. other @i{objects}, which are called its @i{instances}.
  42. Every @i{object} is a @i{direct instance} of a @i{class}.
  43. The @i{class} of an @i{object} determines the set of
  44. operations that can be performed on the @i{object}.
  45. For more information, see @ref{Classes}.
  46. It is possible to write @i{functions} that have behavior @i{specialized}
  47. to the class of the @i{objects} which are their @i{arguments}.
  48. For more information, see @ref{Generic Functions and Methods}.
  49. The @i{class} of the @i{class} of an @i{object}
  50. is called its @i{metaclass}
  51. @IGindex{metaclass}
  52. .
  53. For more information about @i{metaclasses},
  54. see @ref{Meta-Objects}.
  55. @c end of including concept-type-intro
  56. @node Types, Classes, Introduction (Types and Classes), Types and Classes
  57. @section Types
  58. @c including concept-types
  59. @menu
  60. * Data Type Definition::
  61. * Type Relationships::
  62. * Type Specifiers::
  63. @end menu
  64. @node Data Type Definition, Type Relationships, Types, Types
  65. @subsection Data Type Definition
  66. Information about @i{type} usage is located in
  67. the sections specified in @i{Figure~4--1}.
  68. @i{Figure~4--7} lists some @i{classes}
  69. that are particularly relevant to the object system.
  70. @i{Figure~9--1} lists the defined @i{condition} @i{types}.
  71. @group
  72. @noindent
  73. @w{ @b{Section} Data Type }
  74. @w{ _________________________________________________________________________}
  75. @w{ @ref{Classes} Object System types }
  76. @w{ @ref{Slots} Object System types }
  77. @w{ @ref{Objects} Object System types }
  78. @w{ @ref{Generic Functions and Methods} Object System types }
  79. @w{ @ref{Condition System Concepts} Condition System types }
  80. @w{ @ref{Types and Classes} Miscellaneous types }
  81. @w{ @ref{Syntax} All types---read and print syntax }
  82. @w{ @ref{The Lisp Printer} All types---print syntax }
  83. @w{ @ref{Compilation} All types---compilation issues }
  84. @noindent
  85. @w{ Figure 4--1: Cross-References to Data Type Information }
  86. @end group
  87. @node Type Relationships, Type Specifiers, Data Type Definition, Types
  88. @subsection Type Relationships
  89. @table @asis
  90. @item @t{*}
  91. The @i{types} @b{cons}, @b{symbol}, @b{array}, @b{number},
  92. @b{character}, @b{hash-table},
  93. @b{function},
  94. @b{readtable}, @b{package}, @b{pathname}, @b{stream},
  95. @b{random-state}, @b{condition}, @b{restart},
  96. and any single other @i{type} created by @b{defstruct},
  97. @b{define-condition},
  98. or @b{defclass} are @i{pairwise} @i{disjoint},
  99. except for type relations explicitly established by specifying
  100. @i{superclasses} in @b{defclass}
  101. or @b{define-condition}
  102. or the @t{:include} option of @b{destruct}.
  103. @item @t{*}
  104. Any two @i{types} created by @b{defstruct} are
  105. @i{disjoint} unless
  106. one is a @i{supertype} of the other by virtue of
  107. the @b{defstruct} @t{:include} option.
  108. [Editorial Note by KMP: The comments in the source say gray suggested some change
  109. from ``common superclass'' to ``common subclass'' in the following, but the
  110. result looks suspicious to me.]
  111. @item @t{*}
  112. Any two @i{distinct} @i{classes} created by @b{defclass}
  113. or @b{define-condition}
  114. are @i{disjoint} unless they have a common @i{subclass} or
  115. one @i{class} is a @i{subclass} of the other.
  116. @item @t{*}
  117. An implementation may be extended to add other @i{subtype}
  118. relationships between the specified @i{types}, as long as they do
  119. not violate the type relationships and disjointness requirements
  120. specified here. An implementation may define additional @i{types}
  121. that are @i{subtypes} or @i{supertypes} of any
  122. specified @i{types}, as long as each additional @i{type} is
  123. a @i{subtype} of @i{type} @b{t} and a @i{supertype} of @i{type} @b{nil} and the disjointness requirements
  124. are not violated.
  125. At the discretion of the implementation, either @b{standard-object}
  126. or @b{structure-object} might appear in any class precedence list
  127. for a @i{system class} that does not already specify either
  128. @b{standard-object} or @b{structure-object}. If it does,
  129. it must precede the @i{class} @b{t} and follow all other @i{standardized} @i{classes}.
  130. @end table
  131. @node Type Specifiers, , Type Relationships, Types
  132. @subsection Type Specifiers
  133. @i{Type specifiers} can be @i{symbols}, @i{classes}, or @i{lists}.
  134. @i{Figure~4--2} lists @i{symbols} that are
  135. @i{standardized} @i{atomic type specifiers}, and
  136. @i{Figure~4--3} lists
  137. @i{standardized} @i{compound type specifier} @i{names}.
  138. For syntax information, see the dictionary entry for the corresponding @i{type specifier}.
  139. It is possible to define new @i{type specifiers} using
  140. @b{defclass},
  141. @b{define-condition},
  142. @b{defstruct},
  143. or
  144. @b{deftype}.
  145. @group
  146. @noindent
  147. @w{ arithmetic-error function simple-condition }
  148. @w{ array generic-function simple-error }
  149. @w{ atom hash-table simple-string }
  150. @w{ base-char integer simple-type-error }
  151. @w{ base-string keyword simple-vector }
  152. @w{ bignum list simple-warning }
  153. @w{ bit logical-pathname single-float }
  154. @w{ bit-vector long-float standard-char }
  155. @w{ broadcast-stream method standard-class }
  156. @w{ built-in-class method-combination standard-generic-function }
  157. @w{ cell-error nil standard-method }
  158. @w{ character null standard-object }
  159. @w{ class number storage-condition }
  160. @w{ compiled-function package stream }
  161. @w{ complex package-error stream-error }
  162. @w{ concatenated-stream parse-error string }
  163. @w{ condition pathname string-stream }
  164. @w{ cons print-not-readable structure-class }
  165. @w{ control-error program-error structure-object }
  166. @w{ division-by-zero random-state style-warning }
  167. @w{ double-float ratio symbol }
  168. @w{ echo-stream rational synonym-stream }
  169. @w{ end-of-file reader-error t }
  170. @w{ error readtable two-way-stream }
  171. @w{ extended-char real type-error }
  172. @w{ file-error restart unbound-slot }
  173. @w{ file-stream sequence unbound-variable }
  174. @w{ fixnum serious-condition undefined-function }
  175. @w{ float short-float unsigned-byte }
  176. @w{ floating-point-inexact signed-byte vector }
  177. @w{ floating-point-invalid-operation simple-array warning }
  178. @w{ floating-point-overflow simple-base-string }
  179. @w{ floating-point-underflow simple-bit-vector }
  180. @noindent
  181. @w{ Figure 4--2: Standardized Atomic Type Specifiers }
  182. @end group
  183. \indent
  184. If a @i{type specifier} is a @i{list}, the @i{car} of the @i{list}
  185. is a @i{symbol}, and the rest of the @i{list} is subsidiary
  186. @i{type} information. Such a @i{type specifier} is called
  187. a @i{compound type specifier}
  188. @IGindex{compound type specifier}
  189. .
  190. Except as explicitly stated otherwise,
  191. the subsidiary items can be unspecified.
  192. The unspecified subsidiary items are indicated
  193. by writing @t{*}. For example, to completely specify
  194. a @i{vector}, the @i{type} of the elements
  195. and the length of the @i{vector} must be present.
  196. @example
  197. (vector double-float 100)
  198. @end example
  199. The following leaves the length unspecified:
  200. @example
  201. (vector double-float *)
  202. @end example
  203. The following leaves the element type unspecified:
  204. @example
  205. (vector * 100)
  206. @end example
  207. Suppose that two @i{type specifiers} are the same except that the first
  208. has a @t{*} where the second has a more explicit specification.
  209. Then the second denotes a @i{subtype}
  210. of the @i{type} denoted by the first.
  211. If a @i{list} has one or more unspecified items at the end,
  212. those items can be dropped.
  213. If dropping all occurrences of @t{*} results in a @i{singleton} @i{list},
  214. then the parentheses can be dropped as well (the list can be replaced
  215. by the @i{symbol} in its @i{car}).
  216. For example,
  217. @t{(vector double-float *)}
  218. can be abbreviated to @t{(vector double-float)},
  219. and @t{(vector * *)} can be abbreviated to @t{(vector)}
  220. and then to
  221. @t{vector}.
  222. @group
  223. @noindent
  224. @w{ and long-float simple-base-string }
  225. @w{ array member simple-bit-vector }
  226. @w{ base-string mod simple-string }
  227. @w{ bit-vector not simple-vector }
  228. @w{ complex or single-float }
  229. @w{ cons rational string }
  230. @w{ double-float real unsigned-byte }
  231. @w{ eql satisfies values }
  232. @w{ float short-float vector }
  233. @w{ function signed-byte }
  234. @w{ integer simple-array }
  235. @noindent
  236. @w{ Figure 4--3: Standardized Compound Type Specifier Names}
  237. @end group
  238. Figure 4--4 show the @i{defined names} that can be used as
  239. @i{compound type specifier} @i{names}
  240. but that cannot be used as @i{atomic type specifiers}.
  241. @group
  242. @noindent
  243. @w{ and mod satisfies }
  244. @w{ eql not values }
  245. @w{ member or }
  246. @noindent
  247. @w{ Figure 4--4: Standardized Compound-Only Type Specifier Names}
  248. @end group
  249. New @i{type specifiers} can come into existence in two ways.
  250. @table @asis
  251. @item @t{*}
  252. Defining a structure by using @b{defstruct} without using
  253. the @t{:type} specifier or defining a @i{class} by using
  254. @b{defclass}
  255. or @b{define-condition}
  256. automatically causes the name of the structure
  257. or class to be a new @i{type specifier} @i{symbol}.
  258. @item @t{*}
  259. @b{deftype} can be used to define @i{derived type specifiers}
  260. @IGindex{derived type specifier}
  261. ,
  262. which act as `abbreviations' for other @i{type specifiers}.
  263. @end table
  264. A @i{class} @i{object} can be used as a @i{type specifier}.
  265. When used this way, it denotes the set of all members of that @i{class}.
  266. Figure 4--5 shows some @i{defined names} relating to
  267. @i{types} and @i{declarations}.
  268. @group
  269. @noindent
  270. @w{ coerce defstruct subtypep }
  271. @w{ declaim deftype the }
  272. @w{ declare ftype type }
  273. @w{ defclass locally type-of }
  274. @w{ define-condition proclaim typep }
  275. @noindent
  276. @w{ Figure 4--5: Defined names relating to types and declarations.}
  277. @end group
  278. Figure 4--6 shows all @i{defined names} that are @i{type specifier} @i{names},
  279. whether for @i{atomic type specifiers} or @i{compound type specifiers};
  280. this list is the union of the lists in @i{Figure~4--2}
  281. and @i{Figure~4--3}.
  282. @group
  283. @noindent
  284. @w{ and function simple-array }
  285. @w{ arithmetic-error generic-function simple-base-string }
  286. @w{ array hash-table simple-bit-vector }
  287. @w{ atom integer simple-condition }
  288. @w{ base-char keyword simple-error }
  289. @w{ base-string list simple-string }
  290. @w{ bignum logical-pathname simple-type-error }
  291. @w{ bit long-float simple-vector }
  292. @w{ bit-vector member simple-warning }
  293. @w{ broadcast-stream method single-float }
  294. @w{ built-in-class method-combination standard-char }
  295. @w{ cell-error mod standard-class }
  296. @w{ character nil standard-generic-function }
  297. @w{ class not standard-method }
  298. @w{ compiled-function null standard-object }
  299. @w{ complex number storage-condition }
  300. @w{ concatenated-stream or stream }
  301. @w{ condition package stream-error }
  302. @w{ cons package-error string }
  303. @w{ control-error parse-error string-stream }
  304. @w{ division-by-zero pathname structure-class }
  305. @w{ double-float print-not-readable structure-object }
  306. @w{ echo-stream program-error style-warning }
  307. @w{ end-of-file random-state symbol }
  308. @w{ eql ratio synonym-stream }
  309. @w{ error rational t }
  310. @w{ extended-char reader-error two-way-stream }
  311. @w{ file-error readtable type-error }
  312. @w{ file-stream real unbound-slot }
  313. @w{ fixnum restart unbound-variable }
  314. @w{ float satisfies undefined-function }
  315. @w{ floating-point-inexact sequence unsigned-byte }
  316. @w{ floating-point-invalid-operation serious-condition values }
  317. @w{ floating-point-overflow short-float vector }
  318. @w{ floating-point-underflow signed-byte warning }
  319. @noindent
  320. @w{ Figure 4--6: Standardized Type Specifier Names }
  321. @end group
  322. @c end of including concept-types
  323. @node Classes, Types and Classes Dictionary, Types, Types and Classes
  324. @section Classes
  325. @c including concept-classes
  326. While the object system is general enough to describe all @i{standardized} @i{classes}
  327. (including, for example, @b{number}, @b{hash-table}, and
  328. @b{symbol}), Figure 4--7 contains a list of @i{classes} that are
  329. especially relevant to understanding the object system.
  330. @group
  331. @noindent
  332. @w{ built-in-class method-combination standard-object }
  333. @w{ class standard-class structure-class }
  334. @w{ generic-function standard-generic-function structure-object }
  335. @w{ method standard-method }
  336. @noindent
  337. @w{ Figure 4--7: Object System Classes }
  338. @end group
  339. @menu
  340. * Introduction to Classes::
  341. * Defining Classes::
  342. * Creating Instances of Classes::
  343. * Inheritance::
  344. * Determining the Class Precedence List::
  345. * Redefining Classes::
  346. * Integrating Types and Classes::
  347. @end menu
  348. @node Introduction to Classes, Defining Classes, Classes, Classes
  349. @subsection Introduction to Classes
  350. A @i{class}
  351. @IGindex{class}
  352. is an @i{object} that determines the structure and behavior
  353. of a set of other @i{objects}, which are called its @i{instances}
  354. @IGindex{instance}
  355. .
  356. A @i{class} can inherit structure and behavior from other @i{classes}.
  357. A @i{class} whose definition refers to other @i{classes} for the purpose
  358. of inheriting from them is said to be a @i{subclass} of each of
  359. those @i{classes}. The @i{classes} that are designated for purposes of
  360. inheritance are said to be @i{superclasses} of the inheriting @i{class}.
  361. A @i{class} can have a @i{name}. The @i{function} @b{class-name}
  362. takes a @i{class} @i{object} and returns its @i{name}.
  363. The @i{name} of an anonymous @i{class} is @b{nil}. A @i{symbol}
  364. can @i{name} a @i{class}. The @i{function} @b{find-class} takes a
  365. @i{symbol} and returns the @i{class} that the @i{symbol} names.
  366. A @i{class} has a @i{proper name} if the @i{name} is a @i{symbol}
  367. and if the @i{name} of the @i{class} names that @i{class}.
  368. That is, a @i{class}~C has the @i{proper name}~S if S=
  369. @t{(class-name C)} and C= @t{(find-class S)}.
  370. Notice that it is possible for
  371. @t{(find-class S_1)} = @t{(find-class S_2)}
  372. and S_1!= S_2.
  373. If C= @t{(find-class S)}, we say that C is the @i{class} @i{named} S.
  374. A @i{class} C_1 is
  375. a @i{direct superclass}
  376. @IGindex{direct superclass}
  377. of a @i{class} C_2
  378. if C_2 explicitly designates C_1
  379. as a @i{superclass} in its definition.
  380. In this case C_2 is a @i{direct subclass}
  381. @IGindex{direct subclass}
  382. of C_1.
  383. A @i{class} C_n is a @i{superclass}
  384. @IGindex{superclass}
  385. of
  386. a @i{class} C_1 if there exists a series of
  387. @i{classes} C_2,...,C_@{n-1@} such that
  388. C_@{i+1@} is a @i{direct superclass} of C_i for 1 <= i<n.
  389. In this case, C_1 is a @i{subclass}
  390. @IGindex{subclass}
  391. of C_n.
  392. A @i{class} is considered neither a @i{superclass} nor a @i{subclass} of itself.
  393. That is, if C_1 is a @i{superclass} of C_2,
  394. then C_1 != C_2.
  395. The set of @i{classes} consisting of some given @i{class} C
  396. along with all of its @i{superclasses} is called ``C and its superclasses.''
  397. Each @i{class} has a @i{class precedence list}
  398. @IGindex{class precedence list}
  399. ,
  400. which is a total ordering on the set of the given @i{class} and its @i{superclasses}.
  401. The total ordering is expressed as a list ordered from most specific to least specific.
  402. The @i{class precedence list} is used in several ways. In general, more
  403. specific @i{classes} can @i{shadow}
  404. @IGindex{shadow}
  405. _1 features that would
  406. otherwise be inherited from less specific @i{classes}.
  407. The @i{method} selection and combination process uses
  408. the @i{class precedence list} to order @i{methods}
  409. from most specific to least specific.
  410. When a @i{class} is defined, the order in which its direct @i{superclasses}
  411. are mentioned in the defining form is important. Each @i{class} has a
  412. @i{local precedence order}
  413. @IGindex{local precedence order}
  414. , which is a @i{list} consisting of the
  415. @i{class} followed by its @i{direct superclasses} in the order mentioned
  416. in the defining @i{form}.
  417. A @i{class precedence list} is always consistent with the
  418. @i{local precedence order} of each @i{class} in the list.
  419. The @i{classes} in each @i{local precedence order} appear
  420. within the @i{class precedence list} in the same order.
  421. If the @i{local precedence orders} are inconsistent with each other,
  422. no @i{class precedence list} can be constructed, and an error is signaled.
  423. The @i{class precedence list} and its computation is discussed
  424. in @ref{Determining the Class Precedence List}.
  425. @i{classes} are organized into a directed acyclic graph.
  426. There are two distinguished @i{classes}, named @b{t} and @b{standard-object}.
  427. The @i{class} named @b{t} has no @i{superclasses}.
  428. It is a @i{superclass} of every @i{class} except itself.
  429. The @i{class} named @b{standard-object} is an @i{instance} of
  430. the @i{class} @b{standard-class} and is a @i{superclass} of
  431. every @i{class} that is an @i{instance} of the @i{class} @b{standard-class} except itself.
  432. [Reviewer Note by Barmar: This or something like it needs to be said in the introduction.]
  433. There is a mapping from the object system @i{class} space into
  434. the @i{type} space. Many of the standard @i{types} specified
  435. in this document have a corresponding @i{class} that has the same
  436. @i{name} as the @i{type}. Some @i{types} do not have a
  437. corresponding @i{class}. The integration of the @i{type} and @i{class}
  438. systems is discussed in @ref{Integrating Types and Classes}.
  439. @i{Classes} are represented by @i{objects} that are themselves
  440. @i{instances} of @i{classes}.
  441. The @i{class} of the @i{class} of an @i{object} is termed
  442. the @i{metaclass}
  443. @IGindex{metaclass}
  444. of that @i{object}. When no misinterpretation is
  445. possible, the term @i{metaclass} is used to refer to a @i{class}
  446. that has @i{instances} that are themselves @i{classes}. The @i{metaclass}
  447. determines the form of inheritance used by the @i{classes} that are its
  448. @i{instances} and the representation of the @i{instances} of those @i{classes}.
  449. The object system provides a default @i{metaclass}, @b{standard-class}, that is
  450. appropriate for most programs.
  451. Except where otherwise specified, all @i{classes} mentioned in this
  452. standard are @i{instances} of the @i{class} @b{standard-class},
  453. all @i{generic functions} are @i{instances}
  454. of the @i{class} @b{standard-generic-function},
  455. and all @i{methods} are @i{instances} of the @i{class} @b{standard-method}.
  456. @menu
  457. * Standard Metaclasses::
  458. @end menu
  459. @node Standard Metaclasses, , Introduction to Classes, Introduction to Classes
  460. @subsubsection Standard Metaclasses
  461. The object system provides a number of predefined @i{metaclasses}.
  462. These include the @i{classes} @b{standard-class},
  463. @b{built-in-class}, and @b{structure-class}:
  464. @table @asis
  465. @item @t{*}
  466. The @i{class} @b{standard-class} is the default @i{class} of
  467. @i{classes} defined by @b{defclass}.
  468. @item @t{*}
  469. The @i{class} @b{built-in-class} is the @i{class} whose
  470. @i{instances} are @i{classes} that have special implementations with
  471. restricted capabilities. Any @i{class} that corresponds to a standard
  472. @i{type} might be an @i{instance} of @b{built-in-class}.
  473. The predefined @i{type} specifiers that are required to have
  474. corresponding @i{classes} are listed in @i{Figure~4--8}.
  475. It is @i{implementation-dependent} whether each of these @i{classes}
  476. is implemented as a @i{built-in class}.
  477. @item @t{*}
  478. All @i{classes} defined by means of @b{defstruct} are
  479. @i{instances} of the @i{class} @b{structure-class}.
  480. @end table
  481. @node Defining Classes, Creating Instances of Classes, Introduction to Classes, Classes
  482. @subsection Defining Classes
  483. The macro @b{defclass} is used to define a new named @i{class}.
  484. The definition of a @i{class} includes:
  485. @table @asis
  486. @item @t{*}
  487. The @i{name} of the new @i{class}.
  488. For newly-defined @i{classes} this @i{name} is a @i{proper name}.
  489. @item @t{*}
  490. The list of the direct @i{superclasses} of the new @i{class}.
  491. @item @t{*}
  492. A set of @i{slot specifiers}
  493. @IGindex{slot specifier}
  494. .
  495. Each @i{slot specifier} includes the @i{name} of the @i{slot}
  496. and zero or more @i{slot} options. A @i{slot} option pertains
  497. only to a single @i{slot}. If a @i{class} definition contains
  498. two @i{slot specifiers} with the same @i{name}, an error is signaled.
  499. @item @t{*}
  500. A set of @i{class} options.
  501. Each @i{class} option pertains to the @i{class} as a whole.
  502. @end table
  503. The @i{slot} options and @i{class} options of
  504. the @b{defclass} form provide mechanisms for the following:
  505. @table @asis
  506. @item @t{*}
  507. Supplying a default initial value @i{form}
  508. for a given @i{slot}.
  509. @item @t{*}
  510. Requesting that @i{methods} for @i{generic functions}
  511. be automatically generated for reading or writing @i{slots}.
  512. @item @t{*}
  513. Controlling whether a given @i{slot} is shared by
  514. all @i{instances}
  515. of the @i{class} or whether each
  516. @i{instance} of the @i{class} has its own @i{slot}.
  517. @item @t{*}
  518. Supplying a set of initialization arguments and initialization
  519. argument defaults to be used in @i{instance} creation.
  520. @item @t{*}
  521. Indicating that the @i{metaclass} is to be other
  522. than the default. The @t{:metaclass} option is reserved for future use;
  523. an implementation can be extended to make use of the @t{:metaclass}
  524. option.
  525. @item @t{*}
  526. Indicating the expected @i{type} for the value stored
  527. in the @i{slot}.
  528. @item @t{*}
  529. Indicating the @i{documentation string} for the @i{slot}.
  530. @end table
  531. @node Creating Instances of Classes, Inheritance, Defining Classes, Classes
  532. @subsection Creating Instances of Classes
  533. The generic function @b{make-instance} creates and returns a new
  534. @i{instance} of a @i{class}.
  535. The object system provides several mechanisms for
  536. specifying how a new @i{instance} is to be initialized. For example, it
  537. is possible to specify the initial values for @i{slots} in newly created
  538. @i{instances}
  539. either by giving arguments to @b{make-instance} or by
  540. providing default initial values. Further initialization activities
  541. can be performed by @i{methods} written for @i{generic functions}
  542. that are
  543. part of the initialization protocol. The complete initialization
  544. protocol is described in @ref{Object Creation and Initialization}.
  545. @node Inheritance, Determining the Class Precedence List, Creating Instances of Classes, Classes
  546. @subsection Inheritance
  547. A @i{class} can inherit @i{methods}, @i{slots},
  548. and some @b{defclass} options from its @i{superclasses}.
  549. Other sections describe the inheritance of @i{methods},
  550. the inheritance of @i{slots} and @i{slot} options,
  551. and the inheritance of @i{class} options.
  552. @menu
  553. * Examples of Inheritance::
  554. * Inheritance of Class Options::
  555. @end menu
  556. @node Examples of Inheritance, Inheritance of Class Options, Inheritance, Inheritance
  557. @subsubsection Examples of Inheritance
  558. @example
  559. (defclass C1 ()
  560. ((S1 :initform 5.4 :type number)
  561. (S2 :allocation :class)))
  562. (defclass C2 (C1)
  563. ((S1 :initform 5 :type integer)
  564. (S2 :allocation :instance)
  565. (S3 :accessor C2-S3)))
  566. @end example
  567. @i{Instances} of the class @t{C1} have a @i{local slot} named @t{S1},
  568. whose default initial value is 5.4 and
  569. whose @i{value} should always be a @i{number}.
  570. The class @t{C1} also has a @i{shared slot} named @t{S2}.
  571. There is a @i{local slot} named @t{S1} in @i{instances} of @t{C2}.
  572. The default initial value of @t{S1} is 5.
  573. The value of @t{S1} should always be of type @t{(and integer number)}.
  574. There are also @i{local slots} named @t{S2} and @t{S3} in @i{instances} of @t{C2}.
  575. The class @t{C2} has a @i{method} for @t{C2-S3} for reading the value of slot @t{S3};
  576. there is also a @i{method} for @t{(setf C2-S3)} that writes the value of @t{S3}.
  577. @node Inheritance of Class Options, , Examples of Inheritance, Inheritance
  578. @subsubsection Inheritance of Class Options
  579. The @t{:default-initargs} class option is inherited. The set of
  580. defaulted initialization arguments for a @i{class} is the union of the
  581. sets of initialization arguments supplied in
  582. the @t{:default-initargs} class options of the @i{class} and its @i{superclasses}.
  583. When more than one default initial value @i{form} is supplied for a given
  584. initialization argument, the default initial value @i{form} that is used
  585. is the one supplied by the @i{class} that is most specific according to
  586. the @i{class precedence list}.
  587. If a given @t{:default-initargs} class option specifies an
  588. initialization argument of the same @i{name} more than once, an
  589. error of @i{type} @b{program-error} is signaled.
  590. @node Determining the Class Precedence List, Redefining Classes, Inheritance, Classes
  591. @subsection Determining the Class Precedence List
  592. The @b{defclass} form for a @i{class} provides a total ordering
  593. on that @i{class} and its direct @i{superclasses}. This ordering is
  594. called the @i{local precedence order}
  595. @IGindex{local precedence order}
  596. . It is an ordered list of the
  597. @i{class} and its direct @i{superclasses}. The
  598. @i{class precedence list}
  599. @IGindex{class precedence list}
  600. for a class C is a total ordering on
  601. C and its @i{superclasses} that is consistent with the
  602. @i{local precedence orders} for each of C and its @i{superclasses}.
  603. A @i{class} precedes its direct @i{superclasses},
  604. and a direct @i{superclass} precedes all other
  605. direct @i{superclasses} specified to its right
  606. in the @i{superclasses} list of the @b{defclass} form.
  607. For every class C, define
  608. @center R_C=@{(C,C_1),(C_1,C_2),...,(C_@{n-1@},C_n)@}
  609. where C_1,...,C_n are
  610. the direct @i{superclasses} of C in the order in which
  611. they are mentioned in the @b{defclass} form. These ordered pairs
  612. generate the total ordering on the class C and its direct
  613. @i{superclasses}.
  614. Let S_C be the set of C and its @i{superclasses}. Let R be
  615. @center R=\bigcup_@{c\in {S_C}@}R_c
  616. .
  617. [Reviewer Note by Barmar: ``Consistent'' needs to be defined, or maybe we should say
  618. ``logically consistent''?]
  619. The set R might or might not generate a partial ordering, depending on
  620. whether the R_c, c\in S_C, are
  621. consistent; it is assumed
  622. that they are consistent and that R generates a partial ordering.
  623. When the R_c are not consistent, it is said that R is inconsistent.
  624. To compute the @i{class precedence list} for~C,
  625. topologically sort the elements of S_C with respect to the
  626. partial ordering generated by R. When the topological
  627. sort must select a @i{class} from a set of two or more
  628. @i{classes}, none of
  629. which are preceded by other @i{classes} with respect to~R,
  630. the @i{class} selected is chosen deterministically, as described below.
  631. If R is inconsistent, an error is signaled.
  632. @menu
  633. * Topological Sorting::
  634. * Examples of Class Precedence List Determination::
  635. @end menu
  636. @node Topological Sorting, Examples of Class Precedence List Determination, Determining the Class Precedence List, Determining the Class Precedence List
  637. @subsubsection Topological Sorting
  638. Topological sorting proceeds by finding a class C in~S_C such
  639. that no other @i{class} precedes that element according to the elements
  640. in~R. The class C is placed first in the result.
  641. Remove C from S_C, and remove all pairs of the form (C,D),
  642. D\in S_C, from R. Repeat the process, adding
  643. @i{classes} with no predecessors to the end of the result. Stop when no
  644. element can be found that has no predecessor.
  645. If S_C is not empty and the process has stopped, the set R is
  646. inconsistent. If every @i{class} in the finite set of
  647. @i{classes} is preceded
  648. by another, then R contains a loop. That is, there is a chain of
  649. classes C_1,...,C_n such that C_i precedes
  650. C_@{i+1@}, 1<= i<n, and C_n precedes C_1.
  651. Sometimes there are several @i{classes} from S_C with no
  652. predecessors. In this case select the one that has a direct
  653. @i{subclass} rightmost in the @i{class precedence list} computed so far.
  654. (If there is no such candidate @i{class}, R does not generate
  655. a partial ordering---the R_c, c\in S_C, are inconsistent.)
  656. In more precise terms, let @{N_1,...,N_m@}, m>= 2, be
  657. the @i{classes} from S_C with no predecessors. Let (C_1... C_n), n>= 1, be the @i{class precedence list}
  658. constructed so far. C_1 is the most specific @i{class}, and C_n is the least specific. Let 1<= j<= n be the largest number
  659. such that there exists an i where 1<= i<= m and N_i
  660. is a direct @i{superclass} of C_j; N_i is placed next.
  661. The effect of this rule for selecting from a set of @i{classes} with no
  662. predecessors is that the @i{classes} in a simple @i{superclass} chain are
  663. adjacent in the @i{class precedence list} and that @i{classes} in each
  664. relatively separated subgraph are adjacent in the @i{class precedence list}.
  665. For example, let T_1 and T_2 be subgraphs whose only
  666. element in common is the class J.
  667. Suppose that no superclass of J appears in either T_1 or T_2,
  668. and that J is in the superclass chain of every class in both T_1 and T_2.
  669. Let C_1 be the bottom of T_1;
  670. and let C_2 be the bottom of T_2.
  671. Suppose C is a @i{class} whose direct @i{superclasses}
  672. are C_1 and C_2 in that order, then the @i{class precedence list}
  673. for C starts with C and is followed by
  674. all @i{classes} in T_1 except J.
  675. All the @i{classes} of T_2 are next.
  676. The @i{class} J and its @i{superclasses} appear last.
  677. @node Examples of Class Precedence List Determination, , Topological Sorting, Determining the Class Precedence List
  678. @subsubsection Examples of Class Precedence List Determination
  679. This example determines a @i{class precedence list} for the
  680. class @t{pie}. The following @i{classes} are defined:
  681. @example
  682. (defclass pie (apple cinnamon) ())
  683. (defclass apple (fruit) ())
  684. (defclass cinnamon (spice) ())
  685. (defclass fruit (food) ())
  686. (defclass spice (food) ())
  687. (defclass food () ())
  688. @end example
  689. The set S_@{pie@}~= @{{pie, apple, cinnamon, fruit, spice, food,
  690. standard-object, t}@}. The set R~= @{{(pie, apple),
  691. (apple, cinnamon), (apple, fruit), (cinnamon, spice), \break
  692. (fruit, food), (spice, food), (food, standard-object), (standard-object,
  693. t)}@}.
  694. The class @t{pie} is not preceded by anything, so it comes first;
  695. the result so far is @t{(pie)}. Remove @t{pie} from S and pairs
  696. mentioning @t{pie} from R to get S~= @{{apple, cinnamon,
  697. fruit, spice, food, standard-object, t}@} and R~=~@{{(apple, cinnamon), (apple, fruit), (cinnamon, spice),\break (fruit,
  698. food), (spice, food), (food, standard-object),
  699. (standard-object, t)}@}.
  700. The class @t{apple} is not preceded by anything, so it is next; the
  701. result is @t{(pie apple)}. Removing @t{apple} and the relevant
  702. pairs results in S~= @{{cinnamon, fruit, spice, food,
  703. standard-object, t}@} and R~= @{{(cinnamon, spice),
  704. (fruit, food), (spice, food), (food, standard-object),\break
  705. (standard-object, t)}@}.
  706. The classes @t{cinnamon} and @t{fruit} are not preceded by
  707. anything, so the one with a direct @i{subclass} rightmost in the
  708. @i{class precedence list} computed so far goes next. The class @t{apple} is a
  709. direct @i{subclass} of @t{fruit}, and the class @t{pie} is a direct
  710. @i{subclass} of @t{cinnamon}. Because @t{apple} appears to the right
  711. of @t{pie} in the @i{class precedence list},
  712. @t{fruit} goes next, and the
  713. result so far is @t{(pie apple fruit)}. S~= @{{cinnamon,
  714. spice, food, standard-object, t}@}; R~= @{{(cinnamon,
  715. spice), (spice, food),\break (food, standard-object),
  716. (standard-object, t)}@}.
  717. The class @t{cinnamon} is next, giving the result so far as @t{(pie apple fruit cinnamon)}. At this point S~= @{{spice,
  718. food, standard-object, t}@}; R~= @{{(spice, food), (food,
  719. standard-object), (standard-object, t)}@}.
  720. The classes @t{spice}, @t{food}, @b{standard-object}, and
  721. @b{t} are added in that order, and the @i{class precedence list}
  722. is @t{(pie apple fruit cinnamon spice food standard-object t)}.
  723. It is possible to write a set of @i{class} definitions that cannot be
  724. ordered. For example:
  725. @example
  726. (defclass new-class (fruit apple) ())
  727. (defclass apple (fruit) ())
  728. @end example
  729. The class @t{fruit} must precede @t{apple}
  730. because the local ordering of @i{superclasses} must be preserved.
  731. The class @t{apple} must precede @t{fruit}
  732. because a @i{class} always precedes its own @i{superclasses}.
  733. When this situation occurs, an error is signaled, as happens here
  734. when the system tries to compute the @i{class precedence list}
  735. of @t{new-class}.
  736. The following might appear to be a conflicting set of definitions:
  737. @example
  738. (defclass pie (apple cinnamon) ())
  739. (defclass pastry (cinnamon apple) ())
  740. (defclass apple () ())
  741. (defclass cinnamon () ())
  742. @end example
  743. The @i{class precedence list} for @t{pie} is
  744. @t{(pie apple cinnamon standard-object t)}.
  745. The @i{class precedence list} for @t{pastry} is
  746. @t{(pastry cinnamon apple standard-object t)}.
  747. It is not a problem for @t{apple} to precede @t{cinnamon} in the
  748. ordering of the @i{superclasses} of @t{pie} but not in the ordering for
  749. @t{pastry}. However, it is not possible to build a new @i{class} that
  750. has both @t{pie} and @t{pastry} as @i{superclasses}.
  751. @node Redefining Classes, Integrating Types and Classes, Determining the Class Precedence List, Classes
  752. @subsection Redefining Classes
  753. A @i{class} that is a @i{direct instance} of @b{standard-class} can
  754. be redefined if the new @i{class} is also
  755. a @i{direct instance} of @b{standard-class}.
  756. Redefining a @i{class} modifies the existing
  757. @i{class} @i{object} to reflect the new @i{class} definition; it does not
  758. create a new @i{class} @i{object} for the @i{class}.
  759. Any @i{method} @i{object} created by a @t{:reader}, @t{:writer},
  760. or @t{:accessor} option specified by the old @b{defclass} form is
  761. removed from the corresponding @i{generic function}.
  762. @i{Methods} specified by the new @b{defclass} form are added.
  763. When the class C is redefined, changes are propagated to its @i{instances}
  764. and to @i{instances} of any of its @i{subclasses}. Updating such an
  765. @i{instance} occurs at an @i{implementation-dependent} time, but no later than
  766. the next time a @i{slot}
  767. of that @i{instance} is read or written. Updating an
  768. @i{instance}
  769. does not change its identity as defined by the @i{function} @b{eq}.
  770. The updating process may change the @i{slots} of that
  771. particular @i{instance},
  772. but it does not create a new @i{instance}. Whether
  773. updating an @i{instance} consumes storage is @i{implementation-dependent}.
  774. Note that redefining a @i{class} may cause @i{slots} to be added or
  775. deleted. If a @i{class} is redefined in a way that changes the set of
  776. @i{local slots} @i{accessible} in @i{instances}, the @i{instances}
  777. are updated. It is @i{implementation-dependent} whether @i{instances}
  778. are updated if a @i{class} is redefined in a way that does not change
  779. the set of @i{local slots} @i{accessible} in @i{instances}.
  780. The value of a @i{slot}
  781. that is specified as shared both in the old @i{class}
  782. and in the new @i{class} is retained.
  783. If such a @i{shared slot} was unbound
  784. in the old @i{class}, it is unbound in the new @i{class}.
  785. @i{Slots} that
  786. were local in the old @i{class} and that are shared in the new
  787. @i{class} are
  788. initialized. Newly added @i{shared slots} are initialized.
  789. Each newly added @i{shared slot} is set to the result of evaluating the
  790. @i{captured initialization form} for the @i{slot} that was specified
  791. in the @b{defclass} @i{form} for the new @i{class}.
  792. If there was no @i{initialization form}, the @i{slot} is unbound.
  793. If a @i{class} is redefined in such a way that the set of
  794. @i{local slots} @i{accessible} in an @i{instance} of the @i{class}
  795. is changed, a two-step process of updating the @i{instances} of the
  796. @i{class} takes place. The process may be explicitly started by
  797. invoking the generic function @b{make-instances-obsolete}. This
  798. two-step process can happen in other circumstances in some implementations.
  799. For example, in some implementations this two-step process is
  800. triggered if the order of @i{slots} in storage is changed.
  801. The first step modifies the structure of the @i{instance} by adding new
  802. @i{local slots} and discarding @i{local slots} that are not
  803. defined in the new version of the @i{class}. The second step
  804. initializes the newly-added @i{local slots} and performs any other
  805. user-defined actions. These two steps are further specified
  806. in the next two sections.
  807. @menu
  808. * Modifying the Structure of Instances::
  809. * Initializing Newly Added Local Slots (Redefining Classes)::
  810. * Customizing Class Redefinition::
  811. @end menu
  812. @node Modifying the Structure of Instances, Initializing Newly Added Local Slots (Redefining Classes), Redefining Classes, Redefining Classes
  813. @subsubsection Modifying the Structure of Instances
  814. [Reviewer Note by Barmar: What about shared slots that are deleted?]
  815. The first step modifies the structure of @i{instances} of the redefined
  816. @i{class} to conform to its new @i{class} definition.
  817. @i{Local slots} specified
  818. by the new @i{class} definition that are not specified as either local or
  819. shared by the old @i{class} are added, and @i{slots}
  820. not specified as either
  821. local or shared by the new @i{class} definition that are specified as
  822. local by the old @i{class} are discarded.
  823. The @i{names} of these added and discarded
  824. @i{slots} are passed as arguments
  825. to @b{update-instance-for-redefined-class}
  826. as described in the next section.
  827. The values of @i{local slots} specified by both the new and old
  828. @i{classes} are retained. If such a @i{local slot} was unbound,
  829. it remains unbound.
  830. The value of a @i{slot} that is specified as shared in the old
  831. @i{class} and as local in the new @i{class} is retained. If such
  832. a @i{shared slot} was unbound, the @i{local slot} is unbound.
  833. @node Initializing Newly Added Local Slots (Redefining Classes), Customizing Class Redefinition, Modifying the Structure of Instances, Redefining Classes
  834. @subsubsection Initializing Newly Added Local Slots
  835. The second step initializes the newly added @i{local slots} and performs
  836. any other user-defined actions. This step is implemented by the generic
  837. function @b{update-instance-for-redefined-class}, which is called after
  838. completion of the first step of modifying the structure of the
  839. @i{instance}.
  840. The generic function @b{update-instance-for-redefined-class} takes
  841. four required arguments: the @i{instance} being updated after it has
  842. undergone the first step, a list of the names of @i{local slots} that were
  843. added, a list of the names of @i{local slots} that were discarded, and a
  844. property list containing the @i{slot} names and values of
  845. @i{slots} that were
  846. discarded and had values. Included among the discarded @i{slots} are
  847. @i{slots} that were local in the old @i{class} and that are shared in the new
  848. @i{class}.
  849. The generic function @b{update-instance-for-redefined-class} also
  850. takes any number of initialization arguments. When it is called by
  851. the system to update an @i{instance} whose @i{class}
  852. has been redefined, no
  853. initialization arguments are provided.
  854. There is a system-supplied primary @i{method} for
  855. @b{update-instance-for-redefined-class} whose @i{parameter specializer}
  856. for its @i{instance} argument is the @i{class} @b{standard-object}.
  857. First this @i{method} checks the validity of initialization arguments and signals an
  858. error if an initialization argument is supplied that is not declared
  859. as valid. (For more information, see @ref{Declaring the Validity of Initialization Arguments}.)
  860. Then it calls the generic function
  861. @b{shared-initialize} with the following arguments: the
  862. @i{instance},
  863. the list of @i{names} of
  864. the newly added @i{slots}, and the initialization
  865. arguments it received.
  866. @node Customizing Class Redefinition, , Initializing Newly Added Local Slots (Redefining Classes), Redefining Classes
  867. @subsubsection Customizing Class Redefinition
  868. [Reviewer Note by Barmar: This description is hard to follow.]
  869. @i{Methods} for @b{update-instance-for-redefined-class} may be
  870. defined to specify actions to be taken when an @i{instance} is updated.
  871. If only @i{after methods} for @b{update-instance-for-redefined-class} are
  872. defined, they will be run after the system-supplied primary @i{method} for
  873. initialization and therefore will not interfere with the default
  874. behavior of @b{update-instance-for-redefined-class}. Because no
  875. initialization arguments are passed to @b{update-instance-for-redefined-class}
  876. when it is called by the system, the
  877. @i{initialization forms} for @i{slots}
  878. that are filled by @i{before methods} for @b{update-instance-for-redefined-class}
  879. will not be evaluated by @b{shared-initialize}.
  880. @i{Methods} for @b{shared-initialize} may be defined to customize
  881. @i{class} redefinition. For more information, see @ref{Shared-Initialize}.
  882. @node Integrating Types and Classes, , Redefining Classes, Classes
  883. @subsection Integrating Types and Classes
  884. The object system maps the space of @i{classes} into the space of @i{types}.
  885. Every @i{class} that has a proper name has a corresponding @i{type}
  886. with the same @i{name}.
  887. The proper name of every @i{class} is a valid @i{type specifier}. In
  888. addition, every @i{class} @i{object} is a valid @i{type specifier}.
  889. Thus the expression @t{(typep @i{object} @i{class})} evaluates to
  890. @i{true} if the @i{class} of @i{object} is @i{class} itself or
  891. a @i{subclass} of @i{class}. The evaluation of the expression
  892. @t{(subtypep class1 class2)} returns the values
  893. @i{true} and @i{true} if @t{class1} is a subclass of @t{class2} or if they are the
  894. same @i{class}; otherwise it returns the values
  895. @i{false} and @i{true}.
  896. If I is an @i{instance} of some @i{class} C named S
  897. and C is an @i{instance} of @b{standard-class},
  898. the evaluation of the expression @t{(type-of I\/)} returns S
  899. if S is the @i{proper name} of C;
  900. otherwise, it returns C.
  901. Because the names of @i{classes}
  902. and @i{class} @i{objects} are @i{type specifiers}, they may
  903. be used in the special form @b{the} and in type declarations.
  904. Many but not all of the predefined @i{type specifiers} have a
  905. corresponding @i{class} with
  906. the same proper name as the @i{type}. These type
  907. specifiers are listed in @i{Figure~4--8}.
  908. For example, the @i{type} @b{array} has
  909. a corresponding @i{class} named @b{array}.
  910. No @i{type specifier} that is a
  911. list, such as @t{(vector double-float 100)}, has a corresponding @i{class}.
  912. The @i{operator} @b{deftype} does not create any @i{classes}.
  913. Each @i{class} that corresponds to a predefined @i{type specifier} can
  914. be implemented in one of three ways, at the discretion of each implementation.
  915. It can be a @i{standard class},
  916. a @i{structure class},
  917. or a @i{system class}.
  918. A @i{built-in class} is one whose @i{generalized instances} have restricted capabilities
  919. or special representations. Attempting to use @b{defclass} to define
  920. @i{subclasses} of a @b{built-in-class} signals an error.
  921. Calling @b{make-instance} to create a @i{generalized instance} of a
  922. @i{built-in class} signals an error. Calling @b{slot-value} on a
  923. @i{generalized instance} of a @i{built-in class} signals an error.
  924. Redefining a @i{built-in class} or using @b{change-class} to change
  925. the @i{class} of an @i{object} to or from a @i{built-in class} signals an error.
  926. However, @i{built-in classes} can be used as @i{parameter specializers}
  927. in @i{methods}.
  928. It is possible to determine whether a @i{class} is a @i{built-in class}
  929. by checking the @i{metaclass}.
  930. A @i{standard class} is an @i{instance} of the @i{class} @b{standard-class},
  931. a @i{built-in class} is an @i{instance} of the @i{class} @b{built-in-class}, and
  932. a @i{structure class} is an @i{instance} of the @i{class} @b{structure-class}.
  933. Each @i{structure} @i{type} created by @b{defstruct} without
  934. using the @t{:type} option has a corresponding @i{class}.
  935. This @i{class} is a @i{generalized instance} of the @i{class} @b{structure-class}.
  936. The @t{:include} option of @b{defstruct} creates a direct
  937. @i{subclass} of the @i{class}
  938. that corresponds to the included @i{structure}
  939. @i{type}.
  940. It is @i{implementation-dependent} whether @i{slots} are involved in the
  941. operation of @i{functions} defined in this specification
  942. on @i{instances} of @i{classes} defined in this specification,
  943. except when @i{slots} are explicitly defined by this specification.
  944. If in a particular @i{implementation} a @i{class} defined in this specification
  945. has @i{slots} that are not defined by this specfication, the names of these @i{slots}
  946. must not be @i{external symbols} of @i{packages} defined in this specification nor
  947. otherwise @i{accessible} in the @t{CL-USER} @i{package}.
  948. The purpose of specifying that many of the standard @i{type specifiers} have a
  949. corresponding @i{class} is to enable users to write @i{methods} that
  950. discriminate on these @i{types}. @i{Method} selection requires that a
  951. @i{class precedence list} can be determined for each @i{class}.
  952. The hierarchical relationships among the @i{type specifiers} are mirrored by
  953. relationships among the @i{classes} corresponding to those @i{types}.
  954. @i{Figure~4--8} lists the set of @i{classes}
  955. that correspond to predefined @i{type specifiers}.
  956. @group
  957. @noindent
  958. @w{ arithmetic-error generic-function simple-error }
  959. @w{ array hash-table simple-type-error }
  960. @w{ bit-vector integer simple-warning }
  961. @w{ broadcast-stream list standard-class }
  962. @w{ built-in-class logical-pathname standard-generic-function }
  963. @w{ cell-error method standard-method }
  964. @w{ character method-combination standard-object }
  965. @w{ class null storage-condition }
  966. @w{ complex number stream }
  967. @w{ concatenated-stream package stream-error }
  968. @w{ condition package-error string }
  969. @w{ cons parse-error string-stream }
  970. @w{ control-error pathname structure-class }
  971. @w{ division-by-zero print-not-readable structure-object }
  972. @w{ echo-stream program-error style-warning }
  973. @w{ end-of-file random-state symbol }
  974. @w{ error ratio synonym-stream }
  975. @w{ file-error rational t }
  976. @w{ file-stream reader-error two-way-stream }
  977. @w{ float readtable type-error }
  978. @w{ floating-point-inexact real unbound-slot }
  979. @w{ floating-point-invalid-operation restart unbound-variable }
  980. @w{ floating-point-overflow sequence undefined-function }
  981. @w{ floating-point-underflow serious-condition vector }
  982. @w{ function simple-condition warning }
  983. @noindent
  984. @w{ Figure 4--8: Classes that correspond to pre-defined type specifiers }
  985. @end group
  986. The @i{class precedence list} information specified in the entries for
  987. each of these @i{classes} are those that are required by the object system.
  988. Individual implementations may be extended to define other type
  989. specifiers to have a corresponding @i{class}. Individual implementations
  990. may be extended to add other @i{subclass} relationships and to add other
  991. @i{elements} to the @i{class precedence lists} as long as
  992. they do not violate the type relationships and disjointness
  993. requirements specified by this standard.
  994. A standard @i{class} defined with no direct @i{superclasses} is guaranteed to
  995. be disjoint from all of the @i{classes} in the table, except for the
  996. class named @b{t}.
  997. @c end of including concept-classes
  998. @node Types and Classes Dictionary, , Classes, Types and Classes
  999. @section Types and Classes Dictionary
  1000. @c including dict-types
  1001. @menu
  1002. * nil (Type)::
  1003. * boolean::
  1004. * function (System Class)::
  1005. * compiled-function::
  1006. * generic-function::
  1007. * standard-generic-function::
  1008. * class::
  1009. * built-in-class::
  1010. * structure-class::
  1011. * standard-class::
  1012. * method::
  1013. * standard-method::
  1014. * structure-object::
  1015. * standard-object::
  1016. * method-combination::
  1017. * t (System Class)::
  1018. * satisfies::
  1019. * member::
  1020. * not (Type Specifier)::
  1021. * and (Type Specifier)::
  1022. * or (Type Specifier)::
  1023. * values (Type Specifier)::
  1024. * eql (Type Specifier)::
  1025. * coerce::
  1026. * deftype::
  1027. * subtypep::
  1028. * type-of::
  1029. * typep::
  1030. * type-error::
  1031. * type-error-datum::
  1032. * simple-type-error::
  1033. @end menu
  1034. @node nil (Type), boolean, Types and Classes Dictionary, Types and Classes Dictionary
  1035. @subsection nil [Type]
  1036. @subsubheading Supertypes::
  1037. all @i{types}
  1038. @subsubheading Description::
  1039. The @i{type} @b{nil} contains no @i{objects} and so is also
  1040. called the @i{empty type}.
  1041. The @i{type} @b{nil} is a @i{subtype} of every @i{type}.
  1042. No @i{object} is of @i{type} @b{nil}.
  1043. @subsubheading Notes::
  1044. The @i{type} containing the @i{object} @b{nil} is the @i{type} @b{null},
  1045. not the @i{type} @b{nil}.
  1046. @node boolean, function (System Class), nil (Type), Types and Classes Dictionary
  1047. @subsection boolean [Type]
  1048. @subsubheading Supertypes::
  1049. @b{boolean},
  1050. @b{symbol},
  1051. @b{t}
  1052. @subsubheading Description::
  1053. The @i{type} @b{boolean} contains the @i{symbols} @b{t} and @b{nil},
  1054. which represent true and false, respectively.
  1055. @subsubheading See Also::
  1056. @b{t} (@i{constant variable}),
  1057. @b{nil} (@i{constant variable}),
  1058. @ref{if}
  1059. ,
  1060. @ref{not}
  1061. ,
  1062. @ref{complement}
  1063. @subsubheading Notes::
  1064. Conditional operations, such as @b{if},
  1065. permit the use of @i{generalized booleans},
  1066. not just @i{booleans};
  1067. any @i{non-nil} value,
  1068. not just @b{t},
  1069. counts as true for a @i{generalized boolean}.
  1070. However, as a matter of convention,
  1071. the @i{symbol} @b{t} is considered the canonical value to use
  1072. even for a @i{generalized boolean} when no better choice presents itself.
  1073. @node function (System Class), compiled-function, boolean, Types and Classes Dictionary
  1074. @subsection function [System Class]
  1075. @subsubheading Class Precedence List::
  1076. @b{function},
  1077. @b{t}
  1078. @subsubheading Description::
  1079. A @i{function} is an @i{object} that represents code
  1080. to be executed when an appropriate number of arguments is supplied.
  1081. A @i{function} is produced by
  1082. the @b{function} @i{special form},
  1083. the @i{function} @b{coerce},
  1084. or
  1085. the @i{function} @b{compile}.
  1086. A @i{function} can be directly invoked by using it as the first argument to
  1087. @b{funcall}, @b{apply}, or @b{multiple-value-call}.
  1088. @subsubheading Compound Type Specifier Kind::
  1089. Specializing.
  1090. @subsubheading Compound Type Specifier Syntax::
  1091. (@code{function}@{@i{@t{[}arg-typespec @r{[}value-typespec@r{]}@t{]}}@})
  1092. @w{@i{arg-typespec} ::=@r{(}@{@i{typespec}@}{*} }
  1093. @w{ @t{[}{&optional} @{@i{typespec}@}{*}@t{]} }
  1094. @w{ @t{[}{&rest} @i{typespec}@t{]} }
  1095. @w{ @t{[}{&key} @{{(}keyword typespec@r{)}@}{*}@t{]}@r{)}}
  1096. @subsubheading Compound Type Specifier Arguments::
  1097. @i{typespec}---a @i{type specifier}.
  1098. @i{value-typespec}---a @i{type specifier}.
  1099. @subsubheading Compound Type Specifier Description::
  1100. [Editorial Note by KMP: Isn't there some context info about ftype declarations to be merged here?]
  1101. [Editorial Note by KMP: This could still use some cleaning up.]
  1102. [Editorial Note by Sandra: Still need clarification about what happens if the
  1103. number of arguments doesn't match the FUNCTION type declaration.]
  1104. The list form of the @b{function} @i{type-specifier}
  1105. can be used only for declaration and not for discrimination.
  1106. Every element of this @i{type} is
  1107. a @i{function} that accepts arguments of the
  1108. types
  1109. specified by the @i{argj-types} and returns values that are
  1110. members of the @i{types} specified by @i{value-type}. The
  1111. @b{&optional}, @b{&rest}, @b{&key},
  1112. and @b{&allow-other-keys}
  1113. markers can appear in the list of argument types.
  1114. The @i{type specifier} provided
  1115. with @b{&rest} is the @i{type}
  1116. of each actual argument, not the @i{type} of the
  1117. corresponding variable.
  1118. The @b{&key} parameters
  1119. should be supplied as lists of the form @t{(@i{keyword} @i{type})}.
  1120. The @i{keyword} must be a valid keyword-name symbol
  1121. as must be supplied in the actual arguments of a
  1122. call.
  1123. This is usually a @i{symbol} in the @t{KEYWORD} @i{package} but can be any @i{symbol}.
  1124. When @b{&key} is given in a
  1125. @b{function} @i{type specifier} @i{lambda list},
  1126. the @i{keyword parameters} given
  1127. are exhaustive unless @b{&allow-other-keys} is also present.
  1128. @b{&allow-other-keys} is an indication
  1129. that other keyword arguments might actually be
  1130. supplied and, if supplied, can be used.
  1131. For example,
  1132. the @i{type} of the @i{function} @b{make-list} could be declared as follows:
  1133. @example
  1134. (function ((integer 0) &key (:initial-element t)) list)
  1135. @end example
  1136. The @i{value-type} can be a @b{values}
  1137. @i{type specifier} in order to indicate the
  1138. @i{types} of @i{multiple values}.
  1139. Consider a declaration of the following form:
  1140. @example
  1141. (ftype (function (arg0-type arg1-type ...) val-type) f))
  1142. @end example
  1143. Any @i{form}
  1144. @t{(f arg0 arg1 ...)}
  1145. within the scope of
  1146. that declaration is equivalent to the following:
  1147. @example
  1148. (the val-type (f (the arg0-type arg0) (the arg1-type arg1) ...))
  1149. @end example
  1150. That is, the consequences are undefined if any of the arguments are
  1151. not of the specified @i{types} or the result is not of the
  1152. specified @i{type}. In particular, if any argument is not of the
  1153. correct @i{type}, the result is not guaranteed to be of the
  1154. specified @i{type}.
  1155. Thus, an @b{ftype} declaration for a @i{function}
  1156. describes @i{calls} to the @i{function}, not the actual definition
  1157. of the @i{function}.
  1158. Consider a declaration of the following form:
  1159. @example
  1160. (type (function (arg0-type arg1-type ...) val-type) fn-valued-variable)
  1161. @end example
  1162. This declaration has the interpretation that, within the scope of the
  1163. declaration, the consequences are unspecified if the value of @t{fn-valued-variable} is called with arguments not of the specified
  1164. @i{types}; the value resulting from a valid call will be of type
  1165. @t{val-type}.
  1166. As with variable type declarations, nested declarations
  1167. imply intersections of @i{types}, as follows:
  1168. @table @asis
  1169. @item @t{*}
  1170. Consider the following two
  1171. declarations of @b{ftype}:
  1172. @example
  1173. (ftype (function (arg0-type1 arg1-type1 ...) val-type1) f))
  1174. @end example
  1175. and
  1176. @example
  1177. (ftype (function (arg0-type2 arg1-type2 ...) val-type2) f))
  1178. @end example
  1179. If both these declarations are in effect,
  1180. then within the shared scope of the declarations, calls to @t{f} can be
  1181. treated as if @t{f} were declared as follows:
  1182. @example
  1183. (ftype (function ((and arg0-type1 arg0-type2) (and arg1-type1 arg1-type2 ...) ...)
  1184. (and val-type1 val-type2))
  1185. f))
  1186. @end example
  1187. It is permitted to ignore one or all of the @b{ftype} declarations in force.
  1188. @item @t{*}
  1189. If two (or more) type declarations are in effect for a variable, and
  1190. they are both @t{function} declarations, the declarations combine similarly.
  1191. @end table
  1192. @node compiled-function, generic-function, function (System Class), Types and Classes Dictionary
  1193. @subsection compiled-function [Type]
  1194. @subsubheading Supertypes::
  1195. @b{compiled-function},
  1196. @b{function},
  1197. @b{t}
  1198. @subsubheading Description::
  1199. Any @i{function} may be considered by an @i{implementation} to be a
  1200. a @i{compiled function} if it contains no references to @i{macros} that
  1201. must be expanded at run time, and it contains no unresolved references
  1202. to @i{load time values}. See @ref{Compilation Semantics}.
  1203. @i{Functions} whose definitions appear lexically within a
  1204. @i{file} that has been @i{compiled} with @b{compile-file} and then
  1205. @i{loaded} with @b{load} are of @i{type} @b{compiled-function}.
  1206. @i{Functions} produced by the @b{compile} function
  1207. are of @i{type} @b{compiled-function}.
  1208. Other @i{functions} might also be of @i{type} @b{compiled-function}.
  1209. @node generic-function, standard-generic-function, compiled-function, Types and Classes Dictionary
  1210. @subsection generic-function [System Class]
  1211. @subsubheading Class Precedence List::
  1212. @b{generic-function},
  1213. @b{function},
  1214. @b{t}
  1215. @subsubheading Description::
  1216. A @i{generic function}
  1217. @IGindex{generic function}
  1218. is a @i{function} whose behavior
  1219. depends on the @i{classes} or identities of the @i{arguments}
  1220. supplied to it. A generic function object contains a set of
  1221. @i{methods}, a @i{lambda list}, a @i{method combination} @i{type},
  1222. and other information. The @i{methods}
  1223. define the class-specific behavior and operations of the @i{generic function};
  1224. a @i{method} is said to @i{specialize} a @i{generic function}.
  1225. When invoked, a @i{generic function} executes a subset of its
  1226. @i{methods} based on the @i{classes} or identities of its @i{arguments}.
  1227. A @i{generic function} can be used in the same ways that an
  1228. ordinary @i{function} can be used; specifically, a @i{generic function} can
  1229. be used as an argument to @b{funcall} and @b{apply},
  1230. and can be given a global or a local name.
  1231. @node standard-generic-function, class, generic-function, Types and Classes Dictionary
  1232. @subsection standard-generic-function [System Class]
  1233. @subsubheading Class Precedence List::
  1234. @b{standard-generic-function},
  1235. @b{generic-function},
  1236. @b{function},
  1237. @b{t}
  1238. @subsubheading Description::
  1239. The @i{class} @b{standard-generic-function} is the default @i{class} of
  1240. @i{generic functions} @i{established} by
  1241. @b{defmethod},
  1242. @b{ensure-generic-function},
  1243. @b{defgeneric},
  1244. and
  1245. @b{defclass} @i{forms}.
  1246. @node class, built-in-class, standard-generic-function, Types and Classes Dictionary
  1247. @subsection class [System Class]
  1248. @subsubheading Class Precedence List::
  1249. @b{class},
  1250. @b{standard-object},
  1251. @b{t}
  1252. @subsubheading Description::
  1253. The @i{type} @b{class} represents @i{objects} that determine the structure
  1254. and behavior of their @i{instances}. Associated with an @i{object}
  1255. of @i{type} @b{class} is information describing its place in the
  1256. directed acyclic graph of @i{classes}, its @i{slots}, and its options.
  1257. @node built-in-class, structure-class, class, Types and Classes Dictionary
  1258. @subsection built-in-class [System Class]
  1259. @subsubheading Class Precedence List::
  1260. @b{built-in-class},
  1261. @b{class},
  1262. @b{standard-object},
  1263. @b{t}
  1264. @subsubheading Description::
  1265. A @i{built-in class} is a @i{class} whose @i{instances} have
  1266. restricted capabilities or special representations.
  1267. Attempting to use
  1268. @b{defclass} to define @i{subclasses} of a @i{built-in class}
  1269. signals an error of @i{type} @b{error}.
  1270. Calling @b{make-instance} to create an @i{instance}
  1271. of a @i{built-in class} signals an error of @i{type} @b{error}.
  1272. Calling @b{slot-value} on an @i{instance} of a @i{built-in class}
  1273. signals an error of @i{type} @b{error}. Redefining a @i{built-in class}
  1274. or using @b{change-class} to change the @i{class} of an @i{instance}
  1275. to or from a @i{built-in class} signals an error of @i{type} @b{error}.
  1276. However, @i{built-in classes} can be used as @i{parameter specializers}
  1277. in @i{methods}.
  1278. @node structure-class, standard-class, built-in-class, Types and Classes Dictionary
  1279. @subsection structure-class [System Class]
  1280. @subsubheading Class Precedence List::
  1281. @b{structure-class},
  1282. @b{class},
  1283. @b{standard-object},
  1284. @b{t}
  1285. @subsubheading Description::
  1286. All @i{classes} defined by means of @b{defstruct}
  1287. are @i{instances} of the @i{class} @b{structure-class}.
  1288. @node standard-class, method, structure-class, Types and Classes Dictionary
  1289. @subsection standard-class [System Class]
  1290. @subsubheading Class Precedence List::
  1291. @b{standard-class},
  1292. @b{class},
  1293. @b{standard-object},
  1294. @b{t}
  1295. @subsubheading Description::
  1296. The @i{class} @b{standard-class} is the default @i{class} of @i{classes}
  1297. defined by @b{defclass}.
  1298. @node method, standard-method, standard-class, Types and Classes Dictionary
  1299. @subsection method [System Class]
  1300. @subsubheading Class Precedence List::
  1301. @b{method},
  1302. @b{t}
  1303. @subsubheading Description::
  1304. A @i{method} is an @i{object} that represents a modular part of the behavior
  1305. of a @i{generic function}.
  1306. A @i{method} contains @i{code} to implement the @i{method}'s
  1307. behavior, a sequence of @i{parameter specializers} that specify when the
  1308. given @i{method} is applicable, and a sequence of @i{qualifiers}
  1309. that is used by the method combination facility to distinguish among
  1310. @i{methods}. Each required parameter of each
  1311. @i{method} has an associated @i{parameter specializer}, and the
  1312. @i{method} will be invoked only on arguments that satisfy its
  1313. @i{parameter specializers}.
  1314. The method combination facility controls the selection of
  1315. @i{methods}, the order in which they are run, and the values that are
  1316. returned by the generic function. The object system offers a default method
  1317. combination type and provides a facility for declaring new types of
  1318. method combination.
  1319. @subsubheading See Also::
  1320. @ref{Generic Functions and Methods}
  1321. @node standard-method, structure-object, method, Types and Classes Dictionary
  1322. @subsection standard-method [System Class]
  1323. @subsubheading Class Precedence List::
  1324. @b{standard-method},
  1325. @b{method},
  1326. @b{standard-object},
  1327. @b{t}
  1328. @subsubheading Description::
  1329. The @i{class} @b{standard-method} is the default @i{class} of
  1330. @i{methods} defined by the
  1331. @b{defmethod} and
  1332. @b{defgeneric} @i{forms}.
  1333. @node structure-object, standard-object, standard-method, Types and Classes Dictionary
  1334. @subsection structure-object [Class]
  1335. @subsubheading Class Precedence List::
  1336. @b{structure-object},
  1337. @b{t}
  1338. @subsubheading Description::
  1339. The @i{class} @b{structure-object} is an @i{instance} of @b{structure-class}
  1340. and is a @i{superclass} of every @i{class}
  1341. that is an @i{instance} of @b{structure-class}
  1342. except itself, and is a @i{superclass} of every @i{class}
  1343. that is defined by @b{defstruct}.
  1344. @subsubheading See Also::
  1345. @ref{defstruct}
  1346. ,
  1347. @ref{Sharpsign S},
  1348. @ref{Printing Structures}
  1349. @node standard-object, method-combination, structure-object, Types and Classes Dictionary
  1350. @subsection standard-object [Class]
  1351. @subsubheading Class Precedence List::
  1352. @b{standard-object},
  1353. @b{t}
  1354. @subsubheading Description::
  1355. The @i{class} @b{standard-object} is an @i{instance} of @b{standard-class}
  1356. and is a @i{superclass} of every @i{class} that is an @i{instance} of
  1357. @b{standard-class} except itself.
  1358. @node method-combination, t (System Class), standard-object, Types and Classes Dictionary
  1359. @subsection method-combination [System Class]
  1360. @subsubheading Class Precedence List::
  1361. @b{method-combination},
  1362. @b{t}
  1363. @subsubheading Description::
  1364. Every @i{method combination} @i{object} is an
  1365. @i{indirect instance} of the @i{class} @b{method-combination}.
  1366. A @i{method combination} @i{object} represents the information about
  1367. the @i{method combination} being used by a @i{generic function}.
  1368. A @i{method combination} @i{object} contains information about
  1369. both the type of @i{method combination} and the arguments being used
  1370. with that @i{type}.
  1371. @node t (System Class), satisfies, method-combination, Types and Classes Dictionary
  1372. @subsection t [System Class]
  1373. @subsubheading Class Precedence List::
  1374. @b{t}
  1375. @subsubheading Description::
  1376. The set of all @i{objects}.
  1377. The @i{type} @b{t} is a @i{supertype} of every @i{type},
  1378. including itself. Every @i{object} is of @i{type} @b{t}.
  1379. @node satisfies, member, t (System Class), Types and Classes Dictionary
  1380. @subsection satisfies [Type Specifier]
  1381. @subsubheading Compound Type Specifier Kind::
  1382. Predicating.
  1383. @subsubheading Compound Type Specifier Syntax::
  1384. (@code{satisfies}@{@i{predicate-name}@})
  1385. @subsubheading Compound Type Specifier Arguments::
  1386. @i{predicate-name}---a @i{symbol}.
  1387. @subsubheading Compound Type Specifier Description::
  1388. This denotes the set of all @i{objects} that satisfy the
  1389. @i{predicate} @i{predicate-name}, which must be a @i{symbol}
  1390. whose global @i{function} definition is a one-argument
  1391. predicate. A name is required for @i{predicate-name};
  1392. @i{lambda expressions} are not allowed.
  1393. For example, the @i{type specifier} @t{(and integer (satisfies evenp))}
  1394. denotes the set of all even integers.
  1395. The form @t{(typep @i{x} '(satisfies @i{p}))} is equivalent to
  1396. @t{(if (@i{p} @i{x}) t nil)}.
  1397. The argument is required.
  1398. The @i{symbol} @b{*} can be the argument, but it
  1399. denotes itself (the @i{symbol} @b{*}),
  1400. and does not represent an unspecified value.
  1401. The symbol @b{satisfies} is not valid as a @i{type specifier}.
  1402. @node member, not (Type Specifier), satisfies, Types and Classes Dictionary
  1403. @subsection member [Type Specifier]
  1404. @subsubheading Compound Type Specifier Kind::
  1405. Combining.
  1406. @subsubheading Compound Type Specifier Syntax::
  1407. (@code{member}@{@i{@{@i{object}@}{*}}@})
  1408. @subsubheading Compound Type Specifier Arguments::
  1409. @i{object}---an @i{object}.
  1410. @subsubheading Compound Type Specifier Description::
  1411. This denotes the set containing the named @i{objects}. An
  1412. @i{object} is of this @i{type} if and only if it is @b{eql}
  1413. to one of the specified @i{objects}.
  1414. The @i{type specifiers} @t{(member)} and @b{nil} are equivalent.
  1415. @b{*} can be among the @i{objects},
  1416. but if so it denotes itself (the symbol @b{*})
  1417. and does not represent an unspecified value.
  1418. The symbol @b{member} is not valid as a @i{type specifier};
  1419. and, specifically, it is not an abbreviation for either @t{(member)} or @t{(member *)}.
  1420. @subsubheading See Also::
  1421. the @i{type} @b{eql}
  1422. @node not (Type Specifier), and (Type Specifier), member, Types and Classes Dictionary
  1423. @subsection not [Type Specifier]
  1424. @subsubheading Compound Type Specifier Kind::
  1425. Combining.
  1426. @subsubheading Compound Type Specifier Syntax::
  1427. (@code{not}@{@i{typespec}@})
  1428. @subsubheading Compound Type Specifier Arguments::
  1429. @i{typespec}---a @i{type specifier}.
  1430. @subsubheading Compound Type Specifier Description::
  1431. This denotes the set of all @i{objects} that are not of the @i{type} @i{typespec}.
  1432. The argument is required, and cannot be @b{*}.
  1433. The symbol @b{not} is not valid as a @i{type specifier}.
  1434. @node and (Type Specifier), or (Type Specifier), not (Type Specifier), Types and Classes Dictionary
  1435. @subsection and [Type Specifier]
  1436. @subsubheading Compound Type Specifier Kind::
  1437. Combining.
  1438. @subsubheading Compound Type Specifier Syntax::
  1439. (@code{and}@{@i{@{@i{typespec}@}{*}}@})
  1440. @subsubheading Compound Type Specifier Arguments::
  1441. @i{typespec}---a @i{type specifier}.
  1442. @subsubheading Compound Type Specifier Description::
  1443. This denotes the set of all @i{objects} of the @i{type}
  1444. determined by the intersection of the @i{typespecs}.
  1445. @b{*} is not permitted as an argument.
  1446. The @i{type specifiers} @t{(and)} and @b{t} are equivalent.
  1447. The symbol @b{and} is not valid as a @i{type specifier},
  1448. and, specifically, it is not an abbreviation for @t{(and)}.
  1449. @node or (Type Specifier), values (Type Specifier), and (Type Specifier), Types and Classes Dictionary
  1450. @subsection or [Type Specifier]
  1451. @subsubheading Compound Type Specifier Kind::
  1452. Combining.
  1453. @subsubheading Compound Type Specifier Syntax::
  1454. (@code{or}@{@i{@{@i{typespec}@}{*}}@})
  1455. @subsubheading Compound Type Specifier Arguments::
  1456. @i{typespec}---a @i{type specifier}.
  1457. @subsubheading Compound Type Specifier Description::
  1458. This denotes the set of all @i{objects} of the
  1459. @i{type} determined by the union of the @i{typespecs}.
  1460. For example, the @i{type} @b{list} by definition is the same as @t{(or null cons)}.
  1461. Also, the value returned by @b{position} is an @i{object} of @i{type} @t{(or null (integer 0 *))};
  1462. @i{i.e.}, either @b{nil} or a non-negative @i{integer}.
  1463. @b{*} is not permitted as an argument.
  1464. The @i{type specifiers} @t{(or)} and @b{nil} are equivalent.
  1465. The symbol @b{or} is not valid as a @i{type specifier};
  1466. and, specifically, it is not an abbreviation for @t{(or)}.
  1467. @node values (Type Specifier), eql (Type Specifier), or (Type Specifier), Types and Classes Dictionary
  1468. @subsection values [Type Specifier]
  1469. @subsubheading Compound Type Specifier Kind::
  1470. Specializing.
  1471. @subsubheading Compound Type Specifier Syntax::
  1472. (@code{values}@{@i{!@i{value-typespec}}@})
  1473. [Reviewer Note by Barmar: Missing @b{&key}]
  1474. @w{@i{value-typespec} ::=@{@i{typespec}@}{*} @t{[}{&optional} {@{@i{typespec}@}{*}}@t{]} @t{[}{&rest} typespec@t{]} @t{[}@b{&allow-other-keys}@t{]}}
  1475. @subsubheading Compound Type Specifier Arguments::
  1476. @i{typespec}---a @i{type specifier}.
  1477. @subsubheading Compound Type Specifier Description::
  1478. This @i{type specifier} can be used only as the @i{value-type} in a
  1479. @b{function} @i{type specifier} or a @b{the}
  1480. @i{special form}. It is used to specify individual @i{types}
  1481. when @i{multiple values} are involved.
  1482. The @b{&optional} and @b{&rest} markers can appear in the @i{value-type} list;
  1483. they indicate the parameter list of a @i{function} that,
  1484. when given to @b{multiple-value-call} along with the values,
  1485. would correctly receive those values.
  1486. The symbol @b{*} may not be among the @i{value-types}.
  1487. The symbol @b{values} is not valid as a @i{type specifier};
  1488. and, specifically, it is not an abbreviation for @t{(values)}.
  1489. @node eql (Type Specifier), coerce, values (Type Specifier), Types and Classes Dictionary
  1490. @subsection eql [Type Specifier]
  1491. @subsubheading Compound Type Specifier Kind::
  1492. Combining.
  1493. @subsubheading Compound Type Specifier Syntax::
  1494. (@code{eql}@{@i{object}@})
  1495. @subsubheading Compound Type Specifier Arguments::
  1496. @i{object}---an @i{object}.
  1497. @subsubheading Compound Type Specifier Description::
  1498. Represents the @i{type} whose only @i{element} is @i{object}.
  1499. The argument @i{object} is required. The @i{object} can be @b{*},
  1500. but if so it denotes itself (the symbol @b{*})
  1501. and does not represent an unspecified value.
  1502. The @i{symbol} @b{eql} is not valid as an @i{atomic type specifier}.
  1503. @node coerce, deftype, eql (Type Specifier), Types and Classes Dictionary
  1504. @subsection coerce [Function]
  1505. @code{coerce} @i{object result-type} @result{} @i{result}
  1506. @subsubheading Arguments and Values::
  1507. @i{object}---an @i{object}.
  1508. @i{result-type}---a @i{type specifier}.
  1509. @i{result}---an @i{object}, of @i{type} @i{result-type}
  1510. except in situations described in @ref{Rule of Canonical Representation for Complex Rationals}.
  1511. @subsubheading Description::
  1512. @i{Coerces} the @i{object} to @i{type} @i{result-type}.
  1513. If @i{object} is already of @i{type} @i{result-type},
  1514. the @i{object} itself is returned, regardless of whether it
  1515. would have been possible in general to coerce an @i{object} of
  1516. some other @i{type} to @i{result-type}.
  1517. Otherwise, the @i{object} is @i{coerced} to @i{type} @i{result-type}
  1518. according to the following rules:
  1519. @table @asis
  1520. @item @b{sequence}
  1521. If the @i{result-type} is a @i{recognizable subtype} of @b{list},
  1522. and the @i{object} is a @i{sequence},
  1523. then the @i{result} is a @i{list}
  1524. that has the @i{same} @i{elements} as @i{object}.
  1525. If the @i{result-type} is a @i{recognizable subtype} of @b{vector},
  1526. and the @i{object} is a @i{sequence},
  1527. then the @i{result} is a @i{vector}
  1528. that has the @i{same} @i{elements} as @i{object}.
  1529. If @i{result-type} is a specialized @i{type},
  1530. the @i{result} has an @i{actual array element type} that is the result of
  1531. @i{upgrading} the element type part of that @i{specialized} @i{type}.
  1532. If no element type is specified, the element type defaults to @b{t}.
  1533. If the @i{implementation} cannot determine the element type, an error is signaled.
  1534. @item @b{character}
  1535. If the @i{result-type} is @b{character}
  1536. and the @i{object} is a @i{character designator},
  1537. the @i{result} is the @i{character} it denotes.
  1538. @item @b{complex}
  1539. If the @i{result-type} is @b{complex}
  1540. and the @i{object} is a @i{number},
  1541. then the @i{result} is obtained by constructing a @i{complex}
  1542. whose real part is the @i{object} and
  1543. whose imaginary part is the result of @i{coercing} an @i{integer} zero
  1544. to the @i{type} of the @i{object} (using @b{coerce}).
  1545. (If the real part is a @i{rational}, however,
  1546. then the result must be represented as a @i{rational} rather
  1547. than a @i{complex}; see @ref{Rule of Canonical Representation for Complex Rationals}.
  1548. So, for example, @t{(coerce 3 'complex)} is permissible,
  1549. but will return @t{3}, which is not a @i{complex}.)
  1550. @item @b{float}
  1551. If the @i{result-type} is any of @b{float},
  1552. @b{short-float},
  1553. @b{single-float},
  1554. @b{double-float},
  1555. @b{long-float},
  1556. and the @i{object} is a
  1557. @i{real},
  1558. then the @i{result} is a @i{float} of @i{type} @i{result-type}
  1559. which is equal in sign and magnitude to the @i{object} to whatever degree of
  1560. representational precision is permitted by that @i{float} representation.
  1561. (If the @i{result-type} is @b{float}
  1562. and @i{object} is not already a @i{float},
  1563. then the @i{result} is a @i{single float}.)
  1564. @item @b{function}
  1565. If the @i{result-type} is @b{function},
  1566. and @i{object} is any
  1567. @i{function name}
  1568. that is @i{fbound}
  1569. but that is globally defined neither as a @i{macro name} nor as a @i{special operator},
  1570. then the @i{result} is the @i{functional value} of @i{object}.
  1571. If the @i{result-type} is @b{function},
  1572. and @i{object} is a @i{lambda expression},
  1573. then the @i{result} is a @i{closure} of @i{object}
  1574. in the @i{null lexical environment}.
  1575. @item @b{t}
  1576. Any @i{object} can be @i{coerced} to an @i{object} of @i{type} @b{t}.
  1577. In this case, the @i{object} is simply returned.
  1578. @end table
  1579. @subsubheading Examples::
  1580. @example
  1581. (coerce '(a b c) 'vector) @result{} #(A B C)
  1582. (coerce 'a 'character) @result{} #\A
  1583. (coerce 4.56 'complex) @result{} #C(4.56 0.0)
  1584. (coerce 4.5s0 'complex) @result{} #C(4.5s0 0.0s0)
  1585. (coerce 7/2 'complex) @result{} 7/2
  1586. (coerce 0 'short-float) @result{} 0.0s0
  1587. (coerce 3.5L0 'float) @result{} 3.5L0
  1588. (coerce 7/2 'float) @result{} 3.5
  1589. (coerce (cons 1 2) t) @result{} (1 . 2)
  1590. @end example
  1591. All the following @i{forms} should signal an error:
  1592. @example
  1593. (coerce '(a b c) '(vector * 4))
  1594. (coerce #(a b c) '(vector * 4))
  1595. (coerce '(a b c) '(vector * 2))
  1596. (coerce #(a b c) '(vector * 2))
  1597. (coerce "foo" '(string 2))
  1598. (coerce #(#\a #\b #\c) '(string 2))
  1599. (coerce '(0 1) '(simple-bit-vector 3))
  1600. @end example
  1601. @subsubheading Exceptional Situations::
  1602. If a coercion is not possible, an error of @i{type} @b{type-error} is signaled.
  1603. @t{(coerce x 'nil)} always signals an error of @i{type} @b{type-error}.
  1604. An error
  1605. of @i{type} @b{error} is signaled
  1606. if the @i{result-type} is @b{function} but
  1607. @i{object} is a @i{symbol} that is not @i{fbound} or
  1608. if the @i{symbol} names a @i{macro} or a @i{special operator}.
  1609. An error of @i{type} @b{type-error} should be signaled if @i{result-type}
  1610. specifies the number of elements and @i{object} is of a different length.
  1611. @subsubheading See Also::
  1612. @ref{rational}
  1613. ,
  1614. @ref{floor; ffloor; ceiling; fceiling; truncate; ftruncate; round; fround}
  1615. ,
  1616. @ref{char-code}
  1617. ,
  1618. @ref{char-int}
  1619. @subsubheading Notes::
  1620. Coercions from @i{floats} to @i{rationals}
  1621. and from @i{ratios} to @i{integers}
  1622. are not provided because of rounding problems.
  1623. @example
  1624. (coerce x 't) @equiv{} (identity x) @equiv{} x
  1625. @end example
  1626. @node deftype, subtypep, coerce, Types and Classes Dictionary
  1627. @subsection deftype [Macro]
  1628. @code{deftype} @i{name lambda-list {[[@{@i{declaration}@}{*} | @i{documentation}]]} @{@i{form}@}{*}} @result{} @i{name}
  1629. @subsubheading Arguments and Values::
  1630. @i{name}---a @i{symbol}.
  1631. @i{lambda-list}---a @i{deftype lambda list}.
  1632. @i{declaration}---a @b{declare} @i{expression}; not evaluated.
  1633. @i{documentation}---a @i{string}; not evaluated.
  1634. @i{form}---a @i{form}.
  1635. @subsubheading Description::
  1636. @b{deftype} defines a @i{derived type specifier} named @i{name}.
  1637. The meaning of the new @i{type specifier} is given in terms of
  1638. a function which expands the @i{type specifier} into another
  1639. @i{type specifier}, which itself will be expanded if it contains
  1640. references to another @i{derived type specifier}.
  1641. The newly defined @i{type specifier} may be referenced as a list of
  1642. the form @t{(@i{name} @i{arg_1} @i{arg_2} ...)\/}.
  1643. The number of arguments must be appropriate to the @i{lambda-list}.
  1644. If the new @i{type specifier} takes no arguments,
  1645. or if all of its arguments are optional,
  1646. the @i{type specifier} may be used as an @i{atomic type specifier}.
  1647. The @i{argument} @i{expressions} to the @i{type specifier},
  1648. @i{arg_1} ... @i{arg_n}, are not @i{evaluated}.
  1649. Instead, these @i{literal objects} become the @i{objects} to which
  1650. corresponding @i{parameters} become @i{bound}.
  1651. The body of the @b{deftype} @i{form}
  1652. (but not the @i{lambda-list})
  1653. is
  1654. implicitly enclosed in a @i{block} named @i{name},
  1655. and is evaluated as an @i{implicit progn},
  1656. returning a new @i{type specifier}.
  1657. The @i{lexical environment} of the body is the one which was current
  1658. at the time the @b{deftype} form was evaluated, augmented by the
  1659. @i{variables} in the @i{lambda-list}.
  1660. Recursive expansion of the @i{type specifier} returned as the expansion
  1661. must terminate, including the expansion of @i{type specifiers} which
  1662. are nested within the expansion.
  1663. The consequences are undefined if the result of fully expanding a
  1664. @i{type specifier} contains any circular structure, except within
  1665. the @i{objects} referred to by @b{member} and @b{eql}
  1666. @i{type specifiers}.
  1667. @i{Documentation} is attached to @i{name} as a @i{documentation string}
  1668. of kind @b{type}.
  1669. If a @b{deftype} @i{form} appears as a @i{top level form},
  1670. the @i{compiler} must ensure that the @i{name} is recognized
  1671. in subsequent @i{type} declarations.
  1672. The @i{programmer} must ensure that the body of a @b{deftype} form
  1673. can be @i{evaluated} at compile time if the @i{name} is
  1674. referenced in subsequent @i{type} declarations.
  1675. If the expansion of a @i{type specifier} is not defined fully at compile time
  1676. (perhaps because it expands into an unknown @i{type specifier} or a
  1677. @b{satisfies} of a named @i{function} that isn't defined in the
  1678. compile-time environment), an @i{implementation} may ignore any references to
  1679. this @i{type} in declarations and/or signal a warning.
  1680. @subsubheading Examples::
  1681. @example
  1682. (defun equidimensional (a)
  1683. (or (< (array-rank a) 2)
  1684. (apply #'= (array-dimensions a)))) @result{} EQUIDIMENSIONAL
  1685. (deftype square-matrix (&optional type size)
  1686. `(and (array ,type (,size ,size))
  1687. (satisfies equidimensional))) @result{} SQUARE-MATRIX
  1688. @end example
  1689. @subsubheading See Also::
  1690. @b{declare},
  1691. @ref{defmacro}
  1692. ,
  1693. @ref{documentation; (setf documentation)}
  1694. ,
  1695. @ref{Type Specifiers},
  1696. @ref{Syntactic Interaction of Documentation Strings and Declarations}
  1697. @node subtypep, type-of, deftype, Types and Classes Dictionary
  1698. @subsection subtypep [Function]
  1699. @code{subtypep} @i{type-1 type-2 {&optional} environment} @result{} @i{subtype-p, valid-p}
  1700. @subsubheading Arguments and Values::
  1701. @i{type-1}---a @i{type specifier}.
  1702. @i{type-2}---a @i{type specifier}.
  1703. @i{environment}---an @i{environment} @i{object}.
  1704. The default is @b{nil}, denoting the @i{null lexical environment}
  1705. and the current @i{global environment}.
  1706. @i{subtype-p}---a @i{generalized boolean}.
  1707. @i{valid-p}---a @i{generalized boolean}.
  1708. @subsubheading Description::
  1709. If @i{type-1} is a @i{recognizable subtype} of @i{type-2},
  1710. the first @i{value} is @i{true}.
  1711. Otherwise, the first @i{value} is @i{false},
  1712. indicating that either
  1713. @i{type-1} is not a @i{subtype} of @i{type-2}, or else
  1714. @i{type-1} is a @i{subtype} of @i{type-2}
  1715. but is not a @i{recognizable subtype}.
  1716. A second @i{value} is also returned indicating the `certainty' of
  1717. the first @i{value}. If this value is @i{true}, then the first
  1718. value is an accurate indication of the @i{subtype} relationship.
  1719. (The second @i{value} is always @i{true} when the first @i{value}
  1720. is @i{true}.)
  1721. Figure 4--9 summarizes the possible combinations of @i{values}
  1722. that might result.
  1723. @group
  1724. @noindent
  1725. @w{ Value 1 Value 2 Meaning }
  1726. @w{ @i{true} @i{true} @i{type-1} is definitely a @i{subtype} of @i{type-2}. }
  1727. @w{ @i{false} @i{true} @i{type-1} is definitely not a @i{subtype} of @i{type-2}. }
  1728. @w{ @i{false} @i{false} @b{subtypep} could not determine the relationship, }
  1729. @w{ so @i{type-1} might or might not be a @i{subtype} of @i{type-2}. }
  1730. @noindent
  1731. @w{ Figure 4--9: Result possibilities for subtypep }
  1732. @end group
  1733. @b{subtypep} is permitted to return the
  1734. @i{values} @i{false} and @i{false} only when at least
  1735. one argument involves one of these @i{type specifiers}:
  1736. @b{and},
  1737. @b{eql},
  1738. the list form of @b{function},
  1739. @b{member},
  1740. @b{not},
  1741. @b{or},
  1742. @b{satisfies},
  1743. or
  1744. @b{values}.
  1745. (A @i{type specifier} `involves' such a @i{symbol} if,
  1746. after being @i{type expanded},
  1747. it contains that @i{symbol} in a position that would call for
  1748. its meaning as a @i{type specifier} to be used.)
  1749. One consequence of this is that if neither @i{type-1} nor @i{type-2}
  1750. involves any of these @i{type specifiers}, then @b{subtypep} is obliged
  1751. to determine the relationship accurately. In particular, @b{subtypep}
  1752. returns the @i{values} @i{true} and @i{true}
  1753. if the arguments are @b{equal} and do not involve
  1754. any of these @i{type specifiers}.
  1755. @b{subtypep} never returns a second value of @b{nil} when both
  1756. @i{type-1} and @i{type-2} involve only
  1757. the names in @i{Figure~4--2}, or
  1758. names of @i{types} defined by @b{defstruct},
  1759. @b{define-condition},
  1760. or @b{defclass}, or
  1761. @i{derived types} that expand into only those names.
  1762. While @i{type specifiers} listed in @i{Figure~4--2} and
  1763. names of @b{defclass} and @b{defstruct} can in some cases be
  1764. implemented as @i{derived types}, @b{subtypep} regards them as primitive.
  1765. The relationships between @i{types} reflected by @b{subtypep}
  1766. are those specific to the particular implementation. For example, if
  1767. an implementation supports only a single type of floating-point numbers,
  1768. in that implementation @t{(subtypep 'float 'long-float)}
  1769. returns the @i{values} @i{true} and @i{true}
  1770. (since the two @i{types} are identical).
  1771. For all @i{T1} and @i{T2} other than @t{*},
  1772. @t{(array @i{T1})} and @t{(array @i{T2})}
  1773. are two different @i{type specifiers} that always refer to the same sets of
  1774. things if and only if they refer to @i{arrays}
  1775. of exactly the same specialized representation, @i{i.e.}, if @t{(upgraded-array-element-type '@i{T1})} and
  1776. @t{(upgraded-array-element-type '@i{T2})}
  1777. return two different @i{type specifiers} that always refer to the same sets of
  1778. @i{objects}.
  1779. This is another way of saying that
  1780. @t{`(array @i{type-specifier})}
  1781. and
  1782. @t{`(array ,(upgraded-array-element-type '@i{type-specifier}))}
  1783. refer to the same
  1784. set of specialized @i{array} representations.
  1785. For all @i{T1} and @i{T2} other than @t{*},
  1786. the intersection of
  1787. @t{(array @i{T1})}
  1788. and @t{(array @i{T2})} is the empty set
  1789. if and only if they refer to @i{arrays} of different,
  1790. distinct specialized representations.
  1791. Therefore,
  1792. @example
  1793. (subtypep '(array T1) '(array T2)) @result{} @i{true}
  1794. @end example
  1795. if and only if
  1796. @example
  1797. (upgraded-array-element-type 'T1) and
  1798. (upgraded-array-element-type 'T2)
  1799. @end example
  1800. return two different @i{type specifiers} that always refer to the same sets of
  1801. @i{objects}.
  1802. For all type-specifiers @i{T1} and @i{T2} other than @t{*},
  1803. @example
  1804. (subtypep '(complex T1) '(complex T2)) @result{} @i{true}, @i{true}
  1805. @end example
  1806. if:
  1807. @table @asis
  1808. @item 1.
  1809. @t{T1} is a @i{subtype} of @t{T2}, or
  1810. @item 2.
  1811. @t{(upgraded-complex-part-type '@i{T1})} and
  1812. @t{(upgraded-complex-part-type '@i{T2})}
  1813. return two different @i{type specifiers} that always refer to the
  1814. same sets of @i{objects}; in this case,
  1815. @t{(complex @i{T1})} and
  1816. @t{(complex @i{T2})} both refer to the
  1817. same specialized representation.
  1818. @end table
  1819. The @i{values} are @i{false} and @i{true} otherwise.
  1820. The form
  1821. @example
  1822. (subtypep '(complex single-float) '(complex float))
  1823. @end example
  1824. must return @i{true} in all implementations, but
  1825. @example
  1826. (subtypep '(array single-float) '(array float))
  1827. @end example
  1828. returns @i{true} only in implementations that do not have a specialized @i{array}
  1829. representation for @i{single floats} distinct from that for other @i{floats}.
  1830. @subsubheading Examples::
  1831. @example
  1832. (subtypep 'compiled-function 'function) @result{} @i{true}, @i{true}
  1833. (subtypep 'null 'list) @result{} @i{true}, @i{true}
  1834. (subtypep 'null 'symbol) @result{} @i{true}, @i{true}
  1835. (subtypep 'integer 'string) @result{} @i{false}, @i{true}
  1836. (subtypep '(satisfies dummy) nil) @result{} @i{false}, @i{implementation-dependent}
  1837. (subtypep '(integer 1 3) '(integer 1 4)) @result{} @i{true}, @i{true}
  1838. (subtypep '(integer (0) (0)) 'nil) @result{} @i{true}, @i{true}
  1839. (subtypep 'nil '(integer (0) (0))) @result{} @i{true}, @i{true}
  1840. (subtypep '(integer (0) (0)) '(member)) @result{} @i{true}, @i{true} ;or @i{false}, @i{false}
  1841. (subtypep '(member) 'nil) @result{} @i{true}, @i{true} ;or @i{false}, @i{false}
  1842. (subtypep 'nil '(member)) @result{} @i{true}, @i{true} ;or @i{false}, @i{false}
  1843. @end example
  1844. Let @t{<aet-x>} and @t{<aet-y>} be two distinct @i{type specifiers} that
  1845. do not always refer to the same sets of
  1846. @i{objects}
  1847. in a given implementation, but for which
  1848. @b{make-array}, will return an
  1849. @i{object} of the same @i{array} @i{type}.
  1850. Thus, in each case,
  1851. @example
  1852. (subtypep (array-element-type (make-array 0 :element-type '<aet-x>))
  1853. (array-element-type (make-array 0 :element-type '<aet-y>)))
  1854. @result{} @i{true}, @i{true}
  1855. (subtypep (array-element-type (make-array 0 :element-type '<aet-y>))
  1856. (array-element-type (make-array 0 :element-type '<aet-x>)))
  1857. @result{} @i{true}, @i{true}
  1858. @end example
  1859. If @t{(array <aet-x>)}
  1860. and @t{(array <aet-y>)} are different names for
  1861. exactly the same set of @i{objects},
  1862. these names should always refer to the same sets of
  1863. @i{objects}.
  1864. That implies that the following set of tests are also true:
  1865. @example
  1866. (subtypep '(array <aet-x>) '(array <aet-y>)) @result{} @i{true}, @i{true}
  1867. (subtypep '(array <aet-y>) '(array <aet-x>)) @result{} @i{true}, @i{true}
  1868. @end example
  1869. @subsubheading See Also::
  1870. @ref{Types}
  1871. @subsubheading Notes::
  1872. The small differences between the @b{subtypep} specification for
  1873. the @b{array} and @b{complex} types are necessary because there
  1874. is no creation function for @i{complexes} which allows
  1875. the specification of the resultant part type independently of
  1876. the actual types of the parts. Thus in the case of the @i{type} @b{complex},
  1877. the actual type of the parts is referred to, although a @i{number}
  1878. can be a member of more than one @i{type}.
  1879. For example, @t{17} is of @i{type} @t{(mod 18)}
  1880. as well as @i{type} @t{(mod 256)} and @i{type} @b{integer};
  1881. and @t{2.3f5} is of @i{type} @b{single-float}
  1882. as well as @i{type} @b{float}.
  1883. @node type-of, typep, subtypep, Types and Classes Dictionary
  1884. @subsection type-of [Function]
  1885. @code{type-of} @i{object} @result{} @i{typespec}
  1886. @subsubheading Arguments and Values::
  1887. @i{object}---an @i{object}.
  1888. @i{typespec}---a @i{type specifier}.
  1889. @subsubheading Description::
  1890. Returns a @i{type specifier}, @i{typespec}, for a @i{type}
  1891. that has the @i{object} as an @i{element}.
  1892. The @i{typespec} satisfies the following:
  1893. @table @asis
  1894. @item 1.
  1895. For any @i{object} that is an @i{element} of some @i{built-in type}:
  1896. @table @asis
  1897. @item a.
  1898. the @i{type} returned is a @i{recognizable subtype} of that @i{built-in type}.
  1899. @item b.
  1900. the @i{type} returned does not involve
  1901. @t{and},
  1902. @t{eql},
  1903. @t{member},
  1904. @t{not},
  1905. @t{or},
  1906. @t{satisfies},
  1907. or @t{values}.
  1908. @end table
  1909. @item 2.
  1910. For all @i{objects}, @t{(typep @i{object} (type-of @i{object}))}
  1911. returns @i{true}.
  1912. Implicit in this is that @i{type specifiers} which are
  1913. not valid for use with @b{typep}, such as the @i{list} form of the
  1914. @b{function} @i{type specifier}, are never returned by @b{type-of}.
  1915. @item 3.
  1916. The @i{type} returned by @b{type-of} is always a @i{recognizable subtype}
  1917. of the @i{class} returned by @b{class-of}. That is,
  1918. @example
  1919. (subtypep (type-of @i{object}) (class-of @i{object})) @result{} @i{true}, @i{true}
  1920. @end example
  1921. @item 4.
  1922. For @i{objects} of metaclass @b{structure-class} or @b{standard-class},
  1923. and for @i{conditions},
  1924. @b{type-of} returns the @i{proper name} of the @i{class} returned
  1925. by @b{class-of} if it has a @i{proper name},
  1926. and otherwise returns the @i{class} itself.
  1927. In particular, for @i{objects} created by the constructor function
  1928. of a structure defined with @b{defstruct} without a @t{:type} option,
  1929. @b{type-of} returns the structure name; and for @i{objects} created
  1930. by @b{make-condition}, the @i{typespec} is the @i{name} of the
  1931. @i{condition} @i{type}.
  1932. @item 5.
  1933. For each of the @i{types}
  1934. @b{short-float},
  1935. @b{single-float},
  1936. @b{double-float},
  1937. or @b{long-float}
  1938. of which the @i{object} is an @i{element},
  1939. the @i{typespec} is a @i{recognizable subtype} of that @i{type}.
  1940. @end table
  1941. @subsubheading Examples::
  1942. @example
  1943. @end example
  1944. @example
  1945. (type-of 'a) @result{} SYMBOL
  1946. (type-of '(1 . 2))
  1947. @result{} CONS
  1948. @i{OR}@result{} (CONS FIXNUM FIXNUM)
  1949. (type-of #c(0 1))
  1950. @result{} COMPLEX
  1951. @i{OR}@result{} (COMPLEX INTEGER)
  1952. (defstruct temp-struct x y z) @result{} TEMP-STRUCT
  1953. (type-of (make-temp-struct)) @result{} TEMP-STRUCT
  1954. (type-of "abc")
  1955. @result{} STRING
  1956. @i{OR}@result{} (STRING 3)
  1957. (subtypep (type-of "abc") 'string) @result{} @i{true}, @i{true}
  1958. (type-of (expt 2 40))
  1959. @result{} BIGNUM
  1960. @i{OR}@result{} INTEGER
  1961. @i{OR}@result{} (INTEGER 1099511627776 1099511627776)
  1962. @i{OR}@result{} SYSTEM::TWO-WORD-BIGNUM
  1963. @i{OR}@result{} FIXNUM
  1964. (subtypep (type-of 112312) 'integer) @result{} @i{true}, @i{true}
  1965. (defvar *foo* (make-array 5 :element-type t)) @result{} *FOO*
  1966. (class-name (class-of *foo*)) @result{} VECTOR
  1967. (type-of *foo*)
  1968. @result{} VECTOR
  1969. @i{OR}@result{} (VECTOR T 5)
  1970. @end example
  1971. @subsubheading See Also::
  1972. @ref{array-element-type}
  1973. ,
  1974. @ref{class-of}
  1975. ,
  1976. @ref{defstruct}
  1977. ,
  1978. @ref{typecase; ctypecase; etypecase}
  1979. ,
  1980. @ref{typep}
  1981. ,
  1982. @ref{Types}
  1983. @subsubheading Notes::
  1984. Implementors are encouraged to arrange for @b{type-of} to return
  1985. a portable value.
  1986. @node typep, type-error, type-of, Types and Classes Dictionary
  1987. @subsection typep [Function]
  1988. @code{typep} @i{object type-specifier {&optional} environment} @result{} @i{generalized-boolean}
  1989. @subsubheading Arguments and Values::
  1990. @i{object}---an @i{object}.
  1991. @i{type-specifier}---any @i{type specifier} except
  1992. @b{values}, or a @i{type specifier} list
  1993. whose first element is either @b{function} or @b{values}.
  1994. @i{environment}---an @i{environment} @i{object}.
  1995. The default is @b{nil}, denoting the @i{null lexical environment}
  1996. and the and current @i{global environment}.
  1997. @i{generalized-boolean}---a @i{generalized boolean}.
  1998. @subsubheading Description::
  1999. Returns @i{true} if @i{object} is of the @i{type} specified by @i{type-specifier};
  2000. otherwise, returns @i{false}.
  2001. A @i{type-specifier} of the form @t{(satisfies fn)}
  2002. is handled by applying the function @t{fn} to @i{object}.
  2003. @t{(typep @i{object} '(array @i{type-specifier}))},
  2004. where @i{type-specifier} is not @t{*},
  2005. returns @i{true} if and only if @i{object} is an @i{array}
  2006. that could be the result
  2007. of supplying @i{type-specifier}
  2008. as the @t{:element-type} argument to @b{make-array}.
  2009. @t{(array *)} refers to all @i{arrays}
  2010. regardless of element type, while @t{(array @i{type-specifier})}
  2011. refers only to those @i{arrays}
  2012. that can result from giving @i{type-specifier} as the
  2013. @t{:element-type} argument to @b{make-array}.
  2014. A similar interpretation applies to @t{(simple-array @i{type-specifier})}
  2015. and @t{(vector @i{type-specifier})}.
  2016. See @ref{Array Upgrading}.
  2017. @t{(typep @i{object} '(complex @i{type-specifier}))}
  2018. returns @i{true} for all @i{complex} numbers that can result from
  2019. giving @i{numbers} of type @i{type-specifier}
  2020. to the @i{function} @b{complex}, plus all other @i{complex} numbers
  2021. of the same specialized representation.
  2022. Both the real and the imaginary parts of any such
  2023. @i{complex} number must satisfy:
  2024. @example
  2025. (typep realpart 'type-specifier)
  2026. (typep imagpart 'type-specifier)
  2027. @end example
  2028. See the @i{function} @b{upgraded-complex-part-type}.
  2029. @subsubheading Examples::
  2030. @example
  2031. (typep 12 'integer) @result{} @i{true}
  2032. (typep (1+ most-positive-fixnum) 'fixnum) @result{} @i{false}
  2033. (typep nil t) @result{} @i{true}
  2034. (typep nil nil) @result{} @i{false}
  2035. (typep 1 '(mod 2)) @result{} @i{true}
  2036. (typep #c(1 1) '(complex (eql 1))) @result{} @i{true}
  2037. ;; To understand this next example, you might need to refer to
  2038. ;; @ref{Rule of Canonical Representation for Complex Rationals}.
  2039. (typep #c(0 0) '(complex (eql 0))) @result{} @i{false}
  2040. @end example
  2041. Let @t{A{{}_x}} and @t{A{{}_y}} be two @i{type specifiers} that
  2042. denote different @i{types}, but for which
  2043. @example
  2044. (upgraded-array-element-type 'A{{}_x})
  2045. @end example
  2046. and
  2047. @example
  2048. (upgraded-array-element-type 'A{{}_y})
  2049. @end example
  2050. denote the same @i{type}. Notice that
  2051. @example
  2052. (typep (make-array 0 :element-type 'A{{}_x}) '(array A{{}_x})) @result{} @i{true}
  2053. (typep (make-array 0 :element-type 'A{{}_y}) '(array A{{}_y})) @result{} @i{true}
  2054. (typep (make-array 0 :element-type 'A{{}_x}) '(array A{{}_y})) @result{} @i{true}
  2055. (typep (make-array 0 :element-type 'A{{}_y}) '(array A{{}_x})) @result{} @i{true}
  2056. @end example
  2057. @subsubheading Exceptional Situations::
  2058. An error of @i{type} @b{error} is signaled if @i{type-specifier} is @t{values},
  2059. or a @i{type specifier} list whose first element is either
  2060. @b{function} or @b{values}.
  2061. The consequences are undefined if
  2062. the @i{type-specifier} is not a @i{type specifier}.
  2063. @subsubheading See Also::
  2064. @ref{type-of}
  2065. ,
  2066. @ref{upgraded-array-element-type}
  2067. ,
  2068. @ref{upgraded-complex-part-type}
  2069. ,
  2070. @ref{Type Specifiers}
  2071. @subsubheading Notes::
  2072. @i{Implementations} are encouraged to recognize and optimize the case of
  2073. @t{(typep @i{x} (the class @i{y}))},
  2074. since it does not involve any need for expansion
  2075. of @b{deftype} information at runtime.
  2076. @example
  2077. @end example
  2078. @node type-error, type-error-datum, typep, Types and Classes Dictionary
  2079. @subsection type-error [Condition Type]
  2080. @subsubheading Class Precedence List::
  2081. @b{type-error},
  2082. @b{error},
  2083. @b{serious-condition},
  2084. @b{condition},
  2085. @b{t}
  2086. @subsubheading Description::
  2087. The @i{type} @b{type-error} represents a situation in which an @i{object} is not
  2088. of the expected type. The ``offending datum'' and ``expected type'' are initialized
  2089. by the initialization arguments named @t{:datum} and @t{:expected-type} to @b{make-condition},
  2090. and are @i{accessed} by the functions
  2091. @b{type-error-datum} and @b{type-error-expected-type}.
  2092. @subsubheading See Also::
  2093. @ref{type-error-datum; type-error-expected-type}
  2094. , @b{type-error-expected-type}
  2095. @node type-error-datum, simple-type-error, type-error, Types and Classes Dictionary
  2096. @subsection type-error-datum, type-error-expected-type [Function]
  2097. @code{type-error-datum} @i{condition} @result{} @i{datum}
  2098. @code{type-error-expected-type} @i{condition} @result{} @i{expected-type}
  2099. @subsubheading Arguments and Values::
  2100. @i{condition}---a @i{condition} of @i{type} @b{type-error}.
  2101. @i{datum}---an @i{object}.
  2102. @i{expected-type}---a @i{type specifier}.
  2103. @subsubheading Description::
  2104. @b{type-error-datum} returns the offending datum in the @i{situation}
  2105. represented by the @i{condition}.
  2106. @b{type-error-expected-type} returns the expected type of the
  2107. offending datum in the @i{situation} represented by the @i{condition}.
  2108. @subsubheading Examples::
  2109. @example
  2110. (defun fix-digits (condition)
  2111. (check-type condition type-error)
  2112. (let* ((digits '(zero one two three four
  2113. five six seven eight nine))
  2114. (val (position (type-error-datum condition) digits)))
  2115. (if (and val (subtypep 'fixnum (type-error-expected-type condition)))
  2116. (store-value 7))))
  2117. (defun foo (x)
  2118. (handler-bind ((type-error #'fix-digits))
  2119. (check-type x number)
  2120. (+ x 3)))
  2121. (foo 'seven)
  2122. @result{} 10
  2123. @end example
  2124. @subsubheading See Also::
  2125. @b{type-error},
  2126. @ref{Conditions}
  2127. @node simple-type-error, , type-error-datum, Types and Classes Dictionary
  2128. @subsection simple-type-error [Condition Type]
  2129. @subsubheading Class Precedence List::
  2130. @b{simple-type-error},
  2131. @b{simple-condition},
  2132. @b{type-error},
  2133. @b{error},
  2134. @b{serious-condition},
  2135. @b{condition},
  2136. @b{t}
  2137. @subsubheading Description::
  2138. @i{Conditions} of @i{type} @b{simple-type-error}
  2139. are like @i{conditions} of @i{type} @b{type-error},
  2140. except that they provide an alternate mechanism for specifying
  2141. how the @i{condition} is to be @i{reported};
  2142. see the @i{type} @b{simple-condition}.
  2143. @subsubheading See Also::
  2144. @b{simple-condition},
  2145. @ref{simple-condition-format-control; simple-condition-format-arguments}
  2146. ,
  2147. @b{simple-condition-format-arguments},
  2148. @ref{type-error-datum; type-error-expected-type}
  2149. ,
  2150. @b{type-error-expected-type}
  2151. @c end of including dict-types
  2152. @c %**end of chapter