⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cl.texinfo

📁 早期freebsd实现
💻 TEXINFO
📖 第 1 页 / 共 3 页
字号:
@itemx list-lengthVery standard utilities.  List* has proven especially useful toovercome the lack of a real @code{backquote}.  In addition, things thatusually required the relatively clumsy@example(cons 'a (cons 'b oldlist))(append (list a b) oldlist)@end examplecan now be simply put:@example(list* 'a 'b oldlist)@end exampleSee also @code{acons}.@item memberAnother well known function.  Supports test with @code{eql} only.@item acons@itemx pairlisThese two are part of the standards association lists implementation.  Iam leaving @code{sublis} as an exercise for the reader.@item adjoinDone mainly for the sake of @code{pushnew}.@item butlast@itemx last@itemx ldiffOccasionally useful ways to access the last cons or a specified tail ofa list.  I don't remember why there isn't a @code{tailp} here.@item c[ad][ad][ad][ad]r, up to four a's or d'sThese 28 functions (and their setf inverses) have been provided once andfor all.  Many packages contributed to Emacs Lisp contain macros thatimplement some of these, I think this code will make most of themunnecessary. @item first@itemx rest@itemx second@itemx third@itemx fourth@itemx fifth@itemx sixth@itemx seventh@itemx eighth@itemx ninth@itemx tenthMore standard accessors (and their setf inverses).  Not particularlyuseful but easy to provide.@item setnth@itemx setnthcdrThese functions are non-standard.  They are here for @code{defsetf}purposes only, but they might be useful on their own.@end table@node Sequences, Conditionals, Lists, Top@section SequencesSequences are partly supported in Emacs Lisp (see, for instance, the@code{elt} function).  This limited support is compatible with CommonLisp, so it should be easy to extend.  However, the lack ofkeyword arguments makes many of the functions impossible so far (but, asmentioned below, a basic framework for that extensionis provided here). @refillThe functionality really provided here is given by the functions(essentially, predicates) @code{every}, @code{some}, @code{notevery},@code{notany}.  I have found them useful countless times, so I thoughtto provide them before anything else. @refillThat still leaves many omissions, though.@subsection Features Provided@table @code@item every@itemx notany@itemx notevery@itemx someExtremely useful functions.  If your favorite Lisp doesn't have them,you are missing a lot.@item seteltA setf-inverse to @code{elt}.@item add-to-klist@itemx build-klist@itemx extract-from-klistA @dfn{klist} is just an alist whose keys are keywords.  I based thepseudo-keyword argument support of @code{defstruct} on this idea, buttheir best fit is here, as they could help to write the remainingsequence-handling functions (@code{find}, @code{substitute}, @dots{})that I didn't provide for the lack of a good keywordarguments mechanism. @refill@item elt-satisfies-if-not-p@itemx elt-satisfies-if-p@itemx elt-satisfies-test-p@itemx elts-match-under-klist-pThe Common Lisp book defines some of the semantics of sequence functionsin terms of satisfaction of certain tests.  These predicates providethat functionality, but I haven't integrated them with the rest of theextensions.  However, I thought it was better to include them anyway, asthey can serve somebody else as a starting point.@end table@node Conditionals, Iterations, Sequences, Top@section ConditionalsAn elementary incompatibility prevents us from producing true CommonLisp here.  The @code{if} forms are different.  In Emacs Lisp, @code{if}can take any number of subforms, there being a @var{condition} form, a@var{then} form, and after them any number of @var{else} subforms,which are executed in an implicit @code{progn}.  Moreover, that style iswidely used in the Emacs sources, so I thought most impractical to breakwith it to support Common Lisp's @code{if} (where only one @var{else} form istolerated).  For the most part, I use @code{cond} almost always, so itdoesn't bother me much.  If you use single-branch @code{if}s often,consider @code{when} or @code{unless} as alternatives.  @refill@code{case} and @code{ecase} are a convenient way to write things thatusually end up in a very baroque @code{cond}.  @subsection Features Provided@table @code@item MACRO case@itemx MACRO ecase@itemx MACRO unless@itemx MACRO whenThe standard stuff, completely implemented.@end table@node Iterations, Multiple Values, Conditionals, Top@section IterationsHaving a @code{do} macro was my original motivation.  The alternativesin standard Emacs Lisp are either expensive (recursion) or corresponddirectly to the expansion of my macros:@example (macroexpand '  (do ((i 0) (j 1 (+ 1 j)))      ((> j (foo i)) (cons i bar))    (setq i (baz i j))))(let ((i 0) (j 1))  (while (not (> j (foo i)))    (setq i (baz i j))    (psetq j (+ 1 j)))  (cons i bar))@end exampleSo I prefer to leave to the macros the problem of remembering thedetails right.The incompatibilities are due to the problems already discussed(@pxref{Generalities}, for more details). @refillIf you write Emacs Lisp code often, you will find enough uses for these.Examples are cooking up a translation table to move @key{C-s} out of theway of multiplexers, switches, concentrators and similar fauna, orbuilding keymaps.  @refill@subsection Features Provided@table @code@item MACRO do@itemx MACRO do*@itemx MACRO dolist@itemx MACRO dotimesThe standard, but for the lack of implicit blocks.@item MACRO loopThe basic standard one, not the fancy one.  As per the book, warns youabout atomic entries at the surface of the macro (to guarantee that thefancy @code{loop} macros can be made standard later).@item MACRO do-all-symbols@itemx MACRO do-symbolsThese operate on obarrays, the default is the current one.@end table@node Multiple Values, Integer Arithmetic, Iterations, Top@section Multiple ValuesThe multiple values mechanism covers (simply and elegantly, in myopinion) various common needs:@enumerate@itemThe case where a function returns a composite value, that has to beassembled in the callee and disassembled in the caller.  An example is@code{pair-with-newsyms}.@itemThe case where a function might cheaply compute redundant informationthat is useful to the caller only eventually.  For instance, routinesthat compute quotients and remainders together, whose callers might bemore often interested in just receiving the quotient.@itemThe case of functions that usually return a useful value, but might needto elaborate on occasion (say, returning a reason code too).@end enumerateThe general idea is that one such function @i{always} returns the extravalues, but only callers that are aware of this ability receive them.Unaware callers just receive the first value.I think my implementation is pretty much complete.  I am imposing nolimits on the number of multiple values a function may return, soI am not providing the constant @code{multiple-values-limit}.  You canassume multiple values are bound by the memory size only. @refill@subsection Features Provided@table @code@item values@itemx values-listThese are the forms that produce multiple values.@item MACRO multiple-value-bind@itemx MACRO multiple-value-call@itemx MACRO multiple-value-list@itemx MACRO multiple-value-prog1@itemx MACRO multiple-value-setqThese are the forms that receive multiple values.@item VARIABLE *mvalues-count*@itemx VARIABLE *mvalues-values*Used by the implementation.  Don't touch them!@end table@node Integer Arithmetic, Generalized Variables, Multiple Values, Top@section Integer ArithmeticI have provided most of the functions that are supposed to act onintegers.  Of those that take arbitrary numbers, I have implementedthose that have a reasonable implementation if restricted to integersonly, although some more could be added (like a restricted form of@code{expt}).Being a little worried about the bad fame that affects someimplementations of the '%' C operator, I have taken perhaps unnecessaryprecautions whenever integer division is concerned (see the function@code{safe-idiv}).  This should be of interest only when dividingnumbers that might be negative, but I have preferred here to be saferather than fast.  @refill@subsection Features Provided@table @code@item abs@itemx signumThe usual.@item gcd@itemx lcmThe usual.@item isqrtA rather annoying function.  Only use I can think of: to cut short aprime number sieve.@item evenp@itemx oddp@itemx plusp@itemx minuspA few predicates that use to come handy.@item ceiling@itemx floor@itemx round@itemx truncate@itemx mod@itemx remThe intention is to give everybody his preferred way to divide integers.I have tried not to depend on the unreliable semantics of C's integerdivision, I hope I got it right.  Read the code when in doubt.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -