My various dotfiles

chap-10.texi 40KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345
  1. @node Symbols, Packages, Conditions, Top
  2. @chapter Symbols
  3. @menu
  4. * Symbol Concepts::
  5. * Symbols Dictionary::
  6. @end menu
  7. @node Symbol Concepts, Symbols Dictionary, Symbols, Symbols
  8. @section Symbol Concepts
  9. @c including concept-symbols
  10. Figure 10--1 lists some
  11. @i{defined names} that are applicable to the @i{property lists} of @i{symbols}.
  12. @group
  13. @noindent
  14. @w{ get remprop symbol-plist }
  15. @noindent
  16. @w{ Figure 10--1: Property list defined names}
  17. @end group
  18. Figure 10--2 lists some @i{defined names} that are applicable
  19. to the creation of and inquiry about @i{symbols}.
  20. @group
  21. @noindent
  22. @w{ copy-symbol keywordp symbol-package }
  23. @w{ gensym make-symbol symbol-value }
  24. @w{ gentemp symbol-name }
  25. @noindent
  26. @w{ Figure 10--2: Symbol creation and inquiry defined names}
  27. @end group
  28. @c end of including concept-symbols
  29. @node Symbols Dictionary, , Symbol Concepts, Symbols
  30. @section Symbols Dictionary
  31. @c including dict-symbols
  32. @menu
  33. * symbol::
  34. * keyword::
  35. * symbolp::
  36. * keywordp::
  37. * make-symbol::
  38. * copy-symbol::
  39. * gensym::
  40. * *gensym-counter*::
  41. * gentemp::
  42. * symbol-function::
  43. * symbol-name::
  44. * symbol-package::
  45. * symbol-plist::
  46. * symbol-value::
  47. * get::
  48. * remprop::
  49. * boundp::
  50. * makunbound::
  51. * set::
  52. * unbound-variable::
  53. @end menu
  54. @node symbol, keyword, Symbols Dictionary, Symbols Dictionary
  55. @subsection symbol [System Class]
  56. @subsubheading Class Precedence List::
  57. @b{symbol},
  58. @b{t}
  59. @subsubheading Description::
  60. @i{Symbols} are used for their @i{object} identity to name various entities
  61. in @r{Common Lisp}, including (but not limited to) linguistic entities such as
  62. @i{variables} and @i{functions}.
  63. @i{Symbols} can be collected together into @i{packages}.
  64. A @i{symbol} is said to be @i{interned} in a @i{package}
  65. if it is @i{accessible} in that @i{package};
  66. the same @i{symbol} can be @i{interned} in more than one @i{package}.
  67. If a @i{symbol} is not @i{interned} in any @i{package},
  68. it is called @i{uninterned}.
  69. An @i{interned} @i{symbol} is uniquely identifiable by its @i{name} from
  70. any @i{package} in which it is @i{accessible}.
  71. @i{Symbols} have the following attributes. For historically reasons,
  72. these are sometimes referred to as @i{cells}, although the actual
  73. internal representation of @i{symbols} and their attributes is
  74. @i{implementation-dependent}.
  75. @table @asis
  76. @item @b{Name}
  77. The @i{name} of a @i{symbol} is a @i{string} used to identify the @i{symbol}.
  78. Every @i{symbol} has a @i{name},
  79. and the consequences are undefined if that @i{name} is altered.
  80. The @i{name} is used as part of the external, printed representation of
  81. the @i{symbol}; see @ref{Character Syntax}.
  82. The @i{function} @b{symbol-name} returns the @i{name} of a given @i{symbol}.
  83. A @i{symbol} may have any @i{character} in its @i{name}.
  84. @item @b{Package}
  85. The @i{object} in this @i{cell} is called the @i{home package}
  86. of the @i{symbol}. If the @i{home package} is @b{nil}, the @i{symbol}
  87. is sometimes said to have no @i{home package}.
  88. When a @i{symbol} is first created, it has no @i{home package}.
  89. When it is first @i{interned}, the @i{package} in which it is
  90. initially @i{interned} becomes its @i{home package}.
  91. The @i{home package} of a @i{symbol} can be @i{accessed}
  92. by using the @i{function} @b{symbol-package}.
  93. If a @i{symbol} is @i{uninterned} from the @i{package}
  94. which is its @i{home package}, its @i{home package} is set to @b{nil}.
  95. Depending on whether there is another @i{package} in which the @i{symbol}
  96. is @i{interned}, the symbol might or might not really be an @i{uninterned} @i{symbol}.
  97. A @i{symbol} with no @i{home package} is therefore called
  98. @i{apparently uninterned}.
  99. The consequences are undefined if an attempt is made to alter the @i{home package}
  100. of a @i{symbol}
  101. external
  102. in the @t{COMMON-LISP} @i{package} or the @t{KEYWORD} @i{package}.
  103. @item @b{Property list}
  104. The @i{property list} of a @i{symbol} provides a mechanism for
  105. associating named attributes with that @i{symbol}.
  106. The operations for adding and removing entries are @i{destructive}
  107. to the @i{property list}. @r{Common Lisp} provides @i{operators} both for
  108. direct manipulation of @i{property list} @i{objects}
  109. (@i{e.g.}, see @b{getf}, @b{remf}, and @b{symbol-plist})
  110. and for implicit manipulation of a @i{symbol}'s @i{property list}
  111. by reference to the @i{symbol}
  112. (@i{e.g.}, see @b{get} and @b{remprop}).
  113. The @i{property list} associated with a @i{fresh} @i{symbol} is
  114. initially @i{null}.
  115. @item @b{Value}
  116. If a symbol has a value attribute, it is said to be @i{bound},
  117. and that fact can be detected by the @i{function} @b{boundp}.
  118. The @i{object} contained in the @i{value cell} of a @i{bound} @i{symbol}
  119. is the @i{value} of the @i{global variable} named by that @i{symbol},
  120. and can be @i{accessed} by the @i{function} @b{symbol-value}.
  121. A @i{symbol} can be made to be @i{unbound} by the @i{function} @b{makunbound}.
  122. The consequences are undefined if an attempt is made to change the @i{value}
  123. of a @i{symbol} that names a @i{constant variable}, or to make such a
  124. @i{symbol} be @i{unbound}.
  125. @item @b{Function}
  126. If a symbol has a function attribute, it is said to be @i{fbound},
  127. and that fact can be detected by the @i{function} @b{fboundp}.
  128. If the @i{symbol} is the @i{name} of a @i{function} in the @i{global environment},
  129. the @i{function cell} contains the @i{function},
  130. and can be @i{accessed} by the @i{function} @b{symbol-function}.
  131. If the @i{symbol} is the @i{name} of either
  132. a @i{macro} in the @i{global environment} (see @b{macro-function})
  133. or a @i{special operator} (see @b{special-operator-p}),
  134. the @i{symbol} is @i{fbound},
  135. and can be @i{accessed} by the @i{function} @b{symbol-function},
  136. but the @i{object} which the @i{function cell}
  137. contains is of @i{implementation-dependent} @i{type} and purpose.
  138. A @i{symbol} can be made to be @i{funbound} by the @i{function} @b{fmakunbound}.
  139. The consequences are undefined if an attempt is made to change the @i{functional value}
  140. of a @i{symbol} that names a @i{special form}.
  141. @end table
  142. Operations on a @i{symbol}'s @i{value cell} and @i{function cell} are
  143. sometimes described in terms of their effect on the @i{symbol} itself, but
  144. the user should keep in mind that there is an intimate relationship between the
  145. contents of those @i{cells} and the @i{global variable} or
  146. global @i{function} definition, respectively.
  147. @i{Symbols} are used as identifiers for @i{lexical variables} and
  148. lexical @i{function} definitions, but in that role, only their @i{object}
  149. identity is significant. @r{Common Lisp} provides no operation on a @i{symbol} that
  150. can have any effect on a @i{lexical variable} or
  151. on a lexical @i{function} definition.
  152. @subsubheading See Also::
  153. @ref{Symbols as Tokens},
  154. @ref{Potential Numbers as Tokens},
  155. @ref{Printing Symbols}
  156. @node keyword, symbolp, symbol, Symbols Dictionary
  157. @subsection keyword [Type]
  158. @subsubheading Supertypes::
  159. @b{keyword},
  160. @b{symbol},
  161. @b{t}
  162. @subsubheading Description::
  163. The @i{type} @b{keyword} includes all @i{symbols} @i{interned} the @t{KEYWORD} @i{package}.
  164. @i{Interning} a @i{symbol} in the @t{KEYWORD} @i{package} has three automatic effects:
  165. @table @asis
  166. @item 1.
  167. It causes the @i{symbol} to become @i{bound} to itself.
  168. @item 2.
  169. It causes the @i{symbol} to become an @i{external symbol}
  170. of the @t{KEYWORD} @i{package}.
  171. @item 3.
  172. It causes the @i{symbol} to become a @i{constant variable}.
  173. @end table
  174. @subsubheading See Also::
  175. @ref{keywordp}
  176. @node symbolp, keywordp, keyword, Symbols Dictionary
  177. @subsection symbolp [Function]
  178. @code{symbolp} @i{object} @result{} @i{generalized-boolean}
  179. @subsubheading Arguments and Values::
  180. @i{object}---an @i{object}.
  181. @i{generalized-boolean}---a @i{generalized boolean}.
  182. @subsubheading Description::
  183. Returns @i{true} if @i{object} is of @i{type} @b{symbol};
  184. otherwise, returns @i{false}.
  185. @subsubheading Examples::
  186. @example
  187. (symbolp 'elephant) @result{} @i{true}
  188. (symbolp 12) @result{} @i{false}
  189. (symbolp nil) @result{} @i{true}
  190. (symbolp '()) @result{} @i{true}
  191. (symbolp :test) @result{} @i{true}
  192. (symbolp "hello") @result{} @i{false}
  193. @end example
  194. @subsubheading See Also::
  195. @ref{keywordp}
  196. ,
  197. @b{symbol},
  198. @ref{typep}
  199. @subsubheading Notes::
  200. @example
  201. (symbolp @i{object}) @equiv{} (typep @i{object} 'symbol)
  202. @end example
  203. @node keywordp, make-symbol, symbolp, Symbols Dictionary
  204. @subsection keywordp [Function]
  205. @code{keywordp} @i{object} @result{} @i{generalized-boolean}
  206. @subsubheading Arguments and Values::
  207. @i{object}---an @i{object}.
  208. @i{generalized-boolean}---a @i{generalized boolean}.
  209. @subsubheading Description::
  210. Returns @i{true} if @i{object} is a @i{keyword}_1;
  211. otherwise, returns @i{false}.
  212. @subsubheading Examples::
  213. @example
  214. (keywordp 'elephant) @result{} @i{false}
  215. (keywordp 12) @result{} @i{false}
  216. (keywordp :test) @result{} @i{true}
  217. (keywordp ':test) @result{} @i{true}
  218. (keywordp nil) @result{} @i{false}
  219. (keywordp :nil) @result{} @i{true}
  220. (keywordp '(:test)) @result{} @i{false}
  221. (keywordp "hello") @result{} @i{false}
  222. (keywordp ":hello") @result{} @i{false}
  223. (keywordp '&optional) @result{} @i{false}
  224. @end example
  225. @subsubheading See Also::
  226. @ref{constantp}
  227. ,
  228. @ref{keyword}
  229. ,
  230. @ref{symbolp}
  231. ,
  232. @ref{symbol-package}
  233. @node make-symbol, copy-symbol, keywordp, Symbols Dictionary
  234. @subsection make-symbol [Function]
  235. @code{make-symbol} @i{name} @result{} @i{new-symbol}
  236. @subsubheading Arguments and Values::
  237. @i{name}---a @i{string}.
  238. @i{new-symbol}---a @i{fresh}, @i{uninterned} @i{symbol}.
  239. @subsubheading Description::
  240. @b{make-symbol} creates and returns a @i{fresh}, @i{uninterned}
  241. @i{symbol} whose @i{name} is the given @i{name}.
  242. The @i{new-symbol} is neither @i{bound} nor @i{fbound}
  243. and has a @i{null} @i{property list}.
  244. It is @i{implementation-dependent} whether the @i{string}
  245. that becomes the @i{new-symbol}'s @i{name} is the given
  246. @i{name} or a copy of it. Once a @i{string}
  247. has been given as the @i{name} @i{argument} to
  248. @i{make-symbol}, the consequences are undefined if a
  249. subsequent attempt is made to alter that @i{string}.
  250. @subsubheading Examples::
  251. @example
  252. (setq temp-string "temp") @result{} "temp"
  253. (setq temp-symbol (make-symbol temp-string)) @result{} #:|temp|
  254. (symbol-name temp-symbol) @result{} "temp"
  255. (eq (symbol-name temp-symbol) temp-string) @result{} @i{implementation-dependent}
  256. (find-symbol "temp") @result{} NIL, NIL
  257. (eq (make-symbol temp-string) (make-symbol temp-string)) @result{} @i{false}
  258. @end example
  259. @subsubheading Exceptional Situations::
  260. Should signal an error of @i{type} @b{type-error}
  261. if @i{name} is not a @i{string}.
  262. @subsubheading See Also::
  263. @ref{copy-symbol}
  264. @subsubheading Notes::
  265. No attempt is made by @b{make-symbol} to convert the case
  266. of the @i{name} to uppercase. The only case conversion which ever
  267. occurs for @i{symbols} is done by the @i{Lisp reader}.
  268. The program interface to @i{symbol} creation retains case,
  269. and the program interface to interning symbols is case-sensitive.
  270. @node copy-symbol, gensym, make-symbol, Symbols Dictionary
  271. @subsection copy-symbol [Function]
  272. @code{copy-symbol} @i{symbol {&optional} copy-properties} @result{} @i{new-symbol}
  273. @subsubheading Arguments and Values::
  274. @i{symbol}---a @i{symbol}.
  275. @i{copy-properties}---a @i{generalized boolean}.
  276. The default is @i{false}.
  277. @i{new-symbol}---a @i{fresh}, @i{uninterned} @i{symbol}.
  278. @subsubheading Description::
  279. @b{copy-symbol} returns a @i{fresh}, @i{uninterned} @i{symbol},
  280. the @i{name} of which is @b{string=} to and possibly the @i{same} as
  281. the @i{name} of the given @i{symbol}.
  282. If @i{copy-properties} is @i{false},
  283. the @i{new-symbol} is neither @i{bound} nor @i{fbound}
  284. and has a @i{null} @i{property list}.
  285. If @i{copy-properties} is @i{true}, then
  286. the initial @i{value} of @i{new-symbol} is
  287. the @i{value} of @i{symbol},
  288. the initial @i{function} definition of @i{new-symbol} is
  289. the @i{functional value} of @i{symbol},
  290. and the @i{property list} of @i{new-symbol} is
  291. a @i{copy}_2 of the @i{property list} of @i{symbol}.
  292. @subsubheading Examples::
  293. @example
  294. (setq fred 'fred-smith) @result{} FRED-SMITH
  295. (setf (symbol-value fred) 3) @result{} 3
  296. (setq fred-clone-1a (copy-symbol fred nil)) @result{} #:FRED-SMITH
  297. (setq fred-clone-1b (copy-symbol fred nil)) @result{} #:FRED-SMITH
  298. (setq fred-clone-2a (copy-symbol fred t)) @result{} #:FRED-SMITH
  299. (setq fred-clone-2b (copy-symbol fred t)) @result{} #:FRED-SMITH
  300. (eq fred fred-clone-1a) @result{} @i{false}
  301. (eq fred-clone-1a fred-clone-1b) @result{} @i{false}
  302. (eq fred-clone-2a fred-clone-2b) @result{} @i{false}
  303. (eq fred-clone-1a fred-clone-2a) @result{} @i{false}
  304. (symbol-value fred) @result{} 3
  305. (boundp fred-clone-1a) @result{} @i{false}
  306. (symbol-value fred-clone-2a) @result{} 3
  307. (setf (symbol-value fred-clone-2a) 4) @result{} 4
  308. (symbol-value fred) @result{} 3
  309. (symbol-value fred-clone-2a) @result{} 4
  310. (symbol-value fred-clone-2b) @result{} 3
  311. (boundp fred-clone-1a) @result{} @i{false}
  312. (setf (symbol-function fred) #'(lambda (x) x)) @result{} #<FUNCTION anonymous>
  313. (fboundp fred) @result{} @i{true}
  314. (fboundp fred-clone-1a) @result{} @i{false}
  315. (fboundp fred-clone-2a) @result{} @i{false}
  316. @end example
  317. @subsubheading Exceptional Situations::
  318. Should signal an error of @i{type} @b{type-error}
  319. if @i{symbol} is not a @i{symbol}.
  320. @subsubheading See Also::
  321. @ref{make-symbol}
  322. @subsubheading Notes::
  323. Implementors are encouraged not to copy the @i{string}
  324. which is the @i{symbol}'s @i{name} unnecessarily.
  325. Unless there is a good reason to do so, the normal implementation
  326. strategy is for the @i{new-symbol}'s @i{name} to
  327. be @i{identical} to the given @i{symbol}'s @i{name}.
  328. @node gensym, *gensym-counter*, copy-symbol, Symbols Dictionary
  329. @subsection gensym [Function]
  330. @code{gensym} @i{{&optional} x} @result{} @i{new-symbol}
  331. @subsubheading Arguments and Values::
  332. @i{x}---a @i{string} or a non-negative @i{integer}.
  333. Complicated defaulting behavior; see below.
  334. @i{new-symbol}---a @i{fresh}, @i{uninterned} @i{symbol}.
  335. @subsubheading Description::
  336. Creates and returns a @i{fresh}, @i{uninterned} @i{symbol},
  337. as if by calling @b{make-symbol}. (The only difference between
  338. @b{gensym} and @b{make-symbol} is in how the @i{new-symbol}'s
  339. @i{name} is determined.)
  340. The @i{name} of the @i{new-symbol} is the concatenation
  341. of a prefix, which defaults to @t{"G"}, and
  342. a suffix, which is the decimal representation of a number that
  343. defaults to the @i{value} of @b{*gensym-counter*}.
  344. If @i{x} is supplied, and is a @i{string}, then that @i{string}
  345. is used as a prefix instead of @t{"G"} for this call to @b{gensym} only.
  346. If @i{x} is supplied, and is an @i{integer}, then that @i{integer},
  347. instead of the @i{value} of @b{*gensym-counter*}, is used as the suffix
  348. for this call to @b{gensym} only.
  349. If and only if no explicit suffix is supplied,
  350. @b{*gensym-counter*} is incremented after it is used.
  351. @subsubheading Examples::
  352. @example
  353. (setq sym1 (gensym)) @result{} #:G3142
  354. (symbol-package sym1) @result{} NIL
  355. (setq sym2 (gensym 100)) @result{} #:G100
  356. (setq sym3 (gensym 100)) @result{} #:G100
  357. (eq sym2 sym3) @result{} @i{false}
  358. (find-symbol "G100") @result{} NIL, NIL
  359. (gensym "T") @result{} #:T3143
  360. (gensym) @result{} #:G3144
  361. @end example
  362. @subsubheading Side Effects::
  363. Might increment @b{*gensym-counter*}.
  364. @subsubheading Affected By::
  365. @b{*gensym-counter*}
  366. @subsubheading Exceptional Situations::
  367. Should signal an error of @i{type} @b{type-error}
  368. if @i{x} is not a @i{string} or a non-negative @i{integer}.
  369. @subsubheading See Also::
  370. @ref{gentemp}
  371. ,
  372. @b{*gensym-counter*}
  373. @subsubheading Notes::
  374. The ability to pass a numeric argument to @b{gensym} has been deprecated;
  375. explicitly @i{binding} @b{*gensym-counter*} is now stylistically preferred.
  376. (The somewhat baroque conventions for the optional argument are historical
  377. in nature, and supported primarily for compatibility with older dialects
  378. of @r{Lisp}. In modern code, it is recommended that the only kind of argument
  379. used be a string prefix. In general, though, to obtain more flexible control
  380. of the @i{new-symbol}'s @i{name}, consider using @b{make-symbol} instead.)
  381. @node *gensym-counter*, gentemp, gensym, Symbols Dictionary
  382. @subsection *gensym-counter* [Variable]
  383. @subsubheading Value Type::
  384. a non-negative @i{integer}.
  385. @subsubheading Initial Value::
  386. @i{implementation-dependent}.
  387. @subsubheading Description::
  388. A number which will be used in constructing the @i{name} of
  389. the next @i{symbol} generated by the @i{function} @b{gensym}.
  390. @b{*gensym-counter*} can be either @i{assigned} or @i{bound}
  391. at any time, but its value must always be a non-negative @i{integer}.
  392. @subsubheading Affected By::
  393. @b{gensym}.
  394. @subsubheading See Also::
  395. @ref{gensym}
  396. @subsubheading Notes::
  397. The ability to pass a numeric argument to @b{gensym} has been deprecated;
  398. explicitly @i{binding} @b{*gensym-counter*} is now stylistically preferred.
  399. @node gentemp, symbol-function, *gensym-counter*, Symbols Dictionary
  400. @subsection gentemp [Function]
  401. @code{gentemp} @i{{&optional} prefix package} @result{} @i{new-symbol}
  402. @subsubheading Arguments and Values::
  403. @i{prefix}---a @i{string}.
  404. The default is @t{"T"}.
  405. @i{package}---a @i{package designator}.
  406. The default is the @i{current package}.
  407. @i{new-symbol}---a @i{fresh}, @i{interned} @i{symbol}.
  408. @subsubheading Description::
  409. @b{gentemp} creates and returns a @i{fresh} @i{symbol},
  410. @i{interned} in the indicated @i{package}.
  411. The @i{symbol} is guaranteed to be one that was not previously
  412. @i{accessible} in @i{package}.
  413. It is neither @i{bound} nor @i{fbound}, and has a @i{null}
  414. @i{property list}.
  415. The @i{name} of the @i{new-symbol} is the concatenation
  416. of the @i{prefix} and a suffix, which is taken from an internal
  417. counter used only by @b{gentemp}. (If a @i{symbol} by that name
  418. is already @i{accessible} in @i{package}, the counter is incremented as
  419. many times as is necessary to produce a @i{name} that is not already the
  420. @i{name} of a @i{symbol} @i{accessible} in @i{package}.)
  421. @subsubheading Examples::
  422. @example
  423. (gentemp) @result{} T1298
  424. (gentemp "FOO") @result{} FOO1299
  425. (find-symbol "FOO1300") @result{} NIL, NIL
  426. (gentemp "FOO") @result{} FOO1300
  427. (find-symbol "FOO1300") @result{} FOO1300, :INTERNAL
  428. (intern "FOO1301") @result{} FOO1301, :INTERNAL
  429. (gentemp "FOO") @result{} FOO1302
  430. (gentemp) @result{} T1303
  431. @end example
  432. @subsubheading Side Effects::
  433. Its internal counter is incremented one or more times.
  434. @i{Interns} the @i{new-symbol} in @i{package}.
  435. @subsubheading Affected By::
  436. The current state of its internal counter, and
  437. the current state of the @i{package}.
  438. @subsubheading Exceptional Situations::
  439. Should signal an error of @i{type} @b{type-error}
  440. if @i{prefix} is not a @i{string}.
  441. Should signal an error of @i{type} @b{type-error}
  442. if @i{package} is not a @i{package designator}.
  443. @subsubheading See Also::
  444. @ref{gensym}
  445. @subsubheading Notes::
  446. The function @b{gentemp} is deprecated.
  447. If @i{package} is the @t{KEYWORD} @i{package},
  448. the result is an @i{external symbol} of @i{package}.
  449. Otherwise, the result is an @i{internal symbol} of @i{package}.
  450. The @b{gentemp} internal counter is independent of
  451. @b{*gensym-counter*}, the counter used by @b{gensym}.
  452. There is no provision for accessing the @b{gentemp} internal counter.
  453. Just because @b{gentemp} creates a @i{symbol} which did not
  454. previously exist does not mean that such a @i{symbol} might not be
  455. seen in the future (@i{e.g.}, in a data file---perhaps even created by the
  456. same program in another session). As such, this symbol is not truly
  457. unique in the same sense as a @i{gensym} would be. In particular,
  458. programs which do automatic code generation should be careful not to
  459. attach global attributes to such generated @i{symbols} (@i{e.g.}, @b{special} @i{declarations}) and then write them into a file
  460. because such global attributes might, in a different session, end up
  461. applying to other @i{symbols} that were automatically generated on
  462. another day for some other purpose.
  463. @node symbol-function, symbol-name, gentemp, Symbols Dictionary
  464. @subsection symbol-function [Accessor]
  465. @code{symbol-function} @i{symbol} @result{} @i{contents}
  466. (setf (@code{ symbol-function} @i{symbol}) new-contents)@*
  467. @subsubheading Arguments and Values::
  468. @i{symbol}---a @i{symbol}.
  469. @i{contents}---
  470. If the @i{symbol} is globally defined as a @i{macro} or a @i{special operator},
  471. an @i{object} of @i{implementation-dependent} nature and identity is returned.
  472. If the @i{symbol} is not globally defined as
  473. either a @i{macro} or a @i{special operator},
  474. and
  475. if the @i{symbol} is @i{fbound},
  476. a @i{function} @i{object} is returned.
  477. @i{new-contents}---a @i{function}.
  478. @subsubheading Description::
  479. @i{Accesses} the @i{symbol}'s @i{function cell}.
  480. @subsubheading Examples::
  481. @example
  482. (symbol-function 'car) @result{} #<FUNCTION CAR>
  483. (symbol-function 'twice) is an error ;because TWICE isn't defined.
  484. (defun twice (n) (* n 2)) @result{} TWICE
  485. (symbol-function 'twice) @result{} #<FUNCTION TWICE>
  486. (list (twice 3)
  487. (funcall (function twice) 3)
  488. (funcall (symbol-function 'twice) 3))
  489. @result{} (6 6 6)
  490. (flet ((twice (x) (list x x)))
  491. (list (twice 3)
  492. (funcall (function twice) 3)
  493. (funcall (symbol-function 'twice) 3)))
  494. @result{} ((3 3) (3 3) 6)
  495. (setf (symbol-function 'twice) #'(lambda (x) (list x x)))
  496. @result{} #<FUNCTION anonymous>
  497. (list (twice 3)
  498. (funcall (function twice) 3)
  499. (funcall (symbol-function 'twice) 3))
  500. @result{} ((3 3) (3 3) (3 3))
  501. (fboundp 'defun) @result{} @i{true}
  502. (symbol-function 'defun)
  503. @result{} @i{implementation-dependent}
  504. (functionp (symbol-function 'defun))
  505. @result{} @i{implementation-dependent}
  506. (defun symbol-function-or-nil (symbol)
  507. (if (and (fboundp symbol)
  508. (not (macro-function symbol))
  509. (not (special-operator-p symbol)))
  510. (symbol-function symbol)
  511. nil)) @result{} SYMBOL-FUNCTION-OR-NIL
  512. (symbol-function-or-nil 'car) @result{} #<FUNCTION CAR>
  513. (symbol-function-or-nil 'defun) @result{} NIL
  514. @end example
  515. @subsubheading Affected By::
  516. @b{defun}
  517. @subsubheading Exceptional Situations::
  518. Should signal an error of @i{type} @b{type-error}
  519. if @i{symbol} is not a @i{symbol}.
  520. Should signal @b{undefined-function} if @i{symbol} is not @i{fbound}
  521. and an attempt is made to @i{read} its definition. (No such error is signaled
  522. on an attempt to @i{write} its definition.)
  523. @subsubheading See Also::
  524. @ref{fboundp}
  525. ,
  526. @ref{fmakunbound}
  527. ,
  528. @ref{macro-function}
  529. ,
  530. @ref{special-operator-p}
  531. @subsubheading Notes::
  532. @b{symbol-function} cannot @i{access} the value of a lexical function name
  533. produced by @b{flet} or @b{labels}; it can @i{access} only
  534. the global function value.
  535. @b{setf} may be used with
  536. @b{symbol-function} to replace a global function
  537. definition when the @i{symbol}'s function definition
  538. does not represent a @i{special operator}.
  539. @example
  540. (symbol-function @i{symbol}) @equiv{} (fdefinition @i{symbol})
  541. @end example
  542. However, @b{fdefinition} accepts arguments other than just @i{symbols}.
  543. @node symbol-name, symbol-package, symbol-function, Symbols Dictionary
  544. @subsection symbol-name [Function]
  545. @code{symbol-name} @i{symbol} @result{} @i{name}
  546. @subsubheading Arguments and Values::
  547. @i{symbol}---a @i{symbol}.
  548. @i{name}---a @i{string}.
  549. @subsubheading Description::
  550. @b{symbol-name} returns the @i{name} of @i{symbol}.
  551. The consequences are undefined if @i{name} is ever modified.
  552. @subsubheading Examples::
  553. @example
  554. (symbol-name 'temp) @result{} "TEMP"
  555. (symbol-name :start) @result{} "START"
  556. (symbol-name (gensym)) @result{} "G1234" ;for example
  557. @end example
  558. @subsubheading Exceptional Situations::
  559. Should signal an error of @i{type} @b{type-error}
  560. if @i{symbol} is not a @i{symbol}.
  561. @node symbol-package, symbol-plist, symbol-name, Symbols Dictionary
  562. @subsection symbol-package [Function]
  563. @code{symbol-package} @i{symbol} @result{} @i{contents}
  564. @subsubheading Arguments and Values::
  565. @i{symbol}---a @i{symbol}.
  566. @i{contents}---a @i{package} @i{object} or @b{nil}.
  567. @subsubheading Description::
  568. Returns the @i{home package} of @i{symbol}.
  569. @subsubheading Examples::
  570. @example
  571. (in-package "CL-USER") @result{} #<PACKAGE "COMMON-LISP-USER">
  572. (symbol-package 'car) @result{} #<PACKAGE "COMMON-LISP">
  573. (symbol-package 'bus) @result{} #<PACKAGE "COMMON-LISP-USER">
  574. (symbol-package :optional) @result{} #<PACKAGE "KEYWORD">
  575. ;; Gensyms are uninterned, so have no home package.
  576. (symbol-package (gensym)) @result{} NIL
  577. (make-package 'pk1) @result{} #<PACKAGE "PK1">
  578. (intern "SAMPLE1" "PK1") @result{} PK1::SAMPLE1, NIL
  579. (export (find-symbol "SAMPLE1" "PK1") "PK1") @result{} T
  580. (make-package 'pk2 :use '(pk1)) @result{} #<PACKAGE "PK2">
  581. (find-symbol "SAMPLE1" "PK2") @result{} PK1:SAMPLE1, :INHERITED
  582. (symbol-package 'pk1::sample1) @result{} #<PACKAGE "PK1">
  583. (symbol-package 'pk2::sample1) @result{} #<PACKAGE "PK1">
  584. (symbol-package 'pk1::sample2) @result{} #<PACKAGE "PK1">
  585. (symbol-package 'pk2::sample2) @result{} #<PACKAGE "PK2">
  586. ;; The next several forms create a scenario in which a symbol
  587. ;; is not really uninterned, but is "apparently uninterned",
  588. ;; and so SYMBOL-PACKAGE still returns NIL.
  589. (setq s3 'pk1::sample3) @result{} PK1::SAMPLE3
  590. (import s3 'pk2) @result{} T
  591. (unintern s3 'pk1) @result{} T
  592. (symbol-package s3) @result{} NIL
  593. (eq s3 'pk2::sample3) @result{} T
  594. @end example
  595. @subsubheading Affected By::
  596. @b{import},
  597. @b{intern},
  598. @b{unintern}
  599. @subsubheading Exceptional Situations::
  600. Should signal an error of @i{type} @b{type-error}
  601. if @i{symbol} is not a @i{symbol}.
  602. @subsubheading See Also::
  603. @ref{intern}
  604. @node symbol-plist, symbol-value, symbol-package, Symbols Dictionary
  605. @subsection symbol-plist [Accessor]
  606. @code{symbol-plist} @i{symbol} @result{} @i{plist}
  607. (setf (@code{ symbol-plist} @i{symbol}) new-plist)@*
  608. @subsubheading Arguments and Values::
  609. @i{symbol}---a @i{symbol}.
  610. @i{plist}, @i{new-plist}---a @i{property list}.
  611. @subsubheading Description::
  612. @i{Accesses} the @i{property list} of @i{symbol}.
  613. @subsubheading Examples::
  614. @example
  615. (setq sym (gensym)) @result{} #:G9723
  616. (symbol-plist sym) @result{} ()
  617. (setf (get sym 'prop1) 'val1) @result{} VAL1
  618. (symbol-plist sym) @result{} (PROP1 VAL1)
  619. (setf (get sym 'prop2) 'val2) @result{} VAL2
  620. (symbol-plist sym) @result{} (PROP2 VAL2 PROP1 VAL1)
  621. (setf (symbol-plist sym) (list 'prop3 'val3)) @result{} (PROP3 VAL3)
  622. (symbol-plist sym) @result{} (PROP3 VAL3)
  623. @end example
  624. @subsubheading Exceptional Situations::
  625. Should signal an error of @i{type} @b{type-error}
  626. if @i{symbol} is not a @i{symbol}.
  627. @subsubheading See Also::
  628. @ref{get}
  629. ,
  630. @ref{remprop}
  631. @subsubheading Notes::
  632. The use of @b{setf} should be avoided, since a @i{symbol}'s
  633. @i{property list} is a global resource that can contain information
  634. established and depended upon by unrelated programs in the same @i{Lisp image}.
  635. @node symbol-value, get, symbol-plist, Symbols Dictionary
  636. @subsection symbol-value [Accessor]
  637. @code{symbol-value} @i{symbol} @result{} @i{value}
  638. (setf (@code{ symbol-value} @i{symbol}) new-value)@*
  639. @subsubheading Arguments and Values::
  640. @i{symbol}---a @i{symbol} that must have a @i{value}.
  641. @i{value}, @i{new-value}---an @i{object}.
  642. @subsubheading Description::
  643. @i{Accesses} the @i{symbol}'s @i{value cell}.
  644. @subsubheading Examples::
  645. @example
  646. (setf (symbol-value 'a) 1) @result{} 1
  647. (symbol-value 'a) @result{} 1
  648. ;; SYMBOL-VALUE cannot see lexical variables.
  649. (let ((a 2)) (symbol-value 'a)) @result{} 1
  650. (let ((a 2)) (setq a 3) (symbol-value 'a)) @result{} 1
  651. ;; SYMBOL-VALUE can see dynamic variables.
  652. (let ((a 2))
  653. (declare (special a))
  654. (symbol-value 'a)) @result{} 2
  655. (let ((a 2))
  656. (declare (special a))
  657. (setq a 3)
  658. (symbol-value 'a)) @result{} 3
  659. (let ((a 2))
  660. (setf (symbol-value 'a) 3)
  661. a) @result{} 2
  662. a @result{} 3
  663. (symbol-value 'a) @result{} 3
  664. (let ((a 4))
  665. (declare (special a))
  666. (let ((b (symbol-value 'a)))
  667. (setf (symbol-value 'a) 5)
  668. (values a b))) @result{} 5, 4
  669. a @result{} 3
  670. (symbol-value :any-keyword) @result{} :ANY-KEYWORD
  671. (symbol-value 'nil) @result{} NIL
  672. (symbol-value '()) @result{} NIL
  673. ;; The precision of this next one is @i{implementation-dependent}.
  674. (symbol-value 'pi) @result{} 3.141592653589793d0
  675. @end example
  676. @subsubheading Affected By::
  677. @b{makunbound},
  678. @b{set},
  679. @b{setq}
  680. @subsubheading Exceptional Situations::
  681. Should signal an error of @i{type} @b{type-error}
  682. if @i{symbol} is not a @i{symbol}.
  683. Should signal @b{unbound-variable} if @i{symbol} is @i{unbound}
  684. and an attempt is made to @i{read} its @i{value}. (No such error is signaled
  685. on an attempt to @i{write} its @i{value}.)
  686. @subsubheading See Also::
  687. @ref{boundp}
  688. ,
  689. @ref{makunbound}
  690. ,
  691. @ref{set}
  692. ,
  693. @ref{setq}
  694. @subsubheading Notes::
  695. @b{symbol-value} can be used to get the value of a @i{constant variable}.
  696. @b{symbol-value} cannot @i{access} the value of a @i{lexical variable}.
  697. @node get, remprop, symbol-value, Symbols Dictionary
  698. @subsection get [Accessor]
  699. @code{get} @i{symbol indicator {&optional} default} @result{} @i{value}
  700. (setf (@code{ get} @i{symbol indicator {&optional} default}) new-value)@*
  701. @subsubheading Arguments and Values::
  702. @i{symbol}---a @i{symbol}.
  703. @i{indicator}---an @i{object}.
  704. @i{default}---an @i{object}.
  705. The default is @b{nil}.
  706. @i{value}---if the indicated property exists,
  707. the @i{object} that is its @i{value};
  708. otherwise, the specified @i{default}.
  709. @i{new-value}---an @i{object}.
  710. @subsubheading Description::
  711. @b{get} finds a @i{property}
  712. on the @i{property list}_2 of @i{symbol}
  713. whose @i{property indicator} is @i{identical} to @i{indicator},
  714. and returns its corresponding @i{property value}.
  715. If there are multiple @i{properties}_1 with that @i{property indicator},
  716. @b{get} uses the first such @i{property}.
  717. If there is no @i{property} with that @i{property indicator},
  718. @i{default} is returned.
  719. @b{setf} of @b{get} may be used to associate a new @i{object}
  720. with an existing indicator already on the @i{symbol}'s @i{property list},
  721. or to create a new assocation if none exists.
  722. If there are multiple @i{properties}_1 with that @i{property indicator},
  723. @b{setf} of @b{get} associates the @i{new-value}
  724. with the first such @i{property}.
  725. When a @b{get} @i{form} is used as a @b{setf} @i{place},
  726. any @i{default} which is supplied is evaluated according to normal
  727. left-to-right evaluation rules, but its @i{value} is ignored.
  728. @subsubheading Examples::
  729. @example
  730. (defun make-person (first-name last-name)
  731. (let ((person (gensym "PERSON")))
  732. (setf (get person 'first-name) first-name)
  733. (setf (get person 'last-name) last-name)
  734. person)) @result{} MAKE-PERSON
  735. (defvar *john* (make-person "John" "Dow")) @result{} *JOHN*
  736. *john* @result{} #:PERSON4603
  737. (defvar *sally* (make-person "Sally" "Jones")) @result{} *SALLY*
  738. (get *john* 'first-name) @result{} "John"
  739. (get *sally* 'last-name) @result{} "Jones"
  740. (defun marry (man woman married-name)
  741. (setf (get man 'wife) woman)
  742. (setf (get woman 'husband) man)
  743. (setf (get man 'last-name) married-name)
  744. (setf (get woman 'last-name) married-name)
  745. married-name) @result{} MARRY
  746. (marry *john* *sally* "Dow-Jones") @result{} "Dow-Jones"
  747. (get *john* 'last-name) @result{} "Dow-Jones"
  748. (get (get *john* 'wife) 'first-name) @result{} "Sally"
  749. (symbol-plist *john*)
  750. @result{} (WIFE #:PERSON4604 LAST-NAME "Dow-Jones" FIRST-NAME "John")
  751. (defmacro age (person &optional (default ''thirty-something))
  752. `(get ,person 'age ,default)) @result{} AGE
  753. (age *john*) @result{} THIRTY-SOMETHING
  754. (age *john* 20) @result{} 20
  755. (setf (age *john*) 25) @result{} 25
  756. (age *john*) @result{} 25
  757. (age *john* 20) @result{} 25
  758. @end example
  759. @subsubheading Exceptional Situations::
  760. Should signal an error of @i{type} @b{type-error}
  761. if @i{symbol} is not a @i{symbol}.
  762. @subsubheading See Also::
  763. @ref{getf}
  764. ,
  765. @ref{symbol-plist}
  766. ,
  767. @ref{remprop}
  768. @subsubheading Notes::
  769. @example
  770. (get x y) @equiv{} (getf (symbol-plist x) y)
  771. @end example
  772. @i{Numbers} and @i{characters} are not recommended for use
  773. as @i{indicators} in portable code since @b{get} tests
  774. with @b{eq} rather than @b{eql}, and consequently
  775. the effect of using such @i{indicators} is
  776. @i{implementation-dependent}.
  777. There is no way using @b{get} to distinguish an absent property from
  778. one whose value is @i{default}. However, see @b{get-properties}.
  779. @node remprop, boundp, get, Symbols Dictionary
  780. @subsection remprop [Function]
  781. @code{remprop} @i{symbol indicator} @result{} @i{generalized-boolean}
  782. @subsubheading Arguments and Values::
  783. @i{symbol}---a @i{symbol}.
  784. @i{indicator}---an @i{object}.
  785. @i{generalized-boolean}---a @i{generalized boolean}.
  786. @subsubheading Description::
  787. @b{remprop} removes from the @i{property list}_2 of @i{symbol}
  788. a @i{property}_1 with a @i{property indicator}
  789. @i{identical} to @i{indicator}.
  790. If there are multiple @i{properties}_1 with the @i{identical} key,
  791. @b{remprop} only removes the first such @i{property}.
  792. @b{remprop} returns @i{false} if no such @i{property} was found,
  793. or @i{true} if a property was found.
  794. The @i{property indicator}
  795. and the corresponding @i{property value}
  796. are removed in an undefined order
  797. by destructively splicing the property list.
  798. The permissible side-effects correspond to those permitted for @b{remf},
  799. such that:
  800. @example
  801. (remprop @i{x} @i{y}) @equiv{} (remf (symbol-plist @i{x}) @i{y})
  802. @end example
  803. @subsubheading Examples::
  804. @example
  805. (setq test (make-symbol "PSEUDO-PI")) @result{} #:PSEUDO-PI
  806. (symbol-plist test) @result{} ()
  807. (setf (get test 'constant) t) @result{} T
  808. (setf (get test 'approximation) 3.14) @result{} 3.14
  809. (setf (get test 'error-range) 'noticeable) @result{} NOTICEABLE
  810. (symbol-plist test)
  811. @result{} (ERROR-RANGE NOTICEABLE APPROXIMATION 3.14 CONSTANT T)
  812. (setf (get test 'approximation) nil) @result{} NIL
  813. (symbol-plist test)
  814. @result{} (ERROR-RANGE NOTICEABLE APPROXIMATION NIL CONSTANT T)
  815. (get test 'approximation) @result{} NIL
  816. (remprop test 'approximation) @result{} @i{true}
  817. (get test 'approximation) @result{} NIL
  818. (symbol-plist test)
  819. @result{} (ERROR-RANGE NOTICEABLE CONSTANT T)
  820. (remprop test 'approximation) @result{} NIL
  821. (symbol-plist test)
  822. @result{} (ERROR-RANGE NOTICEABLE CONSTANT T)
  823. (remprop test 'error-range) @result{} @i{true}
  824. (setf (get test 'approximation) 3) @result{} 3
  825. (symbol-plist test)
  826. @result{} (APPROXIMATION 3 CONSTANT T)
  827. @end example
  828. @subsubheading Side Effects::
  829. The @i{property list} of @i{symbol} is modified.
  830. @subsubheading Exceptional Situations::
  831. Should signal an error of @i{type} @b{type-error}
  832. if @i{symbol} is not a @i{symbol}.
  833. @subsubheading See Also::
  834. @ref{remf}
  835. ,
  836. @ref{symbol-plist}
  837. @subsubheading Notes::
  838. @i{Numbers} and @i{characters} are not recommended for use as
  839. @i{indicators} in portable code since @b{remprop} tests with
  840. @b{eq} rather than @b{eql}, and consequently the effect of
  841. using such @i{indicators} is @i{implementation-dependent}.
  842. Of course, if you've gotten as far as needing to remove such a
  843. @i{property}, you don't have much choice---the time to have been
  844. thinking about this was when you used @b{setf} of @b{get} to
  845. establish the @i{property}.
  846. @node boundp, makunbound, remprop, Symbols Dictionary
  847. @subsection boundp [Function]
  848. @code{boundp} @i{symbol} @result{} @i{generalized-boolean}
  849. @subsubheading Arguments and Values::
  850. @i{symbol}---a @i{symbol}.
  851. @i{generalized-boolean}---a @i{generalized boolean}.
  852. @subsubheading Description::
  853. Returns @i{true} if @i{symbol} is @i{bound};
  854. otherwise, returns @i{false}.
  855. @subsubheading Examples::
  856. @example
  857. (setq x 1) @result{} 1
  858. (boundp 'x) @result{} @i{true}
  859. (makunbound 'x) @result{} X
  860. (boundp 'x) @result{} @i{false}
  861. (let ((x 2)) (boundp 'x)) @result{} @i{false}
  862. (let ((x 2)) (declare (special x)) (boundp 'x)) @result{} @i{true}
  863. @end example
  864. @subsubheading Exceptional Situations::
  865. Should signal an error of @i{type} @b{type-error}
  866. if @i{symbol} is not a @i{symbol}.
  867. @subsubheading See Also::
  868. @ref{set}
  869. ,
  870. @ref{setq}
  871. ,
  872. @ref{symbol-value}
  873. ,
  874. @ref{makunbound}
  875. @subsubheading Notes::
  876. The @i{function} @b{bound} determines only whether a @i{symbol} has a
  877. value in the @i{global environment}; any @i{lexical bindings}
  878. are ignored.
  879. @node makunbound, set, boundp, Symbols Dictionary
  880. @subsection makunbound [Function]
  881. @code{makunbound} @i{symbol} @result{} @i{symbol}
  882. @subsubheading Arguments and Values::
  883. @i{symbol}---a @i{symbol}
  884. @subsubheading Description::
  885. Makes the @i{symbol} be @i{unbound},
  886. regardless of whether it was previously @i{bound}.
  887. @subsubheading Examples::
  888. @example
  889. (setf (symbol-value 'a) 1)
  890. (boundp 'a) @result{} @i{true}
  891. a @result{} 1
  892. (makunbound 'a) @result{} A
  893. (boundp 'a) @result{} @i{false}
  894. @end example
  895. @subsubheading Side Effects::
  896. The @i{value cell} of @i{symbol} is modified.
  897. @subsubheading Exceptional Situations::
  898. Should signal an error of @i{type} @b{type-error}
  899. if @i{symbol} is not a @i{symbol}.
  900. @subsubheading See Also::
  901. @ref{boundp}
  902. ,
  903. @ref{fmakunbound}
  904. @node set, unbound-variable, makunbound, Symbols Dictionary
  905. @subsection set [Function]
  906. @code{set} @i{symbol value} @result{} @i{value}
  907. @subsubheading Arguments and Values::
  908. @i{symbol}---a @i{symbol}.
  909. @i{value}---an @i{object}.
  910. @subsubheading Description::
  911. @b{set} changes the contents of the @i{value cell} of @i{symbol}
  912. to the given @i{value}.
  913. @example
  914. (set @i{symbol} @i{value}) @equiv{} (setf (symbol-value @i{symbol}) @i{value})
  915. @end example
  916. @subsubheading Examples::
  917. @example
  918. (setf (symbol-value 'n) 1) @result{} 1
  919. (set 'n 2) @result{} 2
  920. (symbol-value 'n) @result{} 2
  921. (let ((n 3))
  922. (declare (special n))
  923. (setq n (+ n 1))
  924. (setf (symbol-value 'n) (* n 10))
  925. (set 'n (+ (symbol-value 'n) n))
  926. n) @result{} 80
  927. n @result{} 2
  928. (let ((n 3))
  929. (setq n (+ n 1))
  930. (setf (symbol-value 'n) (* n 10))
  931. (set 'n (+ (symbol-value 'n) n))
  932. n) @result{} 4
  933. n @result{} 44
  934. (defvar *n* 2)
  935. (let ((*n* 3))
  936. (setq *n* (+ *n* 1))
  937. (setf (symbol-value '*n*) (* *n* 10))
  938. (set '*n* (+ (symbol-value '*n*) *n*))
  939. *n*) @result{} 80
  940. *n* @result{} 2
  941. (defvar *even-count* 0) @result{} *EVEN-COUNT*
  942. (defvar *odd-count* 0) @result{} *ODD-COUNT*
  943. (defun tally-list (list)
  944. (dolist (element list)
  945. (set (if (evenp element) '*even-count* '*odd-count*)
  946. (+ element (if (evenp element) *even-count* *odd-count*)))))
  947. (tally-list '(1 9 4 3 2 7)) @result{} NIL
  948. *even-count* @result{} 6
  949. *odd-count* @result{} 20
  950. @end example
  951. @subsubheading Side Effects::
  952. The @i{value} of @i{symbol} is changed.
  953. @subsubheading See Also::
  954. @ref{setq}
  955. ,
  956. @ref{progv}
  957. ,
  958. @ref{symbol-value}
  959. @subsubheading Notes::
  960. The function @b{set} is deprecated.
  961. @b{set} cannot change the value of a @i{lexical variable}.
  962. @node unbound-variable, , set, Symbols Dictionary
  963. @subsection unbound-variable [Condition Type]
  964. @subsubheading Class Precedence List::
  965. @b{unbound-variable},
  966. @b{cell-error},
  967. @b{error},
  968. @b{serious-condition},
  969. @b{condition},
  970. @b{t}
  971. @subsubheading Description::
  972. The @i{type} @b{unbound-variable} consists of @i{error} @i{conditions}
  973. that represent attempts to @i{read} the @i{value} of an @i{unbound variable}.
  974. The name of the cell (see @b{cell-error}) is the @i{name} of the
  975. @i{variable} that was @i{unbound}.
  976. @subsubheading See Also::
  977. @ref{cell-error-name}
  978. @c end of including dict-symbols
  979. @c %**end of chapter