Mercurial > emacs
comparison man/cl.texi @ 88155:d7ddb3e565de
sync with trunk
author | Henrik Enberg <henrik.enberg@telia.com> |
---|---|
date | Mon, 16 Jan 2006 00:03:54 +0000 |
parents | 23a1cea22d13 |
children |
comparison
equal
deleted
inserted
replaced
88154:8ce476d3ba36 | 88155:d7ddb3e565de |
---|---|
3 @settitle Common Lisp Extensions | 3 @settitle Common Lisp Extensions |
4 | 4 |
5 @copying | 5 @copying |
6 This file documents the GNU Emacs Common Lisp emulation package. | 6 This file documents the GNU Emacs Common Lisp emulation package. |
7 | 7 |
8 Copyright (C) 1993, 2002 Free Software Foundation, Inc. | 8 Copyright (C) 1993, 2002, 2003, 2004, 2005 Free Software Foundation, Inc. |
9 | 9 |
10 @quotation | 10 @quotation |
11 Permission is granted to copy, distribute and/or modify this document | 11 Permission is granted to copy, distribute and/or modify this document |
12 under the terms of the GNU Free Documentation License, Version 1.1 or | 12 under the terms of the GNU Free Documentation License, Version 1.2 or |
13 any later version published by the Free Software Foundation; with no | 13 any later version published by the Free Software Foundation; with no |
14 Invariant Sections, with the Front-Cover texts being ``A GNU | 14 Invariant Sections, with the Front-Cover texts being ``A GNU |
15 Manual'', and with the Back-Cover Texts as in (a) below. A copy of the | 15 Manual'', and with the Back-Cover Texts as in (a) below. A copy of the |
16 license is included in the section entitled ``GNU Free Documentation | 16 license is included in the section entitled ``GNU Free Documentation |
17 License'' in the Emacs manual. | 17 License'' in the Emacs manual. |
48 @vskip 0pt plus 1filll | 48 @vskip 0pt plus 1filll |
49 @insertcopying | 49 @insertcopying |
50 @end titlepage | 50 @end titlepage |
51 | 51 |
52 @node Top, Overview, (dir), (dir) | 52 @node Top, Overview, (dir), (dir) |
53 @chapter Common Lisp Extensions | 53 @chapter Introduction |
54 | 54 |
55 @noindent | 55 @noindent |
56 This document describes a set of Emacs Lisp facilities borrowed from | 56 This document describes a set of Emacs Lisp facilities borrowed from |
57 Common Lisp. All the facilities are described here in detail. While | 57 Common Lisp. All the facilities are described here in detail. While |
58 this document does not assume any prior knowledge of Common Lisp, it | 58 this document does not assume any prior knowledge of Common Lisp, it |
80 * Function Index:: | 80 * Function Index:: |
81 * Variable Index:: | 81 * Variable Index:: |
82 @end menu | 82 @end menu |
83 | 83 |
84 @node Overview, Program Structure, Top, Top | 84 @node Overview, Program Structure, Top, Top |
85 @ifinfo | 85 @ifnottex |
86 @chapter Overview | 86 @chapter Overview |
87 @end ifinfo | 87 @end ifnottex |
88 @iftex | |
89 @section Overview | |
90 @end iftex | |
91 | 88 |
92 @noindent | 89 @noindent |
93 Common Lisp is a huge language, and Common Lisp systems tend to be | 90 Common Lisp is a huge language, and Common Lisp systems tend to be |
94 massive and extremely complex. Emacs Lisp, by contrast, is rather | 91 massive and extremely complex. Emacs Lisp, by contrast, is rather |
95 minimalist in the choice of Lisp features it offers the programmer. | 92 minimalist in the choice of Lisp features it offers the programmer. |
137 @end itemize | 134 @end itemize |
138 | 135 |
139 The package described here was written by Dave Gillespie, | 136 The package described here was written by Dave Gillespie, |
140 @file{daveg@@synaptics.com}. It is a total rewrite of the original | 137 @file{daveg@@synaptics.com}. It is a total rewrite of the original |
141 1986 @file{cl.el} package by Cesar Quiroz. Most features of the | 138 1986 @file{cl.el} package by Cesar Quiroz. Most features of the |
142 the Quiroz package have been retained; any incompatibilities are | 139 Quiroz package have been retained; any incompatibilities are |
143 noted in the descriptions below. Care has been taken in this | 140 noted in the descriptions below. Care has been taken in this |
144 version to ensure that each function is defined efficiently, | 141 version to ensure that each function is defined efficiently, |
145 concisely, and with minimal impact on the rest of the Emacs | 142 concisely, and with minimal impact on the rest of the Emacs |
146 environment. | 143 environment. |
147 | 144 |
737 The type symbol @code{null} represents the symbol @code{nil}. | 734 The type symbol @code{null} represents the symbol @code{nil}. |
738 Thus @code{(typep @var{object} 'null)} is equivalent to | 735 Thus @code{(typep @var{object} 'null)} is equivalent to |
739 @code{(null @var{object})}. | 736 @code{(null @var{object})}. |
740 | 737 |
741 @item | 738 @item |
739 The type symbol @code{atom} represents all objects that are not cons | |
740 cells. Thus @code{(typep @var{object} 'atom)} is equivalent to | |
741 @code{(atom @var{object})}. | |
742 | |
743 @item | |
742 The type symbol @code{real} is a synonym for @code{number}, and | 744 The type symbol @code{real} is a synonym for @code{number}, and |
743 @code{fixnum} is a synonym for @code{integer}. | 745 @code{fixnum} is a synonym for @code{integer}. |
744 | 746 |
745 @item | 747 @item |
746 The type symbols @code{character} and @code{string-char} match | 748 The type symbols @code{character} and @code{string-char} match |
992 @var{place} and @var{form} pairs, the assignments are done sequentially | 994 @var{place} and @var{form} pairs, the assignments are done sequentially |
993 just as with @code{setq}. @code{setf} returns the value of the last | 995 just as with @code{setq}. @code{setf} returns the value of the last |
994 @var{form}. | 996 @var{form}. |
995 | 997 |
996 The following Lisp forms will work as generalized variables, and | 998 The following Lisp forms will work as generalized variables, and |
997 so may legally appear in the @var{place} argument of @code{setf}: | 999 so may appear in the @var{place} argument of @code{setf}: |
998 | 1000 |
999 @itemize @bullet | 1001 @itemize @bullet |
1000 @item | 1002 @item |
1001 A symbol naming a variable. In other words, @code{(setf x y)} is | 1003 A symbol naming a variable. In other words, @code{(setf x y)} is |
1002 exactly equivalent to @code{(setq x y)}, and @code{setq} itself is | 1004 exactly equivalent to @code{(setq x y)}, and @code{setq} itself is |
1074 sequences of code when they are @code{setf}'d (@code{(narrow-to-region | 1076 sequences of code when they are @code{setf}'d (@code{(narrow-to-region |
1075 x (point-max))} in this case). | 1077 x (point-max))} in this case). |
1076 | 1078 |
1077 @item | 1079 @item |
1078 A call of the form @code{(substring @var{subplace} @var{n} [@var{m}])}, | 1080 A call of the form @code{(substring @var{subplace} @var{n} [@var{m}])}, |
1079 where @var{subplace} is itself a legal generalized variable whose | 1081 where @var{subplace} is itself a valid generalized variable whose |
1080 current value is a string, and where the value stored is also a | 1082 current value is a string, and where the value stored is also a |
1081 string. The new string is spliced into the specified part of the | 1083 string. The new string is spliced into the specified part of the |
1082 destination string. For example: | 1084 destination string. For example: |
1083 | 1085 |
1084 @example | 1086 @example |
2380 @result{} (0 1 2 3 4 5 6 7 8 9) | 2382 @result{} (0 1 2 3 4 5 6 7 8 9) |
2381 @end example | 2383 @end example |
2382 | 2384 |
2383 The @code{by} value is always positive, even for downward-counting | 2385 The @code{by} value is always positive, even for downward-counting |
2384 loops. Some sort of @code{from} value is required for downward | 2386 loops. Some sort of @code{from} value is required for downward |
2385 loops; @samp{for x downto 5} is not a legal loop clause all by | 2387 loops; @samp{for x downto 5} is not a valid loop clause all by |
2386 itself. | 2388 itself. |
2387 | 2389 |
2388 @item for @var{var} in @var{list} by @var{function} | 2390 @item for @var{var} in @var{list} by @var{function} |
2389 This clause iterates @var{var} over all the elements of @var{list}, | 2391 This clause iterates @var{var} over all the elements of @var{list}, |
2390 in turn. If you specify the @code{by} term, then @var{function} | 2392 in turn. If you specify the @code{by} term, then @var{function} |
2482 are also recognized but are equivalent to @code{symbols} in Emacs Lisp. | 2484 are also recognized but are equivalent to @code{symbols} in Emacs Lisp. |
2483 | 2485 |
2484 Due to a minor implementation restriction, it will not work to have | 2486 Due to a minor implementation restriction, it will not work to have |
2485 more than one @code{for} clause iterating over symbols, hash tables, | 2487 more than one @code{for} clause iterating over symbols, hash tables, |
2486 keymaps, overlays, or intervals in a given @code{loop}. Fortunately, | 2488 keymaps, overlays, or intervals in a given @code{loop}. Fortunately, |
2487 it would rarely if ever be useful to do so. It @emph{is} legal to mix | 2489 it would rarely if ever be useful to do so. It @emph{is} valid to mix |
2488 one of these types of clauses with other clauses like @code{for ... to} | 2490 one of these types of clauses with other clauses like @code{for ... to} |
2489 or @code{while}. | 2491 or @code{while}. |
2490 | 2492 |
2491 @item for @var{var} being the hash-keys of @var{hash-table} | 2493 @item for @var{var} being the hash-keys of @var{hash-table} |
2492 This clause iterates over the entries in @var{hash-table}. For each | 2494 This clause iterates over the entries in @var{hash-table}. For each |
2728 unnamed temporary variable. Also, @code{into} accumulations do | 2730 unnamed temporary variable. Also, @code{into} accumulations do |
2729 not automatically imply a return value. The loop must use some | 2731 not automatically imply a return value. The loop must use some |
2730 explicit mechanism, such as @code{finally return}, to return | 2732 explicit mechanism, such as @code{finally return}, to return |
2731 the accumulated result. | 2733 the accumulated result. |
2732 | 2734 |
2733 It is legal for several accumulation clauses of the same type to | 2735 It is valid for several accumulation clauses of the same type to |
2734 accumulate into the same place. From Steele: | 2736 accumulate into the same place. From Steele: |
2735 | 2737 |
2736 @example | 2738 @example |
2737 (loop for name in '(fred sue alice joe june) | 2739 (loop for name in '(fred sue alice joe june) |
2738 for kids in '((bob ken) () () (kris sunshine) ()) | 2740 for kids in '((bob ken) () () (kris sunshine) ()) |
3125 (declaim (inline foo bar)) | 3127 (declaim (inline foo bar)) |
3126 (eval-when (compile load eval) (proclaim '(inline foo bar))) | 3128 (eval-when (compile load eval) (proclaim '(inline foo bar))) |
3127 (defsubst foo (...) ...) ; instead of defun | 3129 (defsubst foo (...) ...) ; instead of defun |
3128 @end example | 3130 @end example |
3129 | 3131 |
3130 @strong{Note:} This declaration remains in effect after the | 3132 @strong{Please note:} this declaration remains in effect after the |
3131 containing source file is done. It is correct to use it to | 3133 containing source file is done. It is correct to use it to |
3132 request that a function you have defined should be inlined, | 3134 request that a function you have defined should be inlined, |
3133 but it is impolite to use it to request inlining of an external | 3135 but it is impolite to use it to request inlining of an external |
3134 function. | 3136 function. |
3135 | 3137 |
3249 | 3251 |
3250 @example | 3252 @example |
3251 (get sym prop) @equiv{} (getf (symbol-plist sym) prop) | 3253 (get sym prop) @equiv{} (getf (symbol-plist sym) prop) |
3252 @end example | 3254 @end example |
3253 | 3255 |
3254 It is legal to use @code{getf} as a @code{setf} place, in which case | 3256 It is valid to use @code{getf} as a @code{setf} place, in which case |
3255 its @var{place} argument must itself be a legal @code{setf} place. | 3257 its @var{place} argument must itself be a valid @code{setf} place. |
3256 The @var{default} argument, if any, is ignored in this context. | 3258 The @var{default} argument, if any, is ignored in this context. |
3257 The effect is to change (via @code{setcar}) the value cell in the | 3259 The effect is to change (via @code{setcar}) the value cell in the |
3258 list that corresponds to @var{property}, or to cons a new property-value | 3260 list that corresponds to @var{property}, or to cons a new property-value |
3259 pair onto the list if the property is not yet present. | 3261 pair onto the list if the property is not yet present. |
3260 | 3262 |
3536 date and time. As an extension to Common Lisp, @var{state} may also | 3538 date and time. As an extension to Common Lisp, @var{state} may also |
3537 be an integer in which case the new object is seeded from that | 3539 be an integer in which case the new object is seeded from that |
3538 integer; each different integer seed will result in a completely | 3540 integer; each different integer seed will result in a completely |
3539 different sequence of random numbers. | 3541 different sequence of random numbers. |
3540 | 3542 |
3541 It is legal to print a @code{random-state} object to a buffer or | 3543 It is valid to print a @code{random-state} object to a buffer or |
3542 file and later read it back with @code{read}. If a program wishes | 3544 file and later read it back with @code{read}. If a program wishes |
3543 to use a sequence of pseudo-random numbers which can be reproduced | 3545 to use a sequence of pseudo-random numbers which can be reproduced |
3544 later for debugging, it can call @code{(make-random-state t)} to | 3546 later for debugging, it can call @code{(make-random-state t)} to |
3545 get a new sequence, then print this sequence to a file. When the | 3547 get a new sequence, then print this sequence to a file. When the |
3546 program is later rerun, it can read the original run's random-state | 3548 program is later rerun, it can read the original run's random-state |
4576 The argument names should match the slot names; each slot is | 4578 The argument names should match the slot names; each slot is |
4577 initialized from the corresponding argument. Slots whose names | 4579 initialized from the corresponding argument. Slots whose names |
4578 do not appear in the argument list are initialized based on the | 4580 do not appear in the argument list are initialized based on the |
4579 @var{default-value} in their slot descriptor. Also, @code{&optional} | 4581 @var{default-value} in their slot descriptor. Also, @code{&optional} |
4580 and @code{&key} arguments which don't specify defaults take their | 4582 and @code{&key} arguments which don't specify defaults take their |
4581 defaults from the slot descriptor. It is legal to include arguments | 4583 defaults from the slot descriptor. It is valid to include arguments |
4582 which don't correspond to slot names; these are useful if they are | 4584 which don't correspond to slot names; these are useful if they are |
4583 referred to in the defaults for optional, keyword, or @code{&aux} | 4585 referred to in the defaults for optional, keyword, or @code{&aux} |
4584 arguments which @emph{do} correspond to slots. | 4586 arguments which @emph{do} correspond to slots. |
4585 | 4587 |
4586 You can specify any number of full-format @code{:constructor} | 4588 You can specify any number of full-format @code{:constructor} |
5145 remaining differences between Emacs Lisp and Common Lisp make it | 5147 remaining differences between Emacs Lisp and Common Lisp make it |
5146 difficult to port large Common Lisp applications to Emacs. For | 5148 difficult to port large Common Lisp applications to Emacs. For |
5147 one, some of the features in this package are not fully compliant | 5149 one, some of the features in this package are not fully compliant |
5148 with ANSI or Steele; @pxref{Common Lisp Compatibility}. But there | 5150 with ANSI or Steele; @pxref{Common Lisp Compatibility}. But there |
5149 are also quite a few features that this package does not provide | 5151 are also quite a few features that this package does not provide |
5150 at all. Here are some major omissions that you will want watch out | 5152 at all. Here are some major omissions that you will want to watch out |
5151 for when bringing Common Lisp code into Emacs. | 5153 for when bringing Common Lisp code into Emacs. |
5152 | 5154 |
5153 @itemize @bullet | 5155 @itemize @bullet |
5154 @item | 5156 @item |
5155 Case-insensitivity. Symbols in Common Lisp are case-insensitive | 5157 Case-insensitivity. Symbols in Common Lisp are case-insensitive |
5359 @printindex vr | 5361 @printindex vr |
5360 | 5362 |
5361 @setchapternewpage odd | 5363 @setchapternewpage odd |
5362 @contents | 5364 @contents |
5363 @bye | 5365 @bye |
5366 | |
5367 @ignore | |
5368 arch-tag: b61e7200-3bfa-4a70-a9d3-095e152696f8 | |
5369 @end ignore |