1 This is ../info/lispref.info, produced by makeinfo version 4.0 from
4 INFO-DIR-SECTION XEmacs Editor
6 * Lispref: (lispref). XEmacs Lisp Reference Manual.
11 GNU Emacs Lisp Reference Manual Second Edition (v2.01), May 1993 GNU
12 Emacs Lisp Reference Manual Further Revised (v2.02), August 1993 Lucid
13 Emacs Lisp Reference Manual (for 19.10) First Edition, March 1994
14 XEmacs Lisp Programmer's Manual (for 19.12) Second Edition, April 1995
15 GNU Emacs Lisp Reference Manual v2.4, June 1995 XEmacs Lisp
16 Programmer's Manual (for 19.13) Third Edition, July 1995 XEmacs Lisp
17 Reference Manual (for 19.14 and 20.0) v3.1, March 1996 XEmacs Lisp
18 Reference Manual (for 19.15 and 20.1, 20.2, 20.3) v3.2, April, May,
19 November 1997 XEmacs Lisp Reference Manual (for 21.0) v3.3, April 1998
21 Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995 Free Software
22 Foundation, Inc. Copyright (C) 1994, 1995 Sun Microsystems, Inc.
23 Copyright (C) 1995, 1996 Ben Wing.
25 Permission is granted to make and distribute verbatim copies of this
26 manual provided the copyright notice and this permission notice are
27 preserved on all copies.
29 Permission is granted to copy and distribute modified versions of
30 this manual under the conditions for verbatim copying, provided that the
31 entire resulting derived work is distributed under the terms of a
32 permission notice identical to this one.
34 Permission is granted to copy and distribute translations of this
35 manual into another language, under the above conditions for modified
36 versions, except that this permission notice may be stated in a
37 translation approved by the Foundation.
39 Permission is granted to copy and distribute modified versions of
40 this manual under the conditions for verbatim copying, provided also
41 that the section entitled "GNU General Public License" is included
42 exactly as in the original, and provided that the entire resulting
43 derived work is distributed under the terms of a permission notice
44 identical to this one.
46 Permission is granted to copy and distribute translations of this
47 manual into another language, under the above conditions for modified
48 versions, except that the section entitled "GNU General Public License"
49 may be included in a translation approved by the Free Software
50 Foundation instead of in the original English.
53 File: lispref.info, Node: Sequence Functions, Next: Arrays, Up: Sequences Arrays Vectors
58 In XEmacs Lisp, a "sequence" is either a list, a vector, a bit
59 vector, or a string. The common property that all sequences have is
60 that each is an ordered collection of elements. This section describes
61 functions that accept any kind of sequence.
63 - Function: sequencep object
64 Returns `t' if OBJECT is a list, vector, bit vector, or string,
67 - Function: copy-sequence sequence
68 Returns a copy of SEQUENCE. The copy is the same type of object
69 as the original sequence, and it has the same elements in the same
72 Storing a new element into the copy does not affect the original
73 SEQUENCE, and vice versa. However, the elements of the new
74 sequence are not copies; they are identical (`eq') to the elements
75 of the original. Therefore, changes made within these elements, as
76 found via the copied sequence, are also visible in the original
79 If the sequence is a string with extents or text properties, the
80 extents and text properties in the copy are also copied, not
81 shared with the original. (This means that modifying the extents
82 or text properties of the original will not affect the copy.)
83 However, the actual values of the properties are shared. *Note
84 Extents::, *Note Text Properties::.
86 See also `append' in *Note Building Lists::, `concat' in *Note
87 Creating Strings::, `vconcat' in *Note Vectors::, and `bvconcat'
88 in *Note Bit Vectors::, for other ways to copy sequences.
92 (setq x (vector 'foo bar))
94 (setq y (copy-sequence x))
101 (eq (elt x 1) (elt y 1))
104 ;; Replacing an element of one sequence.
109 ;; Modifying the inside of a shared element.
110 (setcar (aref x 1) 69)
114 ;; Creating a bit vector.
115 (bit-vector 1 0 1 1 0 1 0 0)
118 - Function: length sequence
119 Returns the number of elements in SEQUENCE. If SEQUENCE is a cons
120 cell that is not a list (because the final CDR is not `nil'), a
121 `wrong-type-argument' error is signaled.
134 - Function: elt sequence index
135 This function returns the element of SEQUENCE indexed by INDEX.
136 Legitimate values of INDEX are integers ranging from 0 up to one
137 less than the length of SEQUENCE. If SEQUENCE is a list, then
138 out-of-range values of INDEX return `nil'; otherwise, they trigger
139 an `args-out-of-range' error.
145 (char-to-string (elt "1234" 2))
150 error-->Args out of range: [1 2 3 4], 4
152 error-->Args out of range: [1 2 3 4], -1
154 This function generalizes `aref' (*note Array Functions::) and
155 `nth' (*note List Elements::).
158 File: lispref.info, Node: Arrays, Next: Array Functions, Prev: Sequence Functions, Up: Sequences Arrays Vectors
163 An "array" object has slots that hold a number of other Lisp
164 objects, called the elements of the array. Any element of an array may
165 be accessed in constant time. In contrast, an element of a list
166 requires access time that is proportional to the position of the element
169 When you create an array, you must specify how many elements it has.
170 The amount of space allocated depends on the number of elements.
171 Therefore, it is impossible to change the size of an array once it is
172 created; you cannot add or remove elements. However, you can replace an
173 element with a different value.
175 XEmacs defines three types of array, all of which are
176 one-dimensional: "strings", "vectors", and "bit vectors". A vector is a
177 general array; its elements can be any Lisp objects. A string is a
178 specialized array; its elements must be characters. A bit vector is
179 another specialized array; its elements must be bits (an integer, either
180 0 or 1). Each type of array has its own read syntax. *Note String
181 Type::, *Note Vector Type::, and *Note Bit Vector Type::.
183 All kinds of array share these characteristics:
185 * The first element of an array has index zero, the second element
186 has index 1, and so on. This is called "zero-origin" indexing.
187 For example, an array of four elements has indices 0, 1, 2, and 3.
189 * The elements of an array may be referenced or changed with the
190 functions `aref' and `aset', respectively (*note Array
193 In principle, if you wish to have an array of text characters, you
194 could use either a string or a vector. In practice, we always choose
195 strings for such applications, for four reasons:
197 * They usually occupy one-fourth the space of a vector of the same
198 elements. (This is one-eighth the space for 64-bit machines such
199 as the DEC Alpha, and may also be different when MULE support is
200 compiled into XEmacs.)
202 * Strings are printed in a way that shows the contents more clearly
205 * Strings can hold extent and text properties. *Note Extents::,
206 *Note Text Properties::.
208 * Many of the specialized editing and I/O facilities of XEmacs
209 accept only strings. For example, you cannot insert a vector of
210 characters into a buffer the way you can insert a string. *Note
211 Strings and Characters::.
213 By contrast, for an array of keyboard input characters (such as a key
214 sequence), a vector may be necessary, because many keyboard input
215 characters are non-printable and are represented with symbols rather
216 than with characters. *Note Key Sequence Input::.
218 Similarly, when representing an array of bits, a bit vector has the
219 following advantages over a regular vector:
221 * They occupy 1/32nd the space of a vector of the same elements.
222 (1/64th on 64-bit machines such as the DEC Alpha.)
224 * Bit vectors are printed in a way that shows the contents more
228 File: lispref.info, Node: Array Functions, Next: Vectors, Prev: Arrays, Up: Sequences Arrays Vectors
230 Functions that Operate on Arrays
231 ================================
233 In this section, we describe the functions that accept strings,
234 vectors, and bit vectors.
236 - Function: arrayp object
237 This function returns `t' if OBJECT is an array (i.e., a string,
238 vector, or bit vector).
247 - Function: aref array index
248 This function returns the INDEXth element of ARRAY. The first
249 element is at index zero.
251 (setq primes [2 3 5 7 11 13])
264 See also the function `elt', in *Note Sequence Functions::.
266 - Function: aset array index object
267 This function sets the INDEXth element of ARRAY to be OBJECT. It
270 (setq w [foo bar baz])
291 If ARRAY is a string and OBJECT is not a character, a
292 `wrong-type-argument' error results.
294 - Function: fillarray array object
295 This function fills the array ARRAY with OBJECT, so that each
296 element of ARRAY is OBJECT. It returns ARRAY.
298 (setq a [a b c d e f g])
305 (setq s "When in the course")
306 => "When in the course"
308 => "------------------"
315 If ARRAY is a string and OBJECT is not a character, a
316 `wrong-type-argument' error results.
318 The general sequence functions `copy-sequence' and `length' are
319 often useful for objects known to be arrays. *Note Sequence
323 File: lispref.info, Node: Vectors, Next: Vector Functions, Prev: Array Functions, Up: Sequences Arrays Vectors
328 Arrays in Lisp, like arrays in most languages, are blocks of memory
329 whose elements can be accessed in constant time. A "vector" is a
330 general-purpose array; its elements can be any Lisp objects. (The other
331 kind of array in XEmacs Lisp is the "string", whose elements must be
332 characters.) Vectors in XEmacs serve as obarrays (vectors of symbols),
333 although this is a shortcoming that should be fixed. They are also used
334 internally as part of the representation of a byte-compiled function; if
335 you print such a function, you will see a vector in it.
337 In XEmacs Lisp, the indices of the elements of a vector start from
338 zero and count up from there.
340 Vectors are printed with square brackets surrounding the elements.
341 Thus, a vector whose elements are the symbols `a', `b' and `a' is
342 printed as `[a b a]'. You can write vectors in the same way in Lisp
345 A vector, like a string or a number, is considered a constant for
346 evaluation: the result of evaluating it is the same vector. This does
347 not evaluate or even examine the elements of the vector. *Note
348 Self-Evaluating Forms::.
350 Here are examples of these principles:
352 (setq avector [1 two '(three) "four" [five]])
353 => [1 two (quote (three)) "four" [five]]
355 => [1 two (quote (three)) "four" [five]]
356 (eq avector (eval avector))
360 File: lispref.info, Node: Vector Functions, Next: Bit Vectors, Prev: Vectors, Up: Sequences Arrays Vectors
362 Functions That Operate on Vectors
363 =================================
365 Here are some functions that relate to vectors:
367 - Function: vectorp object
368 This function returns `t' if OBJECT is a vector.
375 - Function: vector &rest objects
376 This function creates and returns a vector whose elements are the
379 (vector 'foo 23 [bar baz] "rats")
380 => [foo 23 [bar baz] "rats"]
384 - Function: make-vector length object
385 This function returns a new vector consisting of LENGTH elements,
386 each initialized to OBJECT.
388 (setq sleepy (make-vector 9 'Z))
389 => [Z Z Z Z Z Z Z Z Z]
391 - Function: vconcat &rest sequences
392 This function returns a new vector containing all the elements of
393 the SEQUENCES. The arguments SEQUENCES may be lists, vectors, or
394 strings. If no SEQUENCES are given, an empty vector is returned.
396 The value is a newly constructed vector that is not `eq' to any
399 (setq a (vconcat '(A B C) '(D E F)))
405 (vconcat [A B C] "aa" '(foo (6 7)))
406 => [A B C 97 97 foo (6 7)]
408 The `vconcat' function also allows integers as arguments. It
409 converts them to strings of digits, making up the decimal print
410 representation of the integer, and then uses the strings instead
411 of the original integers. *Don't use this feature; we plan to
412 eliminate it. If you already use this feature, change your
413 programs now!* The proper way to convert an integer to a decimal
414 number in this way is with `format' (*note Formatting Strings::)
415 or `number-to-string' (*note String Conversion::).
417 For other concatenation functions, see `mapconcat' in *Note
418 Mapping Functions::, `concat' in *Note Creating Strings::, `append'
419 in *Note Building Lists::, and `bvconcat' in *Note Bit Vector
422 The `append' function provides a way to convert a vector into a list
423 with the same elements (*note Building Lists::):
425 (setq avector [1 two (quote (three)) "four" [five]])
426 => [1 two (quote (three)) "four" [five]]
428 => (1 two (quote (three)) "four" [five])
431 File: lispref.info, Node: Bit Vectors, Next: Bit Vector Functions, Prev: Vector Functions, Up: Sequences Arrays Vectors
436 Bit vectors are specialized vectors that can only represent arrays
437 of 1's and 0's. Bit vectors have a very efficient representation and
438 are useful for representing sets of boolean (true or false) values.
440 There is no limit on the size of a bit vector. You could, for
441 example, create a bit vector with 100,000 elements if you really wanted
444 Bit vectors have a special printed representation consisting of `#*'
445 followed by the bits of the vector. For example, a bit vector whose
446 elements are 0, 1, 1, 0, and 1, respectively, is printed as
450 Bit vectors are considered constants for evaluation, like vectors,
451 strings, and numbers. *Note Self-Evaluating Forms::.
454 File: lispref.info, Node: Bit Vector Functions, Prev: Bit Vectors, Up: Sequences Arrays Vectors
456 Functions That Operate on Bit Vectors
457 =====================================
459 Here are some functions that relate to bit vectors:
461 - Function: bit-vector-p object
462 This function returns `t' if OBJECT is a bit vector.
471 - Function: bitp object
472 This function returns `t' if OBJECT is either 0 or 1.
474 - Function: bit-vector &rest bits
475 This function creates and returns a bit vector whose elements are
476 the arguments BITS. Each argument must be a bit, i.e. one of the
479 (bit-vector 0 0 0 1 0 0 0 0 1 0)
484 - Function: make-bit-vector length bit
485 This function creates and returns a bit vector consisting of
486 LENGTH elements, each initialized to BIT, which must be one of the
489 (setq picket-fence (make-bit-vector 9 1))
492 - Function: bvconcat &rest sequences
493 This function returns a new bit vector containing all the elements
494 of the SEQUENCES. The arguments SEQUENCES may be lists, vectors,
495 or bit vectors, all of whose elements are the integers 0 or 1. If
496 no SEQUENCES are given, an empty bit vector is returned.
498 The value is a newly constructed bit vector that is not `eq' to any
501 (setq a (bvconcat '(1 1 0) '(0 0 1)))
507 (bvconcat [1 0 0 0 0] #*111 '(0 0 0 0 1))
510 For other concatenation functions, see `mapconcat' in *Note
511 Mapping Functions::, `concat' in *Note Creating Strings::,
512 `vconcat' in *Note Vector Functions::, and `append' in *Note
515 The `append' function provides a way to convert a bit vector into a
516 list with the same elements (*note Building Lists::):
524 File: lispref.info, Node: Symbols, Next: Evaluation, Prev: Sequences Arrays Vectors, Up: Top
529 A "symbol" is an object with a unique name. This chapter describes
530 symbols, their components, their property lists, and how they are
531 created and interned. Separate chapters describe the use of symbols as
532 variables and as function names; see *Note Variables::, and *Note
533 Functions::. For the precise read syntax for symbols, see *Note Symbol
536 You can test whether an arbitrary Lisp object is a symbol with
539 - Function: symbolp object
540 This function returns `t' if OBJECT is a symbol, `nil' otherwise.
544 * Symbol Components:: Symbols have names, values, function definitions
546 * Definitions:: A definition says how a symbol will be used.
547 * Creating Symbols:: How symbols are kept unique.
548 * Symbol Properties:: Each symbol has a property list
549 for recording miscellaneous information.
552 File: lispref.info, Node: Symbol Components, Next: Definitions, Up: Symbols
557 Each symbol has four components (or "cells"), each of which
558 references another object:
561 The "print name cell" holds a string that names the symbol for
562 reading and printing. See `symbol-name' in *Note Creating
566 The "value cell" holds the current value of the symbol as a
567 variable. When a symbol is used as a form, the value of the form
568 is the contents of the symbol's value cell. See `symbol-value' in
569 *Note Accessing Variables::.
572 The "function cell" holds the function definition of the symbol.
573 When a symbol is used as a function, its function definition is
574 used in its place. This cell is also used to make a symbol stand
575 for a keymap or a keyboard macro, for editor command execution.
576 Because each symbol has separate value and function cells,
577 variables and function names do not conflict. See
578 `symbol-function' in *Note Function Cells::.
581 The "property list cell" holds the property list of the symbol.
582 See `symbol-plist' in *Note Symbol Properties::.
584 The print name cell always holds a string, and cannot be changed.
585 The other three cells can be set individually to any specified Lisp
588 The print name cell holds the string that is the name of the symbol.
589 Since symbols are represented textually by their names, it is important
590 not to have two symbols with the same name. The Lisp reader ensures
591 this: every time it reads a symbol, it looks for an existing symbol with
592 the specified name before it creates a new one. (In XEmacs Lisp, this
593 lookup uses a hashing algorithm and an obarray; see *Note Creating
596 In normal usage, the function cell usually contains a function or
597 macro, as that is what the Lisp interpreter expects to see there (*note
598 Evaluation::). Keyboard macros (*note Keyboard Macros::), keymaps
599 (*note Keymaps::) and autoload objects (*note Autoloading::) are also
600 sometimes stored in the function cell of symbols. We often refer to
601 "the function `foo'" when we really mean the function stored in the
602 function cell of the symbol `foo'. We make the distinction only when
605 The property list cell normally should hold a correctly formatted
606 property list (*note Property Lists::), as a number of functions expect
607 to see a property list there.
609 The function cell or the value cell may be "void", which means that
610 the cell does not reference any object. (This is not the same thing as
611 holding the symbol `void', nor the same as holding the symbol `nil'.)
612 Examining a cell that is void results in an error, such as `Symbol's
613 value as variable is void'.
615 The four functions `symbol-name', `symbol-value', `symbol-plist',
616 and `symbol-function' return the contents of the four cells of a
617 symbol. Here as an example we show the contents of the four cells of
618 the symbol `buffer-file-name':
620 (symbol-name 'buffer-file-name)
621 => "buffer-file-name"
622 (symbol-value 'buffer-file-name)
623 => "/gnu/elisp/symbols.texi"
624 (symbol-plist 'buffer-file-name)
625 => (variable-documentation 29529)
626 (symbol-function 'buffer-file-name)
627 => #<subr buffer-file-name>
629 Because this symbol is the variable which holds the name of the file
630 being visited in the current buffer, the value cell contents we see are
631 the name of the source file of this chapter of the XEmacs Lisp Manual.
632 The property list cell contains the list `(variable-documentation
633 29529)' which tells the documentation functions where to find the
634 documentation string for the variable `buffer-file-name' in the `DOC'
635 file. (29529 is the offset from the beginning of the `DOC' file to
636 where that documentation string begins.) The function cell contains
637 the function for returning the name of the file. `buffer-file-name'
638 names a primitive function, which has no read syntax and prints in hash
639 notation (*note Primitive Function Type::). A symbol naming a function
640 written in Lisp would have a lambda expression (or a byte-code object)
644 File: lispref.info, Node: Definitions, Next: Creating Symbols, Prev: Symbol Components, Up: Symbols
649 A "definition" in Lisp is a special form that announces your
650 intention to use a certain symbol in a particular way. In XEmacs Lisp,
651 you can define a symbol as a variable, or define it as a function (or
652 macro), or both independently.
654 A definition construct typically specifies a value or meaning for the
655 symbol for one kind of use, plus documentation for its meaning when used
656 in this way. Thus, when you define a symbol as a variable, you can
657 supply an initial value for the variable, plus documentation for the
660 `defvar' and `defconst' are special forms that define a symbol as a
661 global variable. They are documented in detail in *Note Defining
664 `defun' defines a symbol as a function, creating a lambda expression
665 and storing it in the function cell of the symbol. This lambda
666 expression thus becomes the function definition of the symbol. (The
667 term "function definition", meaning the contents of the function cell,
668 is derived from the idea that `defun' gives the symbol its definition
669 as a function.) `defsubst', `define-function' and `defalias' are other
670 ways of defining a function. *Note Functions::.
672 `defmacro' defines a symbol as a macro. It creates a macro object
673 and stores it in the function cell of the symbol. Note that a given
674 symbol can be a macro or a function, but not both at once, because both
675 macro and function definitions are kept in the function cell, and that
676 cell can hold only one Lisp object at any given time. *Note Macros::.
678 In XEmacs Lisp, a definition is not required in order to use a symbol
679 as a variable or function. Thus, you can make a symbol a global
680 variable with `setq', whether you define it first or not. The real
681 purpose of definitions is to guide programmers and programming tools.
682 They inform programmers who read the code that certain symbols are
683 _intended_ to be used as variables, or as functions. In addition,
684 utilities such as `etags' and `make-docfile' recognize definitions, and
685 add appropriate information to tag tables and the `DOC' file. *Note
686 Accessing Documentation::.
689 File: lispref.info, Node: Creating Symbols, Next: Symbol Properties, Prev: Definitions, Up: Symbols
691 Creating and Interning Symbols
692 ==============================
694 To understand how symbols are created in XEmacs Lisp, you must know
695 how Lisp reads them. Lisp must ensure that it finds the same symbol
696 every time it reads the same set of characters. Failure to do so would
697 cause complete confusion.
699 When the Lisp reader encounters a symbol, it reads all the characters
700 of the name. Then it "hashes" those characters to find an index in a
701 table called an "obarray". Hashing is an efficient method of looking
702 something up. For example, instead of searching a telephone book cover
703 to cover when looking up Jan Jones, you start with the J's and go from
704 there. That is a simple version of hashing. Each element of the
705 obarray is a "bucket" which holds all the symbols with a given hash
706 code; to look for a given name, it is sufficient to look through all
707 the symbols in the bucket for that name's hash code.
709 If a symbol with the desired name is found, the reader uses that
710 symbol. If the obarray does not contain a symbol with that name, the
711 reader makes a new symbol and adds it to the obarray. Finding or adding
712 a symbol with a certain name is called "interning" it, and the symbol
713 is then called an "interned symbol".
715 Interning ensures that each obarray has just one symbol with any
716 particular name. Other like-named symbols may exist, but not in the
717 same obarray. Thus, the reader gets the same symbols for the same
718 names, as long as you keep reading with the same obarray.
720 No obarray contains all symbols; in fact, some symbols are not in any
721 obarray. They are called "uninterned symbols". An uninterned symbol
722 has the same four cells as other symbols; however, the only way to gain
723 access to it is by finding it in some other object or as the value of a
726 In XEmacs Lisp, an obarray is actually a vector. Each element of the
727 vector is a bucket; its value is either an interned symbol whose name
728 hashes to that bucket, or 0 if the bucket is empty. Each interned
729 symbol has an internal link (invisible to the user) to the next symbol
730 in the bucket. Because these links are invisible, there is no way to
731 find all the symbols in an obarray except using `mapatoms' (below).
732 The order of symbols in a bucket is not significant.
734 In an empty obarray, every element is 0, and you can create an
735 obarray with `(make-vector LENGTH 0)'. *This is the only valid way to
736 create an obarray.* Prime numbers as lengths tend to result in good
737 hashing; lengths one less than a power of two are also good.
739 *Do not try to put symbols in an obarray yourself.* This does not
740 work--only `intern' can enter a symbol in an obarray properly. *Do not
741 try to intern one symbol in two obarrays.* This would garble both
742 obarrays, because a symbol has just one slot to hold the following
743 symbol in the obarray bucket. The results would be unpredictable.
745 It is possible for two different symbols to have the same name in
746 different obarrays; these symbols are not `eq' or `equal'. However,
747 this normally happens only as part of the abbrev mechanism (*note
750 Common Lisp note: In Common Lisp, a single symbol may be interned
753 Most of the functions below take a name and sometimes an obarray as
754 arguments. A `wrong-type-argument' error is signaled if the name is
755 not a string, or if the obarray is not a vector.
757 - Function: symbol-name symbol
758 This function returns the string that is SYMBOL's name. For
764 Changing the string by substituting characters, etc, does change
765 the name of the symbol, but fails to update the obarray, so don't
768 - Function: make-symbol name
769 This function returns a newly-allocated, uninterned symbol whose
770 name is NAME (which must be a string). Its value and function
771 definition are void, and its property list is `nil'. In the
772 example below, the value of `sym' is not `eq' to `foo' because it
773 is a distinct uninterned symbol whose name is also `foo'.
775 (setq sym (make-symbol "foo"))
780 - Function: intern name &optional obarray
781 This function returns the interned symbol whose name is NAME. If
782 there is no such symbol in the obarray OBARRAY, `intern' creates a
783 new one, adds it to the obarray, and returns it. If OBARRAY is
784 omitted, the value of the global variable `obarray' is used.
786 (setq sym (intern "foo"))
791 (setq sym1 (intern "foo" other-obarray))
796 - Function: intern-soft name &optional obarray
797 This function returns the symbol in OBARRAY whose name is NAME, or
798 `nil' if OBARRAY has no symbol with that name. Therefore, you can
799 use `intern-soft' to test whether a symbol with a given name is
800 already interned. If OBARRAY is omitted, the value of the global
801 variable `obarray' is used.
803 (intern-soft "frazzle") ; No such symbol exists.
805 (make-symbol "frazzle") ; Create an uninterned one.
807 (intern-soft "frazzle") ; That one cannot be found.
809 (setq sym (intern "frazzle")) ; Create an interned one.
811 (intern-soft "frazzle") ; That one can be found!
813 (eq sym 'frazzle) ; And it is the same one.
817 This variable is the standard obarray for use by `intern' and
820 - Function: mapatoms function &optional obarray
821 This function calls FUNCTION for each symbol in the obarray
822 OBARRAY. It returns `nil'. If OBARRAY is omitted, it defaults to
823 the value of `obarray', the standard obarray for ordinary symbols.
827 (defun count-syms (s)
828 (setq count (1+ count)))
830 (mapatoms 'count-syms)
835 See `documentation' in *Note Accessing Documentation::, for another
836 example using `mapatoms'.
838 - Function: unintern symbol &optional obarray
839 This function deletes SYMBOL from the obarray OBARRAY. If
840 `symbol' is not actually in the obarray, `unintern' does nothing.
841 If OBARRAY is `nil', the current obarray is used.
843 If you provide a string instead of a symbol as SYMBOL, it stands
844 for a symbol name. Then `unintern' deletes the symbol (if any) in
845 the obarray which has that name. If there is no such symbol,
846 `unintern' does nothing.
848 If `unintern' does delete a symbol, it returns `t'. Otherwise it
852 File: lispref.info, Node: Symbol Properties, Prev: Creating Symbols, Up: Symbols
857 A "property list" ("plist" for short) is a list of paired elements,
858 often stored in the property list cell of a symbol. Each of the pairs
859 associates a property name (usually a symbol) with a property or value.
860 Property lists are generally used to record information about a
861 symbol, such as its documentation as a variable, the name of the file
862 where it was defined, or perhaps even the grammatical class of the
863 symbol (representing a word) in a language-understanding system.
865 Some objects which are not symbols also have property lists
866 associated with them, and XEmacs provides a full complement of
867 functions for working with property lists. *Note Property Lists::.
869 The property names and values in a property list can be any Lisp
870 objects, but the names are usually symbols. They are compared using
871 `eq'. Here is an example of a property list, found on the symbol
872 `progn' when the compiler is loaded:
874 (lisp-indent-function 0 byte-compile byte-compile-progn)
876 Here `lisp-indent-function' and `byte-compile' are property names, and
877 the other two elements are the corresponding values.
881 * Plists and Alists:: Comparison of the advantages of property
882 lists and association lists.
883 * Object Plists:: Functions to access objects' property lists.
884 * Other Plists:: Accessing property lists stored elsewhere.
887 File: lispref.info, Node: Plists and Alists, Next: Object Plists, Up: Symbol Properties
889 Property Lists and Association Lists
890 ------------------------------------
892 Association lists (*note Association Lists::) are very similar to
893 property lists. In contrast to association lists, the order of the
894 pairs in the property list is not significant since the property names
897 Property lists are better than association lists for attaching
898 information to various Lisp function names or variables. If all the
899 associations are recorded in one association list, the program will need
900 to search that entire list each time a function or variable is to be
901 operated on. By contrast, if the information is recorded in the
902 property lists of the function names or variables themselves, each
903 search will scan only the length of one property list, which is usually
904 short. This is why the documentation for a variable is recorded in a
905 property named `variable-documentation'. The byte compiler likewise
906 uses properties to record those functions needing special treatment.
908 However, association lists have their own advantages. Depending on
909 your application, it may be faster to add an association to the front of
910 an association list than to update a property. All properties for a
911 symbol are stored in the same property list, so there is a possibility
912 of a conflict between different uses of a property name. (For this
913 reason, it is a good idea to choose property names that are probably
914 unique, such as by including the name of the library in the property
915 name.) An association list may be used like a stack where associations
916 are pushed on the front of the list and later discarded; this is not
917 possible with a property list.
920 File: lispref.info, Node: Object Plists, Next: Other Plists, Prev: Plists and Alists, Up: Symbol Properties
922 Property List Functions for Objects
923 -----------------------------------
925 Once upon a time, only symbols had property lists. Now, several
926 other object types, including strings, extents, faces and glyphs also
929 - Function: symbol-plist symbol
930 This function returns the property list of SYMBOL.
932 - Function: object-plist object
933 This function returns the property list of OBJECT. If OBJECT is a
934 symbol, this is identical to `symbol-plist'.
936 - Function: setplist symbol plist
937 This function sets SYMBOL's property list to PLIST. Normally,
938 PLIST should be a well-formed property list, but this is not
941 (setplist 'foo '(a 1 b (2 3) c nil))
942 => (a 1 b (2 3) c nil)
944 => (a 1 b (2 3) c nil)
946 For symbols in special obarrays, which are not used for ordinary
947 purposes, it may make sense to use the property list cell in a
948 nonstandard fashion; in fact, the abbrev mechanism does so (*note
949 Abbrevs::). But generally, its use is discouraged. Use `put'
950 instead. `setplist' can only be used with symbols, not other
953 - Function: get object property &optional default
954 This function finds the value of the property named PROPERTY in
955 OBJECT's property list. If there is no such property, `default'
956 (which itself defaults to `nil') is returned.
958 PROPERTY is compared with the existing properties using `eq', so
959 any object is a legitimate property.
961 See `put' for an example.
963 - Function: put object property value
964 This function puts VALUE onto OBJECT's property list under the
965 property name PROPERTY, replacing any previous property value.
966 The `put' function returns VALUE.
968 (put 'fly 'verb 'transitive)
970 (put 'fly 'noun '(a buzzing little bug))
971 => (a buzzing little bug)
975 => (verb transitive noun (a buzzing little bug))
977 - Function: remprop object property
978 This function removes the entry for PROPERTY from the property
979 list of OBJECT. It returns `t' if the property was indeed found
980 and removed, or `nil' if there was no such property. (This
981 function was probably omitted from Emacs originally because, since
982 `get' did not allow a DEFAULT, it was very difficult to
983 distinguish between a missing property and a property whose value
984 was `nil'; thus, setting a property to `nil' was close enough to
985 `remprop' for most purposes.)
988 File: lispref.info, Node: Other Plists, Prev: Object Plists, Up: Symbol Properties
990 Property Lists Not Associated with Objects
991 ------------------------------------------
993 These functions are useful for manipulating property lists that are
994 stored in places other than symbols:
996 - Function: getf plist property &optional default
997 This returns the value of the PROPERTY property stored in the
998 property list PLIST. For example,
1000 (getf '(foo 4) 'foo)
1003 - Macro: putf plist property value
1004 This stores VALUE as the value of the PROPERTY property in the
1005 property list PLIST. It may modify PLIST destructively, or it may
1006 construct a new list structure without altering the old. The
1007 function returns the modified property list, so you can store that
1008 back in the place where you got PLIST. For example,
1010 (setq my-plist '(bar t foo 4))
1012 (setq my-plist (putf my-plist 'foo 69))
1014 (setq my-plist (putf my-plist 'quux '(a)))
1015 => (quux (a) bar t foo 5)
1017 - Function: plists-eq a b
1018 This function returns non-`nil' if property lists A and B are
1019 `eq'. This means that the property lists have the same values for
1020 all the same properties, where comparison between values is done
1023 - Function: plists-equal a b
1024 This function returns non-`nil' if property lists A and B are
1027 Both of the above functions do order-insensitive comparisons.
1029 (plists-eq '(a 1 b 2 c nil) '(b 2 a 1))
1031 (plists-eq '(foo "hello" bar "goodbye") '(bar "goodbye" foo "hello"))
1033 (plists-equal '(foo "hello" bar "goodbye") '(bar "goodbye" foo "hello"))
1037 File: lispref.info, Node: Evaluation, Next: Control Structures, Prev: Symbols, Up: Top
1042 The "evaluation" of expressions in XEmacs Lisp is performed by the
1043 "Lisp interpreter"--a program that receives a Lisp object as input and
1044 computes its "value as an expression". How it does this depends on the
1045 data type of the object, according to rules described in this chapter.
1046 The interpreter runs automatically to evaluate portions of your
1047 program, but can also be called explicitly via the Lisp primitive
1052 * Intro Eval:: Evaluation in the scheme of things.
1053 * Eval:: How to invoke the Lisp interpreter explicitly.
1054 * Forms:: How various sorts of objects are evaluated.
1055 * Quoting:: Avoiding evaluation (to put constants in the program).
1058 File: lispref.info, Node: Intro Eval, Next: Eval, Up: Evaluation
1060 Introduction to Evaluation
1061 ==========================
1063 The Lisp interpreter, or evaluator, is the program that computes the
1064 value of an expression that is given to it. When a function written in
1065 Lisp is called, the evaluator computes the value of the function by
1066 evaluating the expressions in the function body. Thus, running any
1067 Lisp program really means running the Lisp interpreter.
1069 How the evaluator handles an object depends primarily on the data
1072 A Lisp object that is intended for evaluation is called an
1073 "expression" or a "form". The fact that expressions are data objects
1074 and not merely text is one of the fundamental differences between
1075 Lisp-like languages and typical programming languages. Any object can
1076 be evaluated, but in practice only numbers, symbols, lists and strings
1077 are evaluated very often.
1079 It is very common to read a Lisp expression and then evaluate the
1080 expression, but reading and evaluation are separate activities, and
1081 either can be performed alone. Reading per se does not evaluate
1082 anything; it converts the printed representation of a Lisp object to the
1083 object itself. It is up to the caller of `read' whether this object is
1084 a form to be evaluated, or serves some entirely different purpose.
1085 *Note Input Functions::.
1087 Do not confuse evaluation with command key interpretation. The
1088 editor command loop translates keyboard input into a command (an
1089 interactively callable function) using the active keymaps, and then
1090 uses `call-interactively' to invoke the command. The execution of the
1091 command itself involves evaluation if the command is written in Lisp,
1092 but that is not a part of command key interpretation itself. *Note
1095 Evaluation is a recursive process. That is, evaluation of a form may
1096 call `eval' to evaluate parts of the form. For example, evaluation of
1097 a function call first evaluates each argument of the function call, and
1098 then evaluates each form in the function body. Consider evaluation of
1099 the form `(car x)': the subform `x' must first be evaluated
1100 recursively, so that its value can be passed as an argument to the
1103 Evaluation of a function call ultimately calls the function specified
1104 in it. *Note Functions::. The execution of the function may itself
1105 work by evaluating the function definition; or the function may be a
1106 Lisp primitive implemented in C, or it may be a byte-compiled function
1107 (*note Byte Compilation::).
1109 The evaluation of forms takes place in a context called the
1110 "environment", which consists of the current values and bindings of all
1111 Lisp variables.(1) Whenever the form refers to a variable without
1112 creating a new binding for it, the value of the binding in the current
1113 environment is used. *Note Variables::.
1115 Evaluation of a form may create new environments for recursive
1116 evaluation by binding variables (*note Local Variables::). These
1117 environments are temporary and vanish by the time evaluation of the form
1118 is complete. The form may also make changes that persist; these changes
1119 are called "side effects". An example of a form that produces side
1120 effects is `(setq foo 1)'.
1122 The details of what evaluation means for each kind of form are
1123 described below (*note Forms::).
1125 ---------- Footnotes ----------
1127 (1) This definition of "environment" is specifically not intended to
1128 include all the data that can affect the result of a program.
1131 File: lispref.info, Node: Eval, Next: Forms, Prev: Intro Eval, Up: Evaluation
1136 Most often, forms are evaluated automatically, by virtue of their
1137 occurrence in a program being run. On rare occasions, you may need to
1138 write code that evaluates a form that is computed at run time, such as
1139 after reading a form from text being edited or getting one from a
1140 property list. On these occasions, use the `eval' function.
1142 *Please note:* it is generally cleaner and more flexible to call
1143 functions that are stored in data structures, rather than to evaluate
1144 expressions stored in data structures. Using functions provides the
1145 ability to pass information to them as arguments.
1147 The functions and variables described in this section evaluate forms,
1148 specify limits to the evaluation process, or record recently returned
1149 values. Loading a file also does evaluation (*note Loading::).
1151 - Function: eval form
1152 This is the basic function for performing evaluation. It evaluates
1153 FORM in the current environment and returns the result. How the
1154 evaluation proceeds depends on the type of the object (*note
1157 Since `eval' is a function, the argument expression that appears
1158 in a call to `eval' is evaluated twice: once as preparation before
1159 `eval' is called, and again by the `eval' function itself. Here
1166 ;; `eval' receives argument `bar', which is the value of `foo'
1172 The number of currently active calls to `eval' is limited to
1173 `max-lisp-eval-depth' (see below).
1175 - Command: eval-region start end &optional stream
1176 This function evaluates the forms in the current buffer in the
1177 region defined by the positions START and END. It reads forms from
1178 the region and calls `eval' on them until the end of the region is
1179 reached, or until an error is signaled and not handled.
1181 If STREAM is supplied, `standard-output' is bound to it during the
1184 You can use the variable `load-read-function' to specify a function
1185 for `eval-region' to use instead of `read' for reading
1186 expressions. *Note How Programs Do Loading::.
1188 `eval-region' always returns `nil'.
1190 - Command: eval-buffer buffer &optional stream
1191 This is like `eval-region' except that it operates on the whole
1194 - Variable: max-lisp-eval-depth
1195 This variable defines the maximum depth allowed in calls to `eval',
1196 `apply', and `funcall' before an error is signaled (with error
1197 message `"Lisp nesting exceeds max-lisp-eval-depth"'). This counts
1198 internal uses of those functions, such as for calling the functions
1199 mentioned in Lisp expressions, and recursive evaluation of
1200 function call arguments and function body forms.
1202 This limit, with the associated error when it is exceeded, is one
1203 way that Lisp avoids infinite recursion on an ill-defined function.
1205 The default value of this variable is 500. If you set it to a
1206 value less than 100, Lisp will reset it to 100 if the given value
1209 `max-specpdl-size' provides another limit on nesting. *Note Local
1213 The value of this variable is a list of the values returned by all
1214 the expressions that were read from buffers (including the
1215 minibuffer), evaluated, and printed. The elements are ordered
1220 (list 'A (1+ 2) auto-save-default)
1225 This variable is useful for referring back to values of forms
1226 recently evaluated. It is generally a bad idea to print the value
1227 of `values' itself, since this may be very long. Instead, examine
1228 particular elements, like this:
1230 ;; Refer to the most recent evaluation result.
1233 ;; That put a new element on,
1234 ;; so all elements move back one.
1237 ;; This gets the element that was next-to-most-recent
1238 ;; before this example.
1243 File: lispref.info, Node: Forms, Next: Quoting, Prev: Eval, Up: Evaluation
1248 A Lisp object that is intended to be evaluated is called a "form".
1249 How XEmacs evaluates a form depends on its data type. XEmacs has three
1250 different kinds of form that are evaluated differently: symbols, lists,
1251 and "all other types". This section describes all three kinds,
1252 starting with "all other types" which are self-evaluating forms.
1256 * Self-Evaluating Forms:: Forms that evaluate to themselves.
1257 * Symbol Forms:: Symbols evaluate as variables.
1258 * Classifying Lists:: How to distinguish various sorts of list forms.
1259 * Function Indirection:: When a symbol appears as the car of a list,
1260 we find the real function via the symbol.
1261 * Function Forms:: Forms that call functions.
1262 * Macro Forms:: Forms that call macros.
1263 * Special Forms:: ``Special forms'' are idiosyncratic primitives,
1264 most of them extremely important.
1265 * Autoloading:: Functions set up to load files
1266 containing their real definitions.