dict-symbols.tex 46 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577
  1. % -*- Mode: TeX -*-
  2. %!!! Sandra: Avoid talking about "symbols in the foo package"
  3. % This is ambiguous. Does it mean "accessible in", "external in",
  4. % "whose home package is", ...?
  5. % Symbol Types
  6. % Symbol Creation
  7. % Symbol Accessors
  8. % Symbol Properties
  9. % Symbol Function/Value
  10. %-------------------- Symbol Types --------------------
  11. \begincom{symbol}\ftype{System Class}
  12. \label Class Precedence List::
  13. \typeref{symbol},
  14. \typeref{t}
  15. \label Description::
  16. %% 11.0.0 11
  17. %% 10.3.0 2
  18. %% 10.3.0 3
  19. %%% 11.0.0 12
  20. % Some stuff about INTERN, IMPORT, SHADOWING-IMPORT, UNINTERN, etc. was commented out.
  21. \term{Symbols} are used for their \term{object} identity to name various entities
  22. in \clisp, including (but not limited to) linguistic entities such as
  23. \term{variables} and \term{functions}.
  24. \term{Symbols} can be collected together into \term{packages}.
  25. A \term{symbol} is said to be \term{interned} in a \term{package}
  26. if it is \term{accessible} in that \term{package};
  27. the same \term{symbol} can be \term{interned} in more than one \term{package}.
  28. If a \term{symbol} is not \term{interned} in any \term{package},
  29. it is called \term{uninterned}.
  30. An \term{interned} \term{symbol} is uniquely identifiable by its \term{name} from
  31. any \term{package} in which it is \term{accessible}.
  32. %!!! Sandra: I REALLY dislike this terminology. Can't we call these "attributes"
  33. % rather than "components" and leave out the discussion of "cells" entirely?
  34. % My attempt at simplifying some of this convoluted discussion of ``cells''
  35. % follows. --sjl 16 Mar 92
  36. %\term{Symbols} have the following components, or \term{cells}.
  37. %(In each case, it is \term{implementation-dependent} how these \term{cells}
  38. %are represented. For example, they might be explicitly represented as a ``slots''
  39. %in the \term{symbol} itself, or they might be represented as external associations
  40. %between the \term{symbol} and the \term{cell} \term{value} (if any) in some
  41. %\term{environment} or table, or in some cases they might not be explicitly
  42. %represented at all.)
  43. \term{Symbols} have the following attributes.
  44. %% "historically" => "historical" per Boyer/Kaufmann/Moore #11 (by X3J13 vote at May 4-5, 1994 meeting)
  45. %% -kmp 9-May-94
  46. For historical reasons,
  47. these are sometimes referred to as \term{cells}, although the actual
  48. internal representation of \term{symbols} and their attributes is
  49. \term{implementation-dependent}.
  50. \beginlist
  51. %% 10.0.0 5
  52. %% 10.2.0 1
  53. \itemitem{\b{Name}}
  54. The \term{name} of a \term{symbol} is a \term{string} used to identify the \term{symbol}.
  55. Every \term{symbol} has a \term{name},
  56. \issue{CHARACTER-PROPOSAL:2-6-3}
  57. and the consequences are undefined if that \term{name} is altered.
  58. \endissue{CHARACTER-PROPOSAL:2-6-3}
  59. The \term{name} is used as part of the external, printed representation of
  60. the \term{symbol}; \seesection\CharacterSyntax.
  61. \Thefunction{symbol-name} returns the \term{name} of a given \term{symbol}.
  62. \issue{CHARACTER-PROPOSAL:2-6-2}
  63. %% I replaced this on suggestion of KAB. It doesn't match CHARACTER-PROPOSAL 2.6.2,
  64. %% so who knows how it got here. -kmp 21-Jan-92
  65. % The \term{characters} in a \term{symbol}'s \term{name} must be \term{graphic},
  66. % and may come from any supported \term{character} \term{repertoire}.
  67. A \term{symbol} may have any \term{character} in its \term{name}.
  68. \endissue{CHARACTER-PROPOSAL:2-6-2}
  69. %% 10.3.0 1
  70. %% 10.0.0 3
  71. %% 10.0.0 4
  72. %% 10.1.0 1
  73. %% 10.1.0 2
  74. %% 10.1.0 3
  75. %% 10.0.0 4
  76. %% 10.3.0 4
  77. %% 11.0.0 8
  78. %% 11.0.0 10
  79. %% 11.0.0 28
  80. \itemitem{\b{Package}}
  81. The \term{object} in this \term{cell} is called the \term{home package}
  82. of the \term{symbol}. If the \term{home package} is \nil, the \term{symbol}
  83. is sometimes said to have no \term{home package}.
  84. When a \term{symbol} is first created, it has no \term{home package}.
  85. When it is first \term{interned}, the \term{package} in which it is
  86. initially \term{interned} becomes its \term{home package}.
  87. The \term{home package} of a \term{symbol} can be \term{accessed}
  88. by using \thefunction{symbol-package}.
  89. If a \term{symbol} is \term{uninterned} from the \term{package}
  90. which is its \term{home package}, its \term{home package} is set to \nil.
  91. Depending on whether there is another \term{package} in which the \term{symbol}
  92. is \term{interned}, the symbol might or might not really be an \term{uninterned} \term{symbol}.
  93. A \term{symbol} with no \term{home package} is therefore called
  94. \term{apparently uninterned}.
  95. \issue{LISP-SYMBOL-REDEFINITION:MAR89-X3J13}
  96. The consequences are undefined if an attempt is made to alter the \term{home package}
  97. of a \term{symbol}
  98. %Added per Sandra -kmp 13-Dec-91
  99. % ``accessible'' is wrong here -- sjl 16 Mar 92
  100. %accessible
  101. external
  102. in \thepackage{common-lisp} or \thepackage{keyword}.
  103. \endissue{LISP-SYMBOL-REDEFINITION:MAR89-X3J13}
  104. %% 10.1.0 4
  105. \itemitem{\b{Property list}}
  106. The \term{property list} of a \term{symbol} provides a mechanism for
  107. associating named attributes with that \term{symbol}.
  108. The operations for adding and removing entries are \term{destructive}
  109. to the \term{property list}. \clisp\ provides \term{operators} both for
  110. direct manipulation of \term{property list} \term{objects}
  111. (\eg see \funref{getf}, \funref{remf}, and \funref{symbol-plist})
  112. and for implicit manipulation of a \term{symbol}'s \term{property list}
  113. by reference to the \term{symbol}
  114. (\eg see \funref{get} and \funref{remprop}).
  115. The \term{property list} associated with a \term{fresh} \term{symbol} is
  116. initially \term{null}.
  117. %!!! Sandra: What about the property list of symbols in the COMMON-LISP package?
  118. %% 10.0.0 8
  119. \itemitem{\b{Value}}
  120. %!!! Sandra: You could avoid this awkwardness [in sentence 1] by not talking about
  121. % cells at all! All you have to say is:
  122. % "If a symbol has a value attribute, it is said to be bound ..."
  123. %!!! KAB: Does this first sentence really have to be said?
  124. % My attempt at rewording this is below. --sjl 16 Mar 92
  125. %Conceptually, every \term{symbol} has a \term{value cell}, although
  126. %no \term{implementation} is required to explicitly represent it as an \term{object}.
  127. %A \term{symbol}'s \term{value cell} might or might not contain an \term{object}.
  128. %If it does contain an \term{object}, it is said to be \term{bound},
  129. If a symbol has a value attribute, it is said to be \term{bound},
  130. and that fact can be detected by \thefunction{boundp}.
  131. The \term{object} contained in the \term{value cell} of a \term{bound} \term{symbol}
  132. is the \term{value} of the \term{global variable} named by that \term{symbol},
  133. and can be \term{accessed} by \thefunction{symbol-value}.
  134. A \term{symbol} can be made to be \term{unbound} by \thefunction{makunbound}.
  135. The consequences are undefined if an attempt is made to change the \term{value}
  136. of a \term{symbol} that names a \term{constant variable}, or to make such a
  137. \term{symbol} be \term{unbound}.
  138. \itemitem{\b{Function}}
  139. %!!! Sandra: See comment on "Value" above.
  140. %!!! KAB: Does this first sentence really have to be said?
  141. % My attempt at rewording this is below. --sjl 16 Mar 92
  142. %Conceptually, every \term{symbol} has a \term{function cell}, although
  143. %no \term{implementation} is required to explicitly represent it as an \term{object}.
  144. %A \term{symbol}'s \term{function cell} might or might not contain an \term{object}.
  145. %If it does contain an \term{object}, it is said to be \term{fbound},
  146. If a symbol has a function attribute, it is said to be \term{fbound},
  147. and that fact can be detected by \thefunction{fboundp}.
  148. If the \term{symbol} is the \term{name} of a \term{function} in the \term{global environment},
  149. the \term{function cell} contains the \term{function},
  150. and can be \term{accessed} by \thefunction{symbol-function}.
  151. If the \term{symbol} is the \term{name} of either
  152. a \term{macro} in the \term{global environment} (see \funref{macro-function})
  153. or a \term{special operator} (see \funref{special-operator-p}),
  154. the \term{symbol} is \term{fbound},
  155. and can be \term{accessed} by \thefunction{symbol-function},
  156. but the \term{object} which the \term{function cell}
  157. contains is of \term{implementation-dependent} \term{type} and purpose.
  158. A \term{symbol} can be made to be \term{funbound} by \thefunction{fmakunbound}.
  159. The consequences are undefined if an attempt is made to change the \term{functional value}
  160. of a \term{symbol} that names a \term{special form}.
  161. \endlist
  162. Operations on a \term{symbol}'s \term{value cell} and \term{function cell} are
  163. sometimes described in terms of their effect on the \term{symbol} itself, but
  164. the user should keep in mind that there is an intimate relationship between the
  165. contents of those \term{cells} and the \term{global variable} or
  166. global \term{function} definition, respectively.
  167. \term{Symbols} are used as identifiers for \term{lexical variables} and
  168. lexical \term{function} definitions, but in that role, only their \term{object}
  169. identity is significant. \clisp\ provides no operation on a \term{symbol} that
  170. can have any effect on a \term{lexical variable} or
  171. on a lexical \term{function} definition.
  172. \label See Also::
  173. {\secref\SymbolTokens},
  174. {\secref\PotentialNumbersAsTokens},
  175. {\secref\PrintingSymbols}
  176. \endcom%{symbol}\ftype{System Class}
  177. \begincom{keyword}\ftype{Type}
  178. %Added per Barrett's suggestion. -kmp 23-Oct-90
  179. \label Supertypes::
  180. \typeref{keyword},
  181. \typeref{symbol},
  182. \typeref{t}
  183. \label Description::
  184. \Thetype{keyword} includes all \term{symbols} \term{interned} \thepackage{keyword}.
  185. %!!! Non-standard use of "intern"?
  186. \term{Interning} a \term{symbol} in \thepackage{keyword} has three automatic effects:
  187. \beginlist
  188. \item{1.} It causes the \term{symbol} to become \term{bound} to itself.
  189. \item{2.} It causes the \term{symbol} to become an \term{external symbol}
  190. of \thepackage{keyword}.
  191. \item{3.} It causes the \term{symbol} to become a \term{constant variable}.
  192. \endlist
  193. \label See Also::
  194. \funref{keywordp}
  195. \endcom%{keyword}\ftype{Type}
  196. %%% ========== SYMBOLP
  197. \begincom{symbolp}\ftype{Function}
  198. \label Syntax::
  199. \DefunWithValues symbolp {object} {generalized-boolean}
  200. \label Arguments and Values::
  201. \param{object}---an \term{object}.
  202. \param{generalized-boolean}---a \term{generalized boolean}.
  203. \label Description::
  204. %% 6.2.2 4
  205. \TypePredicate{object}{symbol}
  206. \label Examples::
  207. \code
  208. (symbolp 'elephant) \EV \term{true}
  209. (symbolp 12) \EV \term{false}
  210. (symbolp nil) \EV \term{true}
  211. (symbolp '()) \EV \term{true}
  212. (symbolp :test) \EV \term{true}
  213. (symbolp "hello") \EV \term{false}
  214. \endcode
  215. \label Side Effects:\None.
  216. \label Affected By:\None.
  217. \label Exceptional Situations:\None!
  218. \label See Also::
  219. \funref{keywordp},
  220. \typeref{symbol},
  221. \funref{typep}
  222. \label Notes::
  223. \code
  224. (symbolp \param{object}) \EQ (typep \param{object} 'symbol)
  225. \endcode
  226. \endcom
  227. %%% ========== KEYWORDP
  228. \begincom{keywordp}\ftype{Function}
  229. \label Syntax::
  230. \DefunWithValues keywordp {object} {generalized-boolean}
  231. \label Arguments and Values::
  232. \param{object}---an \term{object}.
  233. \param{generalized-boolean}---a \term{generalized boolean}.
  234. \label Description::
  235. %% 10.3.0 15
  236. \Predicate{object}{a \term{keyword}\meaning{1}}
  237. \label Examples::
  238. \code
  239. (keywordp 'elephant) \EV \term{false}
  240. (keywordp 12) \EV \term{false}
  241. (keywordp :test) \EV \term{true}
  242. (keywordp ':test) \EV \term{true}
  243. (keywordp nil) \EV \term{false}
  244. (keywordp :nil) \EV \term{true}
  245. (keywordp '(:test)) \EV \term{false}
  246. (keywordp "hello") \EV \term{false}
  247. (keywordp ":hello") \EV \term{false}
  248. (keywordp '&optional) \EV \term{false}
  249. \endcode
  250. \label Side Effects:\None.
  251. \label Affected By:\None.
  252. \label Exceptional Situations:\None!
  253. \label See Also::
  254. \funref{constantp},
  255. \funref{keyword},
  256. \funref{symbolp},
  257. \funref{symbol-package}
  258. \label Notes:\None.
  259. \endcom
  260. %-------------------- Symbol Creation --------------------
  261. %%% ========== MAKE-SYMBOL
  262. \begincom{make-symbol}\ftype{Function}
  263. \label Syntax::
  264. \DefunWithValues make-symbol {name} {new-symbol}
  265. \label Arguments and Values::
  266. %"simple string" => "string" per Barrett. -kmp 14-Feb-92
  267. \param{name}---a \term{string}.
  268. \param{new-symbol}---a \term{fresh}, \term{uninterned} \term{symbol}.
  269. \label Description::
  270. %% 10.3.0 5
  271. \funref{make-symbol} creates and returns a \term{fresh}, \term{uninterned}
  272. \term{symbol} whose \term{name} is the given \param{name}.
  273. The \param{new-symbol} is neither \term{bound} nor \term{fbound}
  274. and has a \term{null} \term{property list}.
  275. %% 10.3.0 6
  276. It is \term{implementation-dependent} whether the \term{string}
  277. that becomes the \param{new-symbol}'s \term{name} is the given
  278. \param{name} or a copy of it. Once a \term{string}
  279. has been given as the \param{name} \term{argument} to
  280. \term{make-symbol}, the consequences are undefined if a
  281. subsequent attempt is made to alter that \term{string}.
  282. \label Examples::
  283. \code
  284. (setq temp-string "temp") \EV "temp"
  285. (setq temp-symbol (make-symbol temp-string)) \EV #:|temp|
  286. (symbol-name temp-symbol) \EV "temp"
  287. (eq (symbol-name temp-symbol) temp-string) \EV \term{implementation-dependent}
  288. (find-symbol "temp") \EV NIL, NIL
  289. (eq (make-symbol temp-string) (make-symbol temp-string)) \EV \term{false}
  290. \endcode
  291. \label Side Effects:\None.
  292. % This sentence seems totally misplaced. --sjl 16 Mar 92
  293. %The \term{value} of the \term{place} named by \param{index}, if any, is modified.
  294. %% Sandra thinks this is excessive.
  295. %Creates a \term{fresh} \term{symbol}.
  296. \label Affected By:\None.
  297. \label Exceptional Situations::
  298. %"simple string" => "string" per Barrett. -kmp 14-Feb-92
  299. \Shouldchecktype{name}{a \term{string}}
  300. \label See Also::
  301. \funref{copy-symbol}
  302. \label Notes::
  303. No attempt is made by \funref{make-symbol} to convert the case
  304. of the \term{name} to uppercase. The only case conversion which ever
  305. occurs for \term{symbols} is done by the \term{Lisp reader}.
  306. The program interface to \term{symbol} creation retains case,
  307. and the program interface to interning symbols is case-sensitive.
  308. \endcom
  309. %%% ========== COPY-SYMBOL
  310. \begincom{copy-symbol}\ftype{Function}
  311. \label Syntax::
  312. \DefunWithValues copy-symbol {symbol {\opt} copy-properties} {new-symbol}
  313. \label Arguments and Values::
  314. \param{symbol}---a \term{symbol}.
  315. \param{copy-properties}---a \term{generalized boolean}.
  316. \Default{\term{false}}
  317. \param{new-symbol}---a \term{fresh}, \term{uninterned} \term{symbol}.
  318. \label Description::
  319. %% 10.3.0 8
  320. \issue{COPY-SYMBOL-PRINT-NAME:EQUAL}
  321. \funref{copy-symbol} returns a \term{fresh}, \term{uninterned} \term{symbol},
  322. the \term{name} of which is \funref{string=} to and possibly the \term{same} as
  323. the \term{name} of the given \param{symbol}.
  324. \endissue{COPY-SYMBOL-PRINT-NAME:EQUAL}
  325. If \param{copy-properties} is \term{false},
  326. the \param{new-symbol} is neither \term{bound} nor \term{fbound}
  327. and has a \term{null} \term{property list}.
  328. If \param{copy-properties} is \term{true}, then
  329. the initial \term{value} of \param{new-symbol} is
  330. the \term{value} of \param{symbol},
  331. the initial \term{function} definition of \param{new-symbol} is
  332. the \term{functional value} of \param{symbol},
  333. and the \term{property list} of \param{new-symbol} is
  334. \issue{COPY-SYMBOL-COPY-PLIST:COPY-LIST}
  335. a \term{copy}\meaning{2} of the \term{property list} of \param{symbol}.
  336. \endissue{COPY-SYMBOL-COPY-PLIST:COPY-LIST}
  337. \label Examples::
  338. \code
  339. (setq fred 'fred-smith) \EV FRED-SMITH
  340. (setf (symbol-value fred) 3) \EV 3
  341. (setq fred-clone-1a (copy-symbol fred nil)) \EV #:FRED-SMITH
  342. (setq fred-clone-1b (copy-symbol fred nil)) \EV #:FRED-SMITH
  343. (setq fred-clone-2a (copy-symbol fred t)) \EV #:FRED-SMITH
  344. (setq fred-clone-2b (copy-symbol fred t)) \EV #:FRED-SMITH
  345. (eq fred fred-clone-1a) \EV \term{false}
  346. (eq fred-clone-1a fred-clone-1b) \EV \term{false}
  347. (eq fred-clone-2a fred-clone-2b) \EV \term{false}
  348. (eq fred-clone-1a fred-clone-2a) \EV \term{false}
  349. (symbol-value fred) \EV 3
  350. (boundp fred-clone-1a) \EV \term{false}
  351. (symbol-value fred-clone-2a) \EV 3
  352. (setf (symbol-value fred-clone-2a) 4) \EV 4
  353. (symbol-value fred) \EV 3
  354. (symbol-value fred-clone-2a) \EV 4
  355. (symbol-value fred-clone-2b) \EV 3
  356. (boundp fred-clone-1a) \EV \term{false}
  357. (setf (symbol-function fred) #'(lambda (x) x)) \EV #<FUNCTION anonymous>
  358. (fboundp fred) \EV \term{true}
  359. (fboundp fred-clone-1a) \EV \term{false}
  360. (fboundp fred-clone-2a) \EV \term{false}
  361. \endcode
  362. \label Side Effects:\None.
  363. %% Sandra thinks this is excessive.
  364. %Creates a \term{fresh} \term{symbol}.
  365. \label Affected By:\None.
  366. \label Exceptional Situations::
  367. \Shouldchecktype{symbol}{a \term{symbol}}
  368. \label See Also::
  369. \funref{make-symbol}
  370. \label Notes::
  371. Implementors are encouraged not to copy the \term{string}
  372. which is the \term{symbol}'s \term{name} unnecessarily.
  373. Unless there is a good reason to do so, the normal implementation
  374. strategy is for the \param{new-symbol}'s \term{name} to
  375. be \term{identical} to the given \param{symbol}'s \term{name}.
  376. %% Barrett: This is only true if the implementation of MAKE-SYMBOL
  377. % doesn't copy, which it might.
  378. %
  379. % \code
  380. % (copy-symbol \param{x} nil) \EQ (make-symbol (symbol-name \param{x}))
  381. % \endcode
  382. \endcom
  383. %%% ========== GENSYM
  384. \begincom{gensym}\ftype{Function}
  385. \label Syntax::
  386. \DefunWithValues gensym {{\opt} x} {new-symbol}
  387. \label Arguments and Values::
  388. \param{x}---a \term{string} or a non-negative \term{integer}.
  389. \HairyDefault.
  390. \param{new-symbol}---a \term{fresh}, \term{uninterned} \term{symbol}.
  391. \label Description::
  392. %% 10.3.0 9
  393. %% 10.3.0 10
  394. %% 10.3.0 11
  395. Creates and returns a \term{fresh}, \term{uninterned} \term{symbol},
  396. as if by calling \funref{make-symbol}. (The only difference between
  397. \funref{gensym} and \funref{make-symbol} is in how the \param{new-symbol}'s
  398. \term{name} is determined.)
  399. The \term{name} of the \param{new-symbol} is the concatenation
  400. of a prefix, which defaults to \f{"G"}, and
  401. \issue{GENSYM-NAME-STICKINESS:LIKE-TEFLON}
  402. a suffix, which is the decimal representation of a number that
  403. defaults to \thevalueof{*gensym-counter*}.
  404. If \param{x} is supplied, and is a \term{string}, then that \term{string}
  405. is used as a prefix instead of \f{"G"} for this call to \funref{gensym} only.
  406. If \param{x} is supplied, and is an \term{integer}, then that \term{integer},
  407. instead of \thevalueof{*gensym-counter*}, is used as the suffix
  408. for this call to \funref{gensym} only.
  409. If and only if no explicit suffix is supplied,
  410. \varref{*gensym-counter*} is incremented after it is used.
  411. \endissue{GENSYM-NAME-STICKINESS:LIKE-TEFLON}
  412. \label Examples::
  413. \code
  414. (setq sym1 (gensym)) \EV #:G3142
  415. (symbol-package sym1) \EV NIL
  416. (setq sym2 (gensym 100)) \EV #:G100
  417. (setq sym3 (gensym 100)) \EV #:G100
  418. (eq sym2 sym3) \EV \term{false}
  419. (find-symbol "G100") \EV NIL, NIL
  420. (gensym "T") \EV #:T3143
  421. (gensym) \EV #:G3144
  422. \endcode
  423. \label Side Effects::
  424. %% Sandra thinks this is excessive.
  425. %Creates a \term{fresh} \term{symbol}.
  426. Might increment \varref{*gensym-counter*}.
  427. \label Affected By::
  428. \varref{*gensym-counter*}
  429. \label Exceptional Situations::
  430. \Shouldchecktype{x}{a \term{string} or a non-negative \term{integer}}
  431. \label See Also::
  432. \funref{gentemp},
  433. \varref{*gensym-counter*}
  434. \label Notes::
  435. The ability to pass a numeric argument to \funref{gensym} has been deprecated;
  436. explicitly \term{binding} \varref{*gensym-counter*} is now stylistically preferred.
  437. (The somewhat baroque conventions for the optional argument are historical
  438. in nature, and supported primarily for compatibility with older dialects
  439. of \Lisp. In modern code, it is recommended that the only kind of argument
  440. used be a string prefix. In general, though, to obtain more flexible control
  441. of the \param{new-symbol}'s \term{name}, consider using \funref{make-symbol} instead.)
  442. \endcom
  443. %%% ========== *GENSYM-COUNTER*
  444. \begincom{*gensym-counter*}\ftype{Variable}
  445. \issue{GENSYM-NAME-STICKINESS:LIKE-TEFLON}
  446. \label Value Type::
  447. a non-negative \term{integer}.
  448. \label Initial Value::
  449. %A non-negative \term{integer}, the magnitude of which is
  450. \term{implementation-dependent}.
  451. \label Description::
  452. A number which will be used in constructing the \term{name} of
  453. the next \term{symbol} generated by \thefunction{gensym}.
  454. \varref{*gensym-counter*} can be either \term{assigned} or \term{bound}
  455. at any time, but its value must always be a non-negative \term{integer}.
  456. \label Examples:\None.
  457. \label Affected By::
  458. \funref{gensym}.
  459. \label See Also::
  460. \funref{gensym}
  461. \label Notes::
  462. The ability to pass a numeric argument to \funref{gensym} has been deprecated;
  463. explicitly \term{binding} \varref{*gensym-counter*} is now stylistically preferred.
  464. \endissue{GENSYM-NAME-STICKINESS:LIKE-TEFLON}
  465. \endcom
  466. %%% ========== GENTEMP
  467. \begincom{gentemp}\ftype{Function}
  468. \label Syntax::
  469. \DefunWithValues gentemp {{\opt} prefix package} {new-symbol}
  470. \label Arguments and Values::
  471. \param{prefix}---a \term{string}.
  472. \Default{\f{"T"}}
  473. \param{package}---a \term{package designator}.
  474. \Default{the \term{current package}}
  475. \param{new-symbol}---a \term{fresh}, \term{interned} \term{symbol}.
  476. \label Description::
  477. %% 10.3.0 14
  478. \funref{gentemp} creates and returns a \term{fresh} \term{symbol},
  479. \term{interned} in the indicated \param{package}.
  480. %The \term{symbol} is guaranteed to be one that did not previously
  481. %exist in \param{package}.
  482. The \term{symbol} is guaranteed to be one that was not previously
  483. \term{accessible} in \param{package}.
  484. It is neither \term{bound} nor \term{fbound}, and has a \term{null}
  485. \term{property list}.
  486. The \term{name} of the \param{new-symbol} is the concatenation
  487. of the \param{prefix} and a suffix, which is taken from an internal
  488. counter used only by \funref{gentemp}. (If a \term{symbol} by that name
  489. % already exists in \param{package}, the counter is incremented as
  490. is already \term{accessible} in \param{package}, the counter is incremented as
  491. many times as is necessary to produce a \term{name} that is not already the
  492. \term{name} of a \term{symbol} \term{accessible} in \param{package}.)
  493. \label Examples::
  494. \code
  495. (gentemp) \EV T1298
  496. (gentemp "FOO") \EV FOO1299
  497. (find-symbol "FOO1300") \EV NIL, NIL
  498. (gentemp "FOO") \EV FOO1300
  499. (find-symbol "FOO1300") \EV FOO1300, :INTERNAL
  500. (intern "FOO1301") \EV FOO1301, :INTERNAL
  501. (gentemp "FOO") \EV FOO1302
  502. (gentemp) \EV T1303
  503. \endcode
  504. \label Side Effects::
  505. Its internal counter is incremented one or more times.
  506. \term{Interns} the \param{new-symbol} in \param{package}.
  507. \label Affected By::
  508. The current state of its internal counter, and
  509. the current state of the \param{package}.
  510. \label Exceptional Situations::
  511. \Shouldchecktype{prefix}{a \term{string}}
  512. \Shouldchecktype{package}{a \term{package designator}}
  513. \label See Also::
  514. \funref{gensym}
  515. \label Notes::
  516. The function \funref{gentemp} is deprecated.
  517. If \param{package} is \thepackage{keyword},
  518. the result is an \term{external symbol} of \param{package}.
  519. Otherwise, the result is an \term{internal symbol} of \param{package}.
  520. The \funref{gentemp} internal counter is independent of
  521. \varref{*gensym-counter*}, the counter used by \funref{gensym}.
  522. There is no provision for accessing the \funref{gentemp} internal counter.
  523. Just because \funref{gentemp} creates a \term{symbol} which did not
  524. previously exist does not mean that such a \term{symbol} might not be
  525. seen in the future (\eg in a data file---perhaps even created by the
  526. same program in another session). As such, this symbol is not truly
  527. unique in the same sense as a \term{gensym} would be. In particular,
  528. programs which do automatic code generation should be careful not to
  529. attach global attributes to such generated \term{symbols} (\eg
  530. \declref{special} \term{declarations}) and then write them into a file
  531. because such global attributes might, in a different session, end up
  532. applying to other \term{symbols} that were automatically generated on
  533. another day for some other purpose.
  534. \endcom
  535. %-------------------- Symbol Accessors --------------------
  536. %%% ========== SYMBOL-FUNCTION
  537. \begincom{symbol-function}\ftype{Accessor}
  538. \label Syntax::
  539. \DefunWithValues symbol-function {symbol} {contents}
  540. \Defsetf symbol-function {symbol} {new-contents}
  541. \label Arguments and Values::
  542. \issue{FUNCTION-TYPE:X3J13-MARCH-88}
  543. % The symbol need not be fbound for the SETF form. --sjl 16 Mar 92
  544. %\param{symbol}---an \term{fbound} \term{symbol}.
  545. \param{symbol}---a \term{symbol}.
  546. \endissue{FUNCTION-TYPE:X3J13-MARCH-88}
  547. \param{contents}---
  548. \issue{FUNCTION-TYPE:X3J13-MARCH-88}
  549. If the \param{symbol} is globally defined as a \term{macro} or a \term{special operator},
  550. %% Removed per Barrett. -kmp 14-Feb-92
  551. %and if the \param{symbol} is \term{fbound},
  552. an \term{object} of \term{implementation-dependent} nature and identity is returned.
  553. If the \param{symbol} is not globally defined as
  554. either a \term{macro} or a \term{special operator},
  555. and
  556. if the \param{symbol} is \term{fbound},
  557. a \term{function} \term{object} is returned.
  558. \endissue{FUNCTION-TYPE:X3J13-MARCH-88}
  559. \issue{FUNCTION-TYPE:X3J13-MARCH-88}
  560. \param{new-contents}---a \term{function}.
  561. \endissue{FUNCTION-TYPE:X3J13-MARCH-88}
  562. %% This shouldn't be needed, actually.
  563. % \issue{FUNCTION-TYPE:X3J13-MARCH-88}
  564. % The consequences of attempting to make the global \term{function} definition
  565. % of a \term{symbol} be a \term{symbol}, a \term{list}, or the value returned
  566. % by \funref{symbol-function} on the name of a \term{macro} or a
  567. % \term{special form} are unspecified.
  568. % \endissue{FUNCTION-TYPE:X3J13-MARCH-88}
  569. \label Description::
  570. %% 7.1.1 14
  571. \term{Accesses} the \term{symbol}'s \term{function cell}.
  572. \label Examples::
  573. %Some examples involving FBOUNDP simplified/corrected per Moore #2 (first public review)
  574. % -kmp 12-May-93
  575. \code
  576. (symbol-function 'car) \EV #<FUNCTION CAR>
  577. (symbol-function 'twice) is an error ;because TWICE isn't defined.
  578. (defun twice (n) (* n 2)) \EV TWICE
  579. (symbol-function 'twice) \EV #<FUNCTION TWICE>
  580. (list (twice 3)
  581. (funcall (function twice) 3)
  582. (funcall (symbol-function 'twice) 3))
  583. \EV (6 6 6)
  584. (flet ((twice (x) (list x x)))
  585. (list (twice 3)
  586. (funcall (function twice) 3)
  587. (funcall (symbol-function 'twice) 3)))
  588. \EV ((3 3) (3 3) 6)
  589. (setf (symbol-function 'twice) #'(lambda (x) (list x x)))
  590. \EV #<FUNCTION anonymous>
  591. (list (twice 3)
  592. (funcall (function twice) 3)
  593. (funcall (symbol-function 'twice) 3))
  594. \EV ((3 3) (3 3) (3 3))
  595. (fboundp 'defun) \EV \term{true}
  596. (symbol-function 'defun)
  597. \EV \term{implementation-dependent}
  598. (functionp (symbol-function 'defun))
  599. \EV \term{implementation-dependent}
  600. (defun symbol-function-or-nil (symbol)
  601. (if (and (fboundp symbol)
  602. (not (macro-function symbol))
  603. (not (special-operator-p symbol)))
  604. (symbol-function symbol)
  605. nil)) \EV SYMBOL-FUNCTION-OR-NIL
  606. (symbol-function-or-nil 'car) \EV #<FUNCTION CAR>
  607. (symbol-function-or-nil 'defun) \EV NIL
  608. \endcode
  609. \label Side Effects:\None.
  610. \label Affected By::
  611. \macref{defun}
  612. \label Exceptional Situations::
  613. \Shouldchecktype{symbol}{a \term{symbol}}
  614. Should signal \typeref{undefined-function} if \param{symbol} is not \term{fbound}
  615. and an attempt is made to \term{read} its definition. (No such error is signaled
  616. on an attempt to \term{write} its definition.)
  617. \label See Also::
  618. \funref{fboundp},
  619. \funref{fmakunbound},
  620. \funref{macro-function},
  621. \issue{SPECIAL-FORM-P-MISNOMER:RENAME}
  622. \funref{special-operator-p}
  623. \endissue{SPECIAL-FORM-P-MISNOMER:RENAME}
  624. \label Notes::
  625. %% 7.1.1 16
  626. \funref{symbol-function} cannot \term{access} the value of a lexical function name
  627. produced by \specref{flet} or \specref{labels}; it can \term{access} only
  628. the global function value.
  629. %!!! Sandra thinks this should be in the Description. I'm not so sure. -kmp 13-Dec-91
  630. \macref{setf} may be used with
  631. \funref{symbol-function} to replace a global function
  632. definition when the \term{symbol}'s function definition
  633. does not represent a \term{special operator}.
  634. \code
  635. (symbol-function \param{symbol}) \EQ (fdefinition \param{symbol})
  636. \endcode
  637. However, \funref{fdefinition} accepts arguments other than just \term{symbols}.
  638. \endcom
  639. %%% ========== SYMBOL-NAME
  640. \begincom{symbol-name}\ftype{Function}
  641. \label Syntax::
  642. \DefunWithValues symbol-name {symbol} {name}
  643. \label Arguments and Values::
  644. \param{symbol}---a \term{symbol}.
  645. %"simple string" => "string" per Barrett. -kmp 14-Feb-92
  646. \param{name}---a \term{string}.
  647. \label Description::
  648. %% 10.2.0 2
  649. \funref{symbol-name} returns the \term{name} of \param{symbol}.
  650. \issue{LISP-SYMBOL-REDEFINITION:MAR89-X3J13}
  651. The consequences are undefined if \param{name} is ever modified.
  652. \endissue{LISP-SYMBOL-REDEFINITION:MAR89-X3J13}
  653. \label Examples::
  654. \code
  655. (symbol-name 'temp) \EV "TEMP"
  656. (symbol-name :start) \EV "START"
  657. (symbol-name (gensym)) \EV "G1234" ;for example
  658. \endcode
  659. \label Side Effects:\None.
  660. \label Affected By:\None.
  661. \label Exceptional Situations::
  662. \Shouldchecktype{symbol}{a \term{symbol}}
  663. \label See Also:\None.
  664. \label Notes:\None.
  665. \endcom
  666. %%% ========== SYMBOL-PACKAGE
  667. \begincom{symbol-package}\ftype{Function}
  668. \label Syntax::
  669. \DefunWithValues symbol-package {symbol} {contents}
  670. \label Arguments and Values::
  671. \param{symbol}---a \term{symbol}.
  672. \param{contents}---a \term{package} \term{object} or \nil.
  673. \label Description::
  674. %% 10.3.0 15
  675. Returns the \term{home package} of \param{symbol}.
  676. \label Examples::
  677. \code
  678. (in-package "CL-USER") \EV #<PACKAGE "COMMON-LISP-USER">
  679. (symbol-package 'car) \EV #<PACKAGE "COMMON-LISP">
  680. (symbol-package 'bus) \EV #<PACKAGE "COMMON-LISP-USER">
  681. (symbol-package :optional) \EV #<PACKAGE "KEYWORD">
  682. ;; Gensyms are uninterned, so have no home package.
  683. (symbol-package (gensym)) \EV NIL
  684. (make-package 'pk1) \EV #<PACKAGE "PK1">
  685. (intern "SAMPLE1" "PK1") \EV PK1::SAMPLE1, NIL
  686. (export (find-symbol "SAMPLE1" "PK1") "PK1") \EV T
  687. (make-package 'pk2 :use '(pk1)) \EV #<PACKAGE "PK2">
  688. (find-symbol "SAMPLE1" "PK2") \EV PK1:SAMPLE1, :INHERITED
  689. (symbol-package 'pk1::sample1) \EV #<PACKAGE "PK1">
  690. (symbol-package 'pk2::sample1) \EV #<PACKAGE "PK1">
  691. (symbol-package 'pk1::sample2) \EV #<PACKAGE "PK1">
  692. (symbol-package 'pk2::sample2) \EV #<PACKAGE "PK2">
  693. ;; The next several forms create a scenario in which a symbol
  694. ;; is not really uninterned, but is "apparently uninterned",
  695. ;; and so SYMBOL-PACKAGE still returns NIL.
  696. (setq s3 'pk1::sample3) \EV PK1::SAMPLE3
  697. (import s3 'pk2) \EV T
  698. (unintern s3 'pk1) \EV T
  699. (symbol-package s3) \EV NIL
  700. (eq s3 'pk2::sample3) \EV T
  701. \endcode
  702. \label Side Effects:\None.
  703. \label Affected By::
  704. \funref{import},
  705. \funref{intern},
  706. \funref{unintern}
  707. \label Exceptional Situations::
  708. \Shouldchecktype{symbol}{a \term{symbol}}
  709. \label See Also::
  710. \funref{intern}
  711. \label Notes:\None.
  712. \endcom
  713. %%% ========== SYMBOL-PLIST
  714. \begincom{symbol-plist}\ftype{Accessor}
  715. \label Syntax::
  716. \DefunWithValues symbol-plist {symbol} {plist}
  717. \Defsetf symbol-plist {symbol} {new-plist}
  718. \label Arguments and Values::
  719. \param{symbol}---a \term{symbol}.
  720. \param{plist}, \param{new-plist}---a \term{property list}.
  721. \label Description::
  722. %% 10.1.0 14
  723. %% 10.1.0 16
  724. \term{Accesses} the \term{property list} of \param{symbol}.
  725. \label Examples::
  726. \code
  727. (setq sym (gensym)) \EV #:G9723
  728. (symbol-plist sym) \EV ()
  729. (setf (get sym 'prop1) 'val1) \EV VAL1
  730. (symbol-plist sym) \EV (PROP1 VAL1)
  731. (setf (get sym 'prop2) 'val2) \EV VAL2
  732. (symbol-plist sym) \EV (PROP2 VAL2 PROP1 VAL1)
  733. (setf (symbol-plist sym) (list 'prop3 'val3)) \EV (PROP3 VAL3)
  734. (symbol-plist sym) \EV (PROP3 VAL3)
  735. \endcode
  736. \label Side Effects:\None.
  737. \label Affected By:\None.
  738. \label Exceptional Situations::
  739. \Shouldchecktype{symbol}{a \term{symbol}}
  740. \label See Also::
  741. \funref{get},
  742. \funref{remprop}
  743. %!!! Barmar thinks there should be a concept section describing
  744. % the format of a plist.
  745. \label Notes::
  746. The use of \macref{setf} should be avoided, since a \term{symbol}'s
  747. \term{property list} is a global resource that can contain information
  748. established and depended upon by unrelated programs in the same \term{Lisp image}.
  749. \endcom
  750. %%% ========== SYMBOL-VALUE
  751. \begincom{symbol-value}\ftype{Accessor}
  752. \label Syntax::
  753. \DefunWithValues symbol-value {symbol} {value}
  754. \Defsetf symbol-value {symbol} {new-value}
  755. \label Arguments and Values::
  756. \param{symbol}---a \term{symbol} that must have a \term{value}.
  757. \param{value}, \param{new-value}---an \term{object}.
  758. \label Description::
  759. \term{Accesses} the \term{symbol}'s \term{value cell}.
  760. \label Examples::
  761. \code
  762. (setf (symbol-value 'a) 1) \EV 1
  763. (symbol-value 'a) \EV 1
  764. ;; SYMBOL-VALUE cannot see lexical variables.
  765. (let ((a 2)) (symbol-value 'a)) \EV 1
  766. (let ((a 2)) (setq a 3) (symbol-value 'a)) \EV 1
  767. ;; SYMBOL-VALUE can see dynamic variables.
  768. (let ((a 2))
  769. (declare (special a))
  770. (symbol-value 'a)) \EV 2
  771. (let ((a 2))
  772. (declare (special a))
  773. (setq a 3)
  774. (symbol-value 'a)) \EV 3
  775. (let ((a 2))
  776. (setf (symbol-value 'a) 3)
  777. a) \EV 2
  778. a \EV 3
  779. (symbol-value 'a) \EV 3
  780. (let ((a 4))
  781. (declare (special a))
  782. (let ((b (symbol-value 'a)))
  783. (setf (symbol-value 'a) 5)
  784. (values a b))) \EV 5, 4
  785. a \EV 3
  786. (symbol-value :any-keyword) \EV :ANY-KEYWORD
  787. (symbol-value 'nil) \EV NIL
  788. (symbol-value '()) \EV NIL
  789. ;; The precision of this next one is \term{implementation-dependent}.
  790. (symbol-value 'pi) \EV 3.141592653589793d0
  791. \endcode
  792. \label Side Effects:\None.
  793. \label Affected By::
  794. \funref{makunbound},
  795. \funref{set},
  796. \specref{setq}
  797. \label Exceptional Situations::
  798. \Shouldchecktype{symbol}{a \term{symbol}}
  799. Should signal \typeref{unbound-variable} if \param{symbol} is \term{unbound}
  800. and an attempt is made to \term{read} its \term{value}. (No such error is signaled
  801. on an attempt to \term{write} its \term{value}.)
  802. \label See Also::
  803. \funref{boundp}, \funref{makunbound}, \funref{set}, \specref{setq}
  804. \label Notes::
  805. \funref{symbol-value} can be used to get the value of a \term{constant variable}.
  806. %% 7.1.1 12
  807. \funref{symbol-value} cannot \term{access} the value of a \term{lexical variable}.
  808. \endcom
  809. %-------------------- Symbol Properties --------------------
  810. %%% ========== GET
  811. \begincom{get}\ftype{Accessor}
  812. \label Syntax::
  813. \DefunWithValues get {symbol indicator {\opt} default} {value}
  814. \Defsetf get {symbol indicator {\opt} default} {new-value}
  815. \label Arguments and Values::
  816. \param{symbol}---a \term{symbol}.
  817. \param{indicator}---an \term{object}.
  818. \param{default}---an \term{object}.
  819. \Default{\nil}
  820. \param{value}---if the indicated property exists,
  821. the \term{object} that is its \term{value};
  822. otherwise, the specified \param{default}.
  823. \param{new-value}---an \term{object}.
  824. \label Description::
  825. %% 10.1.0 8
  826. %% Barrett: Redundant with next paragraph.
  827. % \funref{get} searches the \term{property list} of \param{symbol} for an
  828. % indicator \funref{eq} to \param{indicator}.
  829. % \funref{get} returns the corresponding value of an indicator from
  830. % the \term{property list} of \param{symbol} \funref{eq} to \param{indicator},
  831. % if one is found.
  832. \funref{get} finds a \term{property}
  833. on the \term{property list}\meaning{2} of \param{symbol}
  834. whose \term{property indicator} is \term{identical} to \param{indicator},
  835. and returns its corresponding \term{property value}.
  836. \issue{PLIST-DUPLICATES:ALLOW}
  837. If there are multiple \term{properties}\meaning{1} with that \term{property indicator},
  838. \funref{get} uses the first such \term{property}.
  839. \endissue{PLIST-DUPLICATES:ALLOW}
  840. If there is no \term{property} with that \term{property indicator},
  841. \param{default} is returned.
  842. % %% 10.1.0 12
  843. % \macref{setf} may be used with \funref{get} to create a new property-value
  844. % pair, possibly replacing an old pair with the same property name.
  845. \macref{setf} of \funref{get} may be used to associate a new \term{object}
  846. with an existing indicator already on the \param{symbol}'s \term{property list},
  847. or to create a new assocation if none exists.
  848. \issue{PLIST-DUPLICATES:ALLOW}
  849. If there are multiple \term{properties}\meaning{1} with that \term{property indicator},
  850. \macref{setf} of \funref{get} associates the \param{new-value}
  851. with the first such \term{property}.
  852. \endissue{PLIST-DUPLICATES:ALLOW}
  853. \issue{SETF-GET-DEFAULT:EVALUATED-BUT-IGNORED}
  854. When a \funref{get} \term{form} is used as a \macref{setf} \param{place},
  855. any \param{default} which is supplied is evaluated according to normal
  856. left-to-right evaluation rules, but its \term{value} is ignored.
  857. \endissue{SETF-GET-DEFAULT:EVALUATED-BUT-IGNORED}
  858. \label Examples::
  859. \code
  860. (defun make-person (first-name last-name)
  861. (let ((person (gensym "PERSON")))
  862. (setf (get person 'first-name) first-name)
  863. (setf (get person 'last-name) last-name)
  864. person)) \EV MAKE-PERSON
  865. (defvar *john* (make-person "John" "Dow")) \EV *JOHN*
  866. *john* \EV #:PERSON4603
  867. (defvar *sally* (make-person "Sally" "Jones")) \EV *SALLY*
  868. (get *john* 'first-name) \EV "John"
  869. (get *sally* 'last-name) \EV "Jones"
  870. (defun marry (man woman married-name)
  871. (setf (get man 'wife) woman)
  872. (setf (get woman 'husband) man)
  873. (setf (get man 'last-name) married-name)
  874. (setf (get woman 'last-name) married-name)
  875. married-name) \EV MARRY
  876. (marry *john* *sally* "Dow-Jones") \EV "Dow-Jones"
  877. (get *john* 'last-name) \EV "Dow-Jones"
  878. (get (get *john* 'wife) 'first-name) \EV "Sally"
  879. (symbol-plist *john*)
  880. \EV (WIFE #:PERSON4604 LAST-NAME "Dow-Jones" FIRST-NAME "John")
  881. (defmacro age (person &optional (default ''thirty-something))
  882. `(get ,person 'age ,default)) \EV AGE
  883. (age *john*) \EV THIRTY-SOMETHING
  884. (age *john* 20) \EV 20
  885. (setf (age *john*) 25) \EV 25
  886. (age *john*) \EV 25
  887. (age *john* 20) \EV 25
  888. \endcode
  889. \label Side Effects:\None.
  890. \label Affected By:\None.
  891. \label Exceptional Situations::
  892. \Shouldchecktype{symbol}{a \term{symbol}}
  893. \label See Also::
  894. \funref{getf},
  895. \funref{symbol-plist},
  896. \funref{remprop}
  897. \label Notes::
  898. \code
  899. (get x y) \EQ (getf (symbol-plist x) y)
  900. \endcode
  901. \term{Numbers} and \term{characters} are not recommended for use
  902. as \param{indicators} in portable code since \funref{get} tests
  903. with \funref{eq} rather than \funref{eql}, and consequently
  904. the effect of using such \param{indicators} is
  905. \term{implementation-dependent}.
  906. % \code
  907. % (get 'clyde 'species) \EV NIL
  908. % (setf (get 'clyde 'species) 'elephant) \EV elephant
  909. % (get 'clyde 'species) \EV ELEPHANT
  910. % \endcode
  911. % \param{Default} may be supplied to \funref{get} in this context;
  912. % it is ignored by the \macref{setf} expander function
  913. % for \funref{get}, but
  914. % may be useful in such macros as \macref{push}
  915. % that are related to \macref{setf}:
  916. %
  917. % \code
  918. % (push item (get sym 'token-stack '(initial-item)))
  919. % \endcode
  920. % means approximately the same as
  921. %
  922. % \code
  923. % (setf (get sym 'token-stack '(initial-item))
  924. % (cons item (get sym 'token-stack '(initial-item))))
  925. % \endcode
  926. % which in turn would be treated as
  927. %
  928. % \code
  929. % (setf (get sym 'token-stack)
  930. % (cons item (get sym 'token-stack '(initial-item))))
  931. % \endcode
  932. %
  933. There is no way using \funref{get} to distinguish an absent property from
  934. one whose value is \param{default}. However, see \funref{get-properties}.
  935. % %% 10.1.0 15
  936. % Using \funref{get} on the result of \funref{symbol-plist} does not work;
  937. % the \term{symbol} itself must be given to \funref{get}. \funref{getf} can
  938. % be used to extract properties from a disembodied property list.
  939. \endcom
  940. %%% ========== REMPROP
  941. \begincom{remprop}\ftype{Function}
  942. \label Syntax::
  943. \DefunWithValues remprop {symbol indicator} {generalized-boolean}
  944. \label Arguments and Values::
  945. \param{symbol}---a \term{symbol}.
  946. \param{indicator}---an \term{object}.
  947. \param{generalized-boolean}---a \term{generalized boolean}.
  948. \label Description::
  949. %% 10.1.0 13
  950. \funref{remprop} removes from the \term{property list}\meaning{2} of \param{symbol}
  951. a \term{property}\meaning{1} with a \term{property indicator}
  952. % EQ => identical -kmp 14-Jul-93
  953. \term{identical} to \param{indicator}.
  954. \issue{PLIST-DUPLICATES:ALLOW}
  955. If there are multiple \term{properties}\meaning{1} with the \term{identical} key,
  956. \macref{remprop} only removes the first such \term{property}.
  957. \endissue{PLIST-DUPLICATES:ALLOW}
  958. \macref{remprop} returns \term{false} if no such \term{property} was found,
  959. or \term{true} if a property was found.
  960. The \term{property indicator}
  961. and the corresponding \term{property value}
  962. are removed in an undefined order
  963. by destructively splicing the property list.
  964. \issue{REMF-DESTRUCTION-UNSPECIFIED:X3J13-MAR-89}
  965. The permissible side-effects correspond to those permitted for \macref{remf},
  966. such that:
  967. \code
  968. (remprop \i{x} \i{y}) \EQ (remf (symbol-plist \i{x}) \i{y})
  969. \endcode
  970. \endissue{REMF-DESTRUCTION-UNSPECIFIED:X3J13-MAR-89}
  971. \label Examples::
  972. \code
  973. (setq test (make-symbol "PSEUDO-PI")) \EV #:PSEUDO-PI
  974. (symbol-plist test) \EV ()
  975. (setf (get test 'constant) t) \EV T
  976. (setf (get test 'approximation) 3.14) \EV 3.14
  977. (setf (get test 'error-range) 'noticeable) \EV NOTICEABLE
  978. (symbol-plist test)
  979. \EV (ERROR-RANGE NOTICEABLE APPROXIMATION 3.14 CONSTANT T)
  980. (setf (get test 'approximation) nil) \EV NIL
  981. (symbol-plist test)
  982. \EV (ERROR-RANGE NOTICEABLE APPROXIMATION NIL CONSTANT T)
  983. (get test 'approximation) \EV NIL
  984. (remprop test 'approximation) \EV \term{true}
  985. (get test 'approximation) \EV NIL
  986. (symbol-plist test)
  987. \EV (ERROR-RANGE NOTICEABLE CONSTANT T)
  988. (remprop test 'approximation) \EV NIL
  989. (symbol-plist test)
  990. \EV (ERROR-RANGE NOTICEABLE CONSTANT T)
  991. (remprop test 'error-range) \EV \term{true}
  992. (setf (get test 'approximation) 3) \EV 3
  993. (symbol-plist test)
  994. \EV (APPROXIMATION 3 CONSTANT T)
  995. \endcode
  996. \label Side Effects::
  997. The \term{property list} of \param{symbol} is modified.
  998. \label Affected By:\None.
  999. \label Exceptional Situations::
  1000. \Shouldchecktype{symbol}{a \term{symbol}}
  1001. \label See Also::
  1002. \macref{remf}, \funref{symbol-plist}
  1003. \label Notes::
  1004. \term{Numbers} and \term{characters} are not recommended for use as
  1005. \param{indicators} in portable code since \funref{remprop} tests with
  1006. \funref{eq} rather than \funref{eql}, and consequently the effect of
  1007. using such \param{indicators} is \term{implementation-dependent}.
  1008. Of course, if you've gotten as far as needing to remove such a
  1009. \term{property}, you don't have much choice---the time to have been
  1010. thinking about this was when you used \macref{setf} of \macref{get} to
  1011. establish the \term{property}.
  1012. %Barrett: Bletch.
  1013. \endcom
  1014. %-------------------- Symbol Function/Value --------------------
  1015. %%% ========== BOUNDP
  1016. \begincom{boundp}\ftype{Function}
  1017. \label Syntax::
  1018. \DefunWithValues boundp {symbol} {generalized-boolean}
  1019. \label Arguments and Values::
  1020. \param{symbol}---a \term{symbol}.
  1021. \param{generalized-boolean}---a \term{generalized boolean}.
  1022. \label Description::
  1023. %% 7.1.1 18
  1024. \Predicate{symbol}{\term{bound}}
  1025. \label Examples::
  1026. \code
  1027. (setq x 1) \EV 1
  1028. (boundp 'x) \EV \term{true}
  1029. (makunbound 'x) \EV X
  1030. (boundp 'x) \EV \term{false}
  1031. (let ((x 2)) (boundp 'x)) \EV \term{false}
  1032. (let ((x 2)) (declare (special x)) (boundp 'x)) \EV \term{true}
  1033. \endcode
  1034. \label Affected By:\None.
  1035. \label Exceptional Situations::
  1036. \Shouldchecktype{symbol}{a \term{symbol}}
  1037. \label See Also::
  1038. \funref{set},
  1039. \specref{setq},
  1040. \funref{symbol-value},
  1041. \funref{makunbound}
  1042. \label Notes::
  1043. % I see no lexical environment here. --sjl 16 Mar 92
  1044. %The \term{lexical environment} is ignored.
  1045. \Thefunction{bound} determines only whether a \term{symbol} has a
  1046. value in the \term{global environment}; any \term{lexical bindings}
  1047. are ignored.
  1048. \endcom
  1049. %%% ========== MAKUNBOUND
  1050. \begincom{makunbound}\ftype{Function}
  1051. %!!! Barmar thinks that fmakunbound should move to dict-functions.
  1052. \label Syntax::
  1053. \DefunWithValues makunbound {symbol} {symbol}
  1054. \label Arguments and Values::
  1055. \param{symbol}---a \term{symbol}
  1056. \label Description::
  1057. Makes the \param{symbol} be \term{unbound},
  1058. regardless of whether it was previously \term{bound}.
  1059. \label Examples::
  1060. \code
  1061. (setf (symbol-value 'a) 1)
  1062. (boundp 'a) \EV \term{true}
  1063. a \EV 1
  1064. (makunbound 'a) \EV A
  1065. (boundp 'a) \EV \term{false}
  1066. \endcode
  1067. \label Side Effects::
  1068. The \term{value cell} of \param{symbol} is modified.
  1069. \label Affected By:\None.
  1070. \label Exceptional Situations::
  1071. \Shouldchecktype{symbol}{a \term{symbol}}
  1072. \label See Also::
  1073. \funref{boundp}, \funref{fmakunbound}
  1074. \label Notes:\None.
  1075. \endcom
  1076. %%% ========== SET
  1077. \begincom{set}\ftype{Function}
  1078. \label Syntax::
  1079. \DefunWithValues set {symbol value} {value}
  1080. \label Arguments and Values::
  1081. \param{symbol}---a \term{symbol}.
  1082. %% 7.1.2 9
  1083. \issue{ARGUMENTS-UNDERSPECIFIED:SPECIFY}
  1084. \param{value}---an \term{object}.
  1085. \endissue{ARGUMENTS-UNDERSPECIFIED:SPECIFY}
  1086. \label Description::
  1087. %% 7.1.2 8
  1088. \funref{set} changes the contents of the \term{value cell} of \term{symbol}
  1089. to the given \term{value}.
  1090. \code
  1091. (set \param{symbol} \param{value}) \EQ (setf (symbol-value \param{symbol}) \param{value})
  1092. \endcode
  1093. \label Examples::
  1094. \code
  1095. (setf (symbol-value 'n) 1) \EV 1
  1096. (set 'n 2) \EV 2
  1097. (symbol-value 'n) \EV 2
  1098. (let ((n 3))
  1099. (declare (special n))
  1100. (setq n (+ n 1))
  1101. (setf (symbol-value 'n) (* n 10))
  1102. (set 'n (+ (symbol-value 'n) n))
  1103. n) \EV 80
  1104. n \EV 2
  1105. (let ((n 3))
  1106. (setq n (+ n 1))
  1107. (setf (symbol-value 'n) (* n 10))
  1108. (set 'n (+ (symbol-value 'n) n))
  1109. n) \EV 4
  1110. n \EV 44
  1111. (defvar *n* 2)
  1112. (let ((*n* 3))
  1113. (setq *n* (+ *n* 1))
  1114. (setf (symbol-value '*n*) (* *n* 10))
  1115. (set '*n* (+ (symbol-value '*n*) *n*))
  1116. *n*) \EV 80
  1117. *n* \EV 2
  1118. (defvar *even-count* 0) \EV *EVEN-COUNT*
  1119. (defvar *odd-count* 0) \EV *ODD-COUNT*
  1120. (defun tally-list (list)
  1121. (dolist (element list)
  1122. (set (if (evenp element) '*even-count* '*odd-count*)
  1123. (+ element (if (evenp element) *even-count* *odd-count*)))))
  1124. (tally-list '(1 9 4 3 2 7)) \EV NIL
  1125. *even-count* \EV 6
  1126. *odd-count* \EV 20
  1127. \endcode
  1128. \label Side Effects::
  1129. The \term{value} of \param{symbol} is changed.
  1130. \label Affected By:\None.
  1131. \label Exceptional Situations:\None.
  1132. \label See Also::
  1133. \specref{setq}, \specref{progv}, \funref{symbol-value}
  1134. \label Notes::
  1135. The function \funref{set} is deprecated.
  1136. %% 7.1.2 11
  1137. \funref{set} cannot change the value of a \term{lexical variable}.
  1138. \endcom
  1139. %-------------------- Symbol Errors --------------------
  1140. \begincom{unbound-variable}\ftype{Condition Type}
  1141. \label Class Precedence List::
  1142. \typeref{unbound-variable},
  1143. \typeref{cell-error},
  1144. \typeref{error},
  1145. \typeref{serious-condition},
  1146. \typeref{condition},
  1147. \typeref{t}
  1148. \label Description::
  1149. \Thetype{unbound-variable} consists of \term{error} \term{conditions}
  1150. that represent attempts to \term{read} the \term{value} of an \term{unbound variable}.
  1151. %Barrett: "name"?
  1152. %KMP: An "unbound variable" is by definition just a "name". See glossary.
  1153. The name of the cell (see \typeref{cell-error}) is the \term{name} of the
  1154. \term{variable} that was \term{unbound}.
  1155. \label See Also::
  1156. \funref{cell-error-name}
  1157. \endcom%{unbound-variable}\ftype{Condition Type}