comparison man/cl.texi @ 380:8626e4521993 r21-2-5

Import from CVS: tag r21-2-5
author cvs
date Mon, 13 Aug 2007 11:07:10 +0200
parents cc15677e0335
children 74fd4e045ea6
comparison
equal deleted inserted replaced
379:76b7d63099ad 380:8626e4521993
945 it compares numbers without regard to type (so that @code{(equalp 3 945 it compares numbers without regard to type (so that @code{(equalp 3
946 3.0)} is true). Vectors and conses are compared recursively. All other 946 3.0)} is true). Vectors and conses are compared recursively. All other
947 objects are compared as if by @code{equal}. 947 objects are compared as if by @code{equal}.
948 948
949 This function differs from Common Lisp @code{equalp} in several 949 This function differs from Common Lisp @code{equalp} in several
950 respects. First, in keeping with the idea that strings are less 950 respects. In keeping with the idea that strings are less
951 vector-like in Emacs Lisp, this package's @code{equalp} also will not 951 vector-like in Emacs Lisp, this package's @code{equalp} also will not
952 compare strings against vectors of integers. Second, Common Lisp's 952 compare strings against vectors of integers.
953 @code{equalp} compares hash tables without regard to ordering, whereas
954 this package simply compares hash tables in terms of their underlying
955 structure (which means vectors for Lucid Emacs 19 hash tables, or lists
956 for other hash tables).
957 @end defun 953 @end defun
958 954
959 Also note that the Common Lisp functions @code{member} and @code{assoc} 955 Also note that the Common Lisp functions @code{member} and @code{assoc}
960 use @code{eql} to compare elements, whereas Emacs Lisp follows the 956 use @code{eql} to compare elements, whereas Emacs Lisp follows the
961 MacLisp tradition and uses @code{equal} for these two functions. 957 MacLisp tradition and uses @code{equal} for these two functions.
1096 The use of @code{nthcdr} as a @var{place} form is an extension 1092 The use of @code{nthcdr} as a @var{place} form is an extension
1097 to standard Common Lisp. 1093 to standard Common Lisp.
1098 1094
1099 @item 1095 @item
1100 The following Emacs-specific functions are also @code{setf}-able. 1096 The following Emacs-specific functions are also @code{setf}-able.
1101 (Some of these are defined only in Emacs 19 or only in Lucid Emacs.) 1097 (Some of these are defined only in Emacs 19 or only in XEmacs.)
1102 1098
1103 @smallexample 1099 @smallexample
1104 buffer-file-name marker-position 1100 buffer-file-name marker-position
1105 buffer-modified-p match-data 1101 buffer-modified-p match-data
1106 buffer-name mouse-position 1102 buffer-name mouse-position
1107 buffer-string overlay-end 1103 buffer-string overlay-end
1108 buffer-substring overlay-get 1104 buffer-substring overlay-get
1109 current-buffer overlay-start 1105 current-buffer overlay-start
1110 current-case-table point 1106 current-case-table point
1111 current-column point-marker 1107 current-column point-marker
1112 current-global-map point-max 1108 current-global-map point-max
1113 current-input-mode point-min 1109 current-input-mode point-min
1114 current-local-map process-buffer 1110 current-local-map process-buffer
1115 current-window-configuration process-filter 1111 current-window-configuration process-filter
1116 default-file-modes process-sentinel 1112 default-file-modes process-sentinel
1117 default-value read-mouse-position 1113 default-value read-mouse-position
1118 documentation-property screen-height 1114 documentation-property screen-height
1119 extent-data screen-menubar 1115 extent-data screen-menubar
1120 extent-end-position screen-width 1116 extent-end-position screen-width
1121 extent-start-position selected-window 1117 extent-start-position selected-window
1122 face-background selected-screen 1118 face-background selected-screen
1123 face-background-pixmap selected-frame 1119 face-background-pixmap selected-frame
1124 face-font standard-case-table 1120 face-font standard-case-table
1125 face-foreground syntax-table 1121 face-foreground syntax-table
1126 face-underline-p window-buffer 1122 face-underline-p window-buffer
1127 file-modes window-dedicated-p 1123 file-modes window-dedicated-p
1128 frame-height window-display-table 1124 frame-height window-display-table
1129 frame-parameters window-height 1125 frame-parameters window-height
1130 frame-visible-p window-hscroll 1126 frame-visible-p window-hscroll
1131 frame-width window-point 1127 frame-width window-point
1132 get-register window-start 1128 get-register window-start
1133 getenv window-width 1129 getenv window-width
1134 global-key-binding x-get-cut-buffer 1130 global-key-binding x-get-cut-buffer
1135 keymap-parent x-get-cutbuffer 1131 keymap-parent x-get-cutbuffer
1136 local-key-binding x-get-secondary-selection 1132 local-key-binding x-get-secondary-selection
1137 mark x-get-selection 1133 mark x-get-selection
1138 mark-marker 1134 mark-marker
1139 @end smallexample 1135 @end smallexample
1140 1136
1141 Most of these have directly corresponding ``set'' functions, like 1137 Most of these have directly corresponding ``set'' functions, like
1142 @code{use-local-map} for @code{current-local-map}, or @code{goto-char} 1138 @code{use-local-map} for @code{current-local-map}, or @code{goto-char}
1143 for @code{point}. A few, like @code{point-min}, expand to longer 1139 for @code{point}. A few, like @code{point-min}, expand to longer
2582 is the opposite word of the word following @code{the}) to cause 2578 is the opposite word of the word following @code{the}) to cause
2583 @var{var} and @var{var2} to be bound to the two parts of each 2579 @var{var} and @var{var2} to be bound to the two parts of each
2584 hash table entry. 2580 hash table entry.
2585 2581
2586 @item for @var{var} being the key-codes of @var{keymap} 2582 @item for @var{var} being the key-codes of @var{keymap}
2587 This clause iterates over the entries in @var{keymap}. In GNU Emacs 2583 This clause iterates over the entries in @var{keymap}. In GNU Emacs 18
2588 18 and 19, keymaps are either alists or vectors, and key-codes are 2584 and 19, keymaps are either alists or vectors, and key-codes are integers
2589 integers or symbols. In Lucid Emacs 19, keymaps are a special new 2585 or symbols. In XEmacs, keymaps are a special new data type, and
2590 data type, and key-codes are symbols or lists of symbols. The 2586 key-codes are symbols or lists of symbols. The iteration does not enter
2591 iteration does not enter nested keymaps or inherited (parent) keymaps. 2587 nested keymaps or inherited (parent) keymaps. You can use @samp{the
2592 You can use @samp{the key-bindings} to access the commands bound to 2588 key-bindings} to access the commands bound to the keys rather than the
2593 the keys rather than the key codes, and you can add a @code{using} 2589 key codes, and you can add a @code{using} clause to access both the
2594 clause to access both the codes and the bindings together. 2590 codes and the bindings together.
2595 2591
2596 @item for @var{var} being the key-seqs of @var{keymap} 2592 @item for @var{var} being the key-seqs of @var{keymap}
2597 This clause iterates over all key sequences defined by @var{keymap} 2593 This clause iterates over all key sequences defined by @var{keymap}
2598 and its nested keymaps, where @var{var} takes on values which are 2594 and its nested keymaps, where @var{var} takes on values which are
2599 strings in Emacs 18 or vectors in Emacs 19. The strings or vectors 2595 strings in Emacs 18 or vectors in Emacs 19. The strings or vectors
2600 are reused for each iteration, so you must copy them if you wish to keep 2596 are reused for each iteration, so you must copy them if you wish to keep
2601 them permanently. You can add a @samp{using (key-bindings ...)} 2597 them permanently. You can add a @samp{using (key-bindings ...)}
2602 clause to get the command bindings as well. 2598 clause to get the command bindings as well.
2603 2599
2604 @item for @var{var} being the overlays [of @var{buffer}] @dots{} 2600 @item for @var{var} being the overlays [of @var{buffer}] @dots{}
2605 This clause iterates over the Emacs 19 ``overlays'' or Lucid 2601 This clause iterates over the Emacs 19 ``overlays'' or XEmacs
2606 Emacs ``extents'' of a buffer (the clause @code{extents} is synonymous 2602 ``extents'' of a buffer (the clause @code{extents} is synonymous with
2607 with @code{overlays}). Under Emacs 18, this clause iterates zero 2603 @code{overlays}). Under Emacs 18, this clause iterates zero times. If
2608 times. If the @code{of} term is omitted, the current buffer is used. 2604 the @code{of} term is omitted, the current buffer is used. This clause
2609 This clause also accepts optional @samp{from @var{pos}} and 2605 also accepts optional @samp{from @var{pos}} and @samp{to @var{pos}}
2610 @samp{to @var{pos}} terms, limiting the clause to overlays which 2606 terms, limiting the clause to overlays which overlap the specified
2611 overlap the specified region. 2607 region.
2612 2608
2613 @item for @var{var} being the intervals [of @var{buffer}] @dots{} 2609 @item for @var{var} being the intervals [of @var{buffer}] @dots{}
2614 This clause iterates over all intervals of a buffer with constant 2610 This clause iterates over all intervals of a buffer with constant
2615 text properties. The variable @var{var} will be bound to conses 2611 text properties. The variable @var{var} will be bound to conses
2616 of start and end positions, where one start position is always equal 2612 of start and end positions, where one start position is always equal
3215 Emacs 19. 3211 Emacs 19.
3216 3212
3217 @example 3213 @example
3218 (declaim (inline foo bar)) 3214 (declaim (inline foo bar))
3219 (eval-when (compile load eval) (proclaim '(inline foo bar))) 3215 (eval-when (compile load eval) (proclaim '(inline foo bar)))
3220 (proclaim-inline foo bar) ; Lucid Emacs only 3216 (proclaim-inline foo bar) ; XEmacs only
3221 (defsubst foo (...) ...) ; instead of defun; Emacs 19 only 3217 (defsubst foo (...) ...) ; instead of defun; Emacs 19 only
3222 @end example 3218 @end example
3223 3219
3224 @strong{Please note:} This declaration remains in effect after the 3220 @strong{Please note:} This declaration remains in effect after the
3225 containing source file is done. It is correct to use it to 3221 containing source file is done. It is correct to use it to
4599 4595
4600 @node Hash Tables, Structures, Lists, Top 4596 @node Hash Tables, Structures, Lists, Top
4601 @chapter Hash Tables 4597 @chapter Hash Tables
4602 4598
4603 @noindent 4599 @noindent
4600 Hash tables are now implemented directly in the C code and documented in
4601 @ref{Hash Tables,,, lispref, XEmacs Lisp Programmer's Manual}.
4602
4603 @ignore
4604 A @dfn{hash table} is a data structure that maps ``keys'' onto 4604 A @dfn{hash table} is a data structure that maps ``keys'' onto
4605 ``values.'' Keys and values can be arbitrary Lisp data objects. 4605 ``values.'' Keys and values can be arbitrary Lisp data objects.
4606 Hash tables have the property that the time to search for a given 4606 Hash tables have the property that the time to search for a given
4607 key is roughly constant; simpler data structures like association 4607 key is roughly constant; simpler data structures like association
4608 lists take time proportional to the number of entries in the list. 4608 lists take time proportional to the number of entries in the list.
4620 In this package, any reasonable predicate function will work, 4620 In this package, any reasonable predicate function will work,
4621 though if you use something else you should check the details of 4621 though if you use something else you should check the details of
4622 the hashing function described below to make sure it is suitable 4622 the hashing function described below to make sure it is suitable
4623 for your predicate. 4623 for your predicate.
4624 4624
4625 Some versions of Emacs (like Lucid Emacs 19) include a built-in 4625 Some versions of Emacs (like XEmacs) include a built-in hash
4626 hash table type; in these versions, @code{make-hash-table} with 4626 table type; in these versions, @code{make-hash-table} with a test of
4627 a test of @code{eq} will use these built-in hash tables. In all 4627 @code{eq}, @code{eql}, or @code{equal} will use these built-in hash
4628 other cases, it will return a hash-table object which takes the 4628 tables. In all other cases, it will return a hash-table object which
4629 form of a list with an identifying ``tag'' symbol at the front. 4629 takes the form of a list with an identifying ``tag'' symbol at the
4630 All of the hash table functions in this package can operate on 4630 front. All of the hash table functions in this package can operate on
4631 both types of hash table; normally you will never know which 4631 both types of hash table; normally you will never know which type is
4632 type is being used. 4632 being used.
4633 4633
4634 This function accepts the additional Common Lisp keywords 4634 This function accepts the additional Common Lisp keywords
4635 @code{:rehash-size} and @code{:rehash-threshold}, but it ignores 4635 @code{:rehash-size} and @code{:rehash-threshold}, but it ignores
4636 their values. 4636 their values.
4637 @end defun 4637 @end defun
4668 of the given entry. The return value of @var{function} is ignored; 4668 of the given entry. The return value of @var{function} is ignored;
4669 @var{maphash} itself returns @code{nil}. @xref{Loop Facility}, for 4669 @var{maphash} itself returns @code{nil}. @xref{Loop Facility}, for
4670 an alternate way of iterating over hash tables. 4670 an alternate way of iterating over hash tables.
4671 @end defun 4671 @end defun
4672 4672
4673 @defun hash-table-count table 4673 @defun hash-table-count table This function returns the number of
4674 This function returns the number of entries in @var{table}. 4674 entries in @var{table}. @strong{Warning:} The current implementation of
4675 @strong{Warning:} The current implementation of Lucid Emacs 19 4675 XEmacs hash-tables does not decrement the stored @code{count}
4676 hash-tables does not decrement the stored @code{count} when 4676 when @code{remhash} removes an entry. Therefore, the return value of
4677 @code{remhash} removes an entry. Therefore, the return value of 4677 this function is not dependable if you have used @code{remhash} on the
4678 this function is not dependable if you have used @code{remhash} 4678 table and the table's test is @code{eq}, @code{eql}, or @code{equal}.
4679 on the table and the table's test is @code{eq}. A slower, but 4679 A slower, but reliable, way to count the entries is
4680 reliable, way to count the entries is @code{(loop for x being the 4680 @code{(loop for x being the hash-keys of @var{table} count t)}.
4681 hash-keys of @var{table} count t)}. 4681 @end defun
4682 @end defun 4682
4683 4683 @defun hash-table-p object This function returns @code{t} if
4684 @defun hash-table-p object 4684 @var{object} is a hash table, @code{nil} otherwise. It recognizes both
4685 This function returns @code{t} if @var{object} is a hash table, 4685 types of hash tables (both XEmacs built-in tables and tables implemented
4686 @code{nil} otherwise. It recognizes both types of hash tables 4686 with special lists.)
4687 (both Lucid Emacs built-in tables and tables implemented with
4688 special lists.)
4689 @end defun 4687 @end defun
4690 4688
4691 Sometimes when dealing with hash tables it is useful to know the 4689 Sometimes when dealing with hash tables it is useful to know the
4692 exact ``hash function'' that is used. This package implements 4690 exact ``hash function'' that is used. This package implements
4693 hash tables using Emacs Lisp ``obarrays,'' which are the same 4691 hash tables using Emacs Lisp ``obarrays,'' which are the same
4743 list rather than an obarray of many lists. For very small tables this 4741 list rather than an obarray of many lists. For very small tables this
4744 structure will be more efficient since lookup does not require 4742 structure will be more efficient since lookup does not require
4745 converting the key to a string or looking it up in an obarray. 4743 converting the key to a string or looking it up in an obarray.
4746 However, such tables are guaranteed to take time proportional to 4744 However, such tables are guaranteed to take time proportional to
4747 their size to do a search. 4745 their size to do a search.
4746 @end ignore
4748 4747
4749 @iftex 4748 @iftex
4750 @chapno=18 4749 @chapno=18
4751 @end iftex 4750 @end iftex
4752 4751
5579 @example 5578 @example
5580 (mapcar #'(lambda (x) (* x 2)) list) ; Common Lisp 5579 (mapcar #'(lambda (x) (* x 2)) list) ; Common Lisp
5581 (mapcar (function (lambda (x) (* x 2))) list) ; Emacs Lisp 5580 (mapcar (function (lambda (x) (* x 2))) list) ; Emacs Lisp
5582 @end example 5581 @end example
5583 5582
5584 Lucid Emacs supports @code{#'} notation starting with version 19.8. 5583 XEmacs supports @code{#'} notation starting with version 19.8.
5585 5584
5586 @item 5585 @item
5587 Reader macros. Common Lisp includes a second type of macro that 5586 Reader macros. Common Lisp includes a second type of macro that
5588 works at the level of individual characters. For example, Common 5587 works at the level of individual characters. For example, Common
5589 Lisp implements the quote notation by a reader macro called @code{'}, 5588 Lisp implements the quote notation by a reader macro called @code{'},