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

📄 cl.texinfo

📁 早期freebsd实现
💻 TEXINFO
📖 第 1 页 / 共 3 页
字号:
@end table@node Generalized Variables, Structures, Integer Arithmetic, Top@section Generalized VariablesThis implementation has many limitations.  Take a look to see if youwant to overcome them, the fixes might prove unnecessarily expensive forEmacs purposes.  The ones I am clearly aware of:@enumerate@itemCommon Lisp suggests an underlying mechanism (the setf-methods) toimplement generalized variables.  I have used ad-hoc ideas that gave mea rather trivial implementation that suffers from some inflexibility.  As a result, @code{defsetf}only admits the simplest form and there is no @code{define-modify-macro}nor there are functions to handle the (nonexistent) setf-methods. @refill@itemI haven't implemented (I was uninterested) @code{getf} and friends.This shouldn't be hard.@end enumerateIn addition to providing this mechanism, I have written @code{defsetf}sfor almost every accessor I thought of.  There is room for improvementhere, as Emacs Lisp provides many types of its own (buffers, windows,keymaps, syntax tables, @dots{}) for which pairs of accessors andmutators could be defined.If you want to check whether a function has a setf-inversor, look at theproperty `:setf-update-fn' of its name.  This is a characteristic of myimplementation, not mandated by Common Lisp, so youshouldn't use it in code, but only to determine interactively what canbe setf'd.  @refill@subsection Features Provided@table @code@item MACRO setf@itemx MACRO psetfAlmost complete implementation.  @code{Setf} should handle @code{apply}inside itself and not in a @code{defsetf}, but the difference is sominute I feel lazy about fixing this. @code{Psetf} is the version wherethe assignments occur in parallel. @refill@item MACRO defsetfVery sketchy implementation.  I will appreciate if somebody puts sometime in implementing the whole works of setf-methods and such.@itemx MACRO incf@itemx MACRO decfThe usual and standard.@item MACRO pop@itemx MACRO push@itemx MACRO pushnewShould be the usual, but I haven't had the time to test them properly. @item MACRO rotatef@itemx MACRO shiftfVery fancy.  Good for implementing history rings and such.To swap two values, the following forms are equivalent:@example(rotatef a b)(psetf a b b a)(psetq a b b a)  ;not good for anything but variables@end example@end table@node Structures, Miscellanea, Generalized Variables, Top@section StructuresI haven't had the time to construct a complete implementation ofstructures, but the part provided should stand on its own for manypurposes.  I am not supporting `BOA constructors', nor typed slots (the@code{:type}, @code{:named} and @code{:initial-offset} options), norexplicit representational types.  The rest should bepretty much complete.  See the example file @file{fractions.el} for anidea of how complete the implementation is, and for exercises. @refillWhen writing these functions, I noticed I was incurring in lots ofauxiliaries.  I used dollar signs in their names, in the hope that thiscould prevent clashes with user functions.  In retrospect, I should havedone it in the other sections, too.@subsection Features Provided@table @code@item MACRO defstructCreate records (a la C structs) and use them as types in your programs.Almost completely standard.@item make$structure$instanceThis non-standard function implements most of the `guts' of the `make-'constructors.  It can be used as an example of the pseudokeyword-arguments.  @end table@node Miscellanea, To Do, Structures, Top@section Miscellanea@subsection Features Provided@table @code@item MACRO psetqA parallel-assignments version of @code{setq}, makes the expansions of@code{do} and @code{do*} be very similar, as they should.  Otherwiseused to swap two values, now superseded by @code{rotatef}. @refill@item duplicate-symbols-p@itemx pair-with-newsyms@itemx reassemble-argslists@itemx unzip-list@itemx zip-listsThese are utilities I find useful when parsing a call or generating codeinside a macro.  Non standard.@end table@node To Do, , Miscellanea, Top@section To DoNo doubt many people will like to extend the functionality of theseroutines.  When considering doing so, please try and do it in such a waythat your implementation of a subset of the functionality of Common Lispis not inimical with a more extensive or more correct one.  Fordefiniteness, ask yourself the questions:@itemize @bullet@itemWill my code run under a correct implementation of Common Lisp?@itemWill a correct implementation of Common Lisp run if my code is loaded?@end itemize@noindentThe first question tests the pertinence of your extensions.  The secondtries to discover ``extensions'' that prevent correct implementations ofother features.  Please tell me if you notice a case in which my codefails to pass any of those tests.The next subsections propose some more extensions.  I hope that they areattempted by people learning Lisp, as a way to enhance theirunderstanding.  Of course, experts are also admitted. @refill@subsection Keyword ArgumentsSome effort has been done to handle keywords almost right.  Forinstance, a structure constructor (@pxref{Structures}) can be invokedwith keyword arguments.Look for the functions whose names have a @samp{klist} in them.  Theywere written to facilitate parsing calls with keyword arguments, but Ihaven't done a complete implementation yet.  (Note that @code{member},@code{assoc} and perhaps some other function, have to be implementedindependently of the general framework.  More details by Email if youwant to try your hand at this.) @refill@subsection Mapping FunctionsThere is enough support to write @code{maplist}, @code{mapl}, etc.  EmacsLisp already provides some of the mapping functions, the trick now is tocode the rest in a very efficient manner, so there will be an incentiveto use @code{maplist} over an explicit iteration.  I have a draftimplementation, but I don't have the time to test it now.@subsection Complete the current implementationSome of the features described above are only a partial implementationof the Common Lisp features.  Things that cry for a more complete form:@table @code@item defsetfOnly the simplest format is supported.  The most general one is neededtoo.  Also, try to get @code{define-setf-method} and@code{get-setf-method} to work. @refill@item define-modify-macroSame as above.  The modify-macros provided are all ad hoc.@item defstructI think my version recognizes all the options and then proceeds toignore most of them.  Making sure that at least good error messages areproduced would be nice.  Also, what about BOA constructors?@end tableThere are other places where your programming ingenuity would help usall.  For instance, @code{subst}, @code{sublis} and the like could beeasily provided in the @var{lists} section.  (I haven't done it becauseI wanted to have the keyword arguments stuff first.) @refill@subsection Hash TablesA very simple implementation of hash tables would admit only strings askeys.  For each string and a given number of buckets (a prime isdesirable here), add the numeric values of all (or of a reasonablesubset) of the characters and assign the bucket whose index is theremainder of the sum modulo the (prime) number of buckets.A more convenient implementation can then be based on using@code{prin1-to-string} on an arbitrary Lisp object and using the outputstring as a key. This should make it easy to write @code{sxhash}.Remember that one needs to ensure that @code{(equal x y)} should implythat @w{@code{(= (sxhash x) (sxhash y))}}; and also that the keys arestate-less (so you can write them to a file and read them back later). @refillDon't forget to provide a @code{defsetf} for @code{gethash}.@subsection PackagesPackages should be easy to implement on top of a good hash tableimplementation, either by using it directly or by reusing some sharedcode.  Don't worry too much about efficiency: package qualification hasno run-time cost, only read- and print-time costs.The difficult thing is to integrate it correctly.  You have to replacethe built-in functions @code{read} and @code{write}.  This is not as badas writing a programmable reader, but still a pain.  For starters, yourroutines could remember the default definitions of the above mentionedfunctions: @refill@example(setf def-reader  (symbol-function 'read))(setf def-printer (symbol-function 'print))@dots{}@end exampleAnd then your specialized functions could just use @code{apply} toexercise the default ones, intercepting their activity in time to do thepackage qualification.  You might have to do this to @code{prin1},@code{prin1-to-string} and friends. @refill@subsection Streams and FilesThis is the first ``To Do'' that might require doing some C programming.The purpose is to construct an efficient byte stream abstraction thatwill allow Streams and Files to be handled.  Think of stdio, not UnixI/O, because Emacs already runs under other operating systems.  Also,think of doing it in a way that can be generalized easily (for instance,streams kept in memory without a file behind, streams as an interface toa windowing system, etc.)  Of course, the intended syntax is that ofCommon Lisp.@subsection Reader and PrinterThe Emacs Lisp reader (the C function @code{Fread}) is not reentrant norprogrammable.  It could be fixed as Lisp Code, but that is probablyuglily expensive (as bad as redoing @code{eval} and @code{apply} tosupport lexical scoping).  Doing this  extension is probably a badidea: a Common Lisp reader is incompatible with Emacs Lisp code (becauseof the @samp{?\} constructions) and the most important rule to keep inmind is that this code is running under Emacs, so the host shouldn't beburdened too much with these emulations.  Same goes for a more completeprinter (a Common Lisp @code{format} would be incompatible with theEmacs Lisp one). @refill@subsection BackquoteEven if the reader is not made programmable nor reentrant, a backquotingmechanism could come handy.  You need to study the way the currentreader does @code{quote} and hack from there.  This might be a moreworthwhile extension than the complete rewrite of the reader.@subsection Wild IdeasPerhaps there is a way to implement @code{block}, @code{tagbody},@code{return} and friends in spite of the dynamic scoping of Emacs Lisp.By this, I mean an adequate definition that preserves remotely theoriginal intent and still provides a sensible set of constructs.  Otherdynamically scoped Lisps have these features, so implementing them isnot necessarily impossible.In the same spirit of these extensions would be to provide a port ofsomething like Flavors (was there a PD version from Maryland, for Franz perhaps?) and thenrephrase the language of major and minor modes in an Object Orientedparadigm. @refillAlso, the rather gross @code{loop} macros that are out there in manyLisp systems could be helpful to somepeople (but then think of a @code{lisp-indent-hook} that handles themproperly). @refill@bye

⌨️ 快捷键说明

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