词条 | Common Lisp |
释义 |
| name = Common Lisp | family = Lisp | paradigm = Multi-paradigm: procedural, functional, object-oriented, meta, reflective, generic | generation = 3GL | released = 1984, 1994 for ANSI Common Lisp | designer = Scott Fahlman, Richard P. Gabriel, David A. Moon, Kent Pitman, Guy Steele, Dan Weinreb | developer = ANSI X3J13 committee | standard reference = Common Lisp HyperSpec | latest release version = | latest release date = | typing = dynamic, strong | scope = lexical, optionally dynamic | namespace style = Lisp-2 | implementations = Allegro CL, ABCL, CLISP, Clozure CL, CMUCL, ECL, GCL, LispWorks, Scieneer CL, SBCL, Symbolics Common Lisp | dialects = CLtL1, CLtL2, ANSI Common Lisp | influenced_by = Lisp, Lisp Machine Lisp, Maclisp, Scheme, Interlisp | influenced = Clojure, Dylan, Emacs Lisp, EuLisp, ISLISP, Julia, Moose, R, SKILL, SubL | operating_system = Cross-platform | license = | website = {{URL|http://common-lisp.net/}} | file_ext = .lisp, .lsp, .l, .cl, .fasl }}Common Lisp (CL) is a dialect of the Lisp programming language, published in ANSI standard document ANSI INCITS 226-1994 (R2004) (formerly X3.226-1994 (R1999)).[1] The Common Lisp HyperSpec, a hyperlinked HTML version, has been derived from the ANSI Common Lisp standard.[2] The Common Lisp language was developed as a standardized and improved successor of Maclisp. By the early 1980s several groups were already at work on diverse successors to MacLisp: Lisp Machine Lisp (aka ZetaLisp), Spice Lisp, NIL and S-1 Lisp. Common Lisp sought to unify, standardise, and extend the features of these MacLisp dialects. Common Lisp is not an implementation, but rather a language specification.[3] Several implementations of the Common Lisp standard are available, including free and open-source software and proprietary products.[4] Common Lisp is a general-purpose, multi-paradigm programming language. It supports a combination of procedural, functional, and object-oriented programming paradigms. As a dynamic programming language, it facilitates evolutionary and incremental software development, with iterative compilation into efficient run-time programs. This incremental development is often done interactively without interrupting the running application. It also supports optional type annotation and casting, which can be added as necessary at the later profiling and optimization stages, to permit the compiler to generate more efficient code. For instance, Common Lisp includes CLOS, an object system that supports multimethods and method combinations. It is often implemented with a Metaobject Protocol. Common Lisp is extensible through standard features such as Lisp macros (code transformations) and reader macros (input parsers for characters). Common Lisp provides some backwards compatibility to Maclisp and to John McCarthy's original Lisp. This allows older Lisp software to be ported to Common Lisp.[5] HistoryWork on Common Lisp started in 1981 after an initiative by ARPA manager Bob Engelmore to develop a single community standard Lisp dialect.[6] Much of the initial language design was done via electronic mail.[7][8] In 1982, Guy L. Steele, Jr. gave the first overview of Common Lisp at the 1982 ACM Symposium on LISP and functional programming.[9] The first language documentation was published 1984 as Common Lisp the Language, first edition. A second edition, published in 1990, incorporated many changes to the language, made during the ANSI Common Lisp standardization process. The final ANSI Common Lisp standard then was published in 1994. Since then no update to the standard has been published. Various extensions and improvements to Common Lisp (examples are Unicode, Concurrency, CLOS-based IO) have been provided by implementations and libraries (many available via Quicklisp). {{Lisp}}SyntaxCommon Lisp is a dialect of Lisp. It uses S-expressions to denote both code and data structure. Function calls, macro forms and special forms are written as lists, with the name of the operator first, as in these examples: Data typesCommon Lisp has many data types. Scalar typesNumber types include integers, ratios, floating-point numbers, and complex numbers.[10] Common Lisp uses bignums to represent numerical values of arbitrary size and precision. The ratio type represents fractions exactly, a facility not available in many languages. Common Lisp automatically coerces numeric values among these types as appropriate. The Common Lisp character type is not limited to ASCII characters. Most modern implementations allow Unicode characters.[11] The symbol type is common to Lisp languages, but largely unknown outside them. A symbol is a unique, named data object with several parts: name, value, function, property list and package. Of these, value cell and function cell are the most important. Symbols in Lisp are often used similarly to identifiers in other languages: to hold the value of a variable; however there are many other uses. Normally, when a symbol is evaluated, its value is returned. Some symbols evaluate to themselves, for example all symbols in the keyword package are self-evaluating. Boolean values in Common Lisp are represented by the self-evaluating symbols T and NIL. Common Lisp has namespaces for symbols, called 'packages'. A number of functions are available for rounding scalar numeric values in various ways. The function Data structuresSequence types in Common Lisp include lists, vectors, bit-vectors, and strings. There are many operations that can work on any sequence type. As in almost all other Lisp dialects, lists in Common Lisp are composed of conses, sometimes called cons cells or pairs. A cons is a data structure with two slots, called its car and cdr. A list is a linked chain of conses or the empty list. Each cons's car refers to a member of the list (possibly another list). Each cons's cdr refers to the next cons—except for the last cons in a list, whose cdr refers to the Common Lisp supports multidimensional arrays, and can dynamically resize adjustable arrays if required. Multidimensional arrays can be used for matrix mathematics. A vector is a one-dimensional array. Arrays can carry any type as members (even mixed types in the same array) or can be specialized to contain a specific type of members, as in a vector of bits. Usually only a few types are supported. Many implementations can optimize array functions when the array used is type-specialized. Two type-specialized array types are standard: a string is a vector of characters, while a bit-vector is a vector of bits. Hash tables store associations between data objects. Any object may be used as key or value. Hash tables are automatically resized as needed. Packages are collections of symbols, used chiefly to separate the parts of a program into namespaces. A package may export some symbols, marking them as part of a public interface. Packages can use other packages. Structures, similar in use to C structs and Pascal records, represent arbitrary complex data structures with any number and type of fields (called slots). Structures allow single-inheritance. Classes are similar to structures, but offer more dynamic features and multiple-inheritance. (See CLOS). Classes have been added late to Common Lisp and there is some conceptual overlap with structures. Objects created of classes are called Instances. A special case are Generic Functions. Generic Functions are both functions and instances. FunctionsCommon Lisp supports first-class functions. For instance, it is possible to write functions that take other functions as arguments or return functions as well. This makes it possible to describe very general operations. The Common Lisp library relies heavily on such higher-order functions. For example, the The evaluation model for functions is very simple. When the evaluator encounters a form
If f is the name of a function, then the arguments a1, a2, ..., an are evaluated in left-to-right order, and the function is found and invoked with those values supplied as parameters. Defining functionsThe macro Function definitions may include compiler directives, known as declarations, which provide hints to the compiler about optimization settings or the data types of arguments. They may also include documentation strings (docstrings), which the Lisp system may use to provide interactive documentation: Anonymous functions (function literals) are defined using Local functions can be defined with There are a number of other operators related to the definition and manipulation of functions. For instance, a function may be compiled with the Defining generic functions and methodsThe macro The macro Methods can specialize their parameters over CLOS standard classes, system classes, structure classes or objects. For many types there are corresponding system classes. When a generic function is called, multiple-dispatch will determine the effective method to use. Generic Functions are also a first class data type. There are many more features to Generic Functions and Methods than described above. The function namespaceThe namespace for function names is separate from the namespace for data variables. This is a key difference between Common Lisp and Scheme. For Common Lisp, operators that define names in the function namespace include To pass a function by name as an argument to another function, one must use the Scheme's evaluation model is simpler: there is only one namespace, and all positions in the form are evaluated (in any order) -- not just the arguments. Code written in one dialect is therefore sometimes confusing to programmers more experienced in the other. For instance, many Common Lisp programmers like to use descriptive variable names such as list or string which could cause problems in Scheme, as they would locally shadow function names. Whether a separate namespace for functions is an advantage is a source of contention in the Lisp community. It is usually referred to as the Lisp-1 vs. Lisp-2 debate. Lisp-1 refers to Scheme's model and Lisp-2 refers to Common Lisp's model. These names were coined in a 1988 paper by Richard P. Gabriel and Kent Pitman, which extensively compares the two approaches.[12] Multiple return valuesCommon Lisp supports the concept of multiple values,[13] where any expression always has a single primary value, but it might also have any number of secondary values, which might be received and inspected by interested callers. This concept is distinct from returning a list value, as the secondary values are fully optional, and passed via a dedicated side channel. This means that callers may remain entirely unaware of the secondary values being there if they have no need for them, and it makes it convenient to use the mechanism for communicating information that is sometimes useful, but not always necessary. For example,
(let ((x 1266778) (y 458)) (multiple-value-bind (quotient remainder) (truncate x y) (format nil "~A divided by ~A is ~A remainder ~A" x y quotient remainder)))
(defun get-answer (library) (defun the-answer-1 (library)
(defun the-answer-2 (library) (multiple-value-bind (answer sure-p) (get-answer library) (if (not sure-p) "I don't know" (format nil "The answer is ~A" answer))))
Multiple values are supported by a handful of standard forms, most common of which are the (defun magic-eight-ball () "Return an outlook prediction, with the probability as a secondary value" (values "Outlook good" (random 1.0)))
Other typesOther data types in Common Lisp include:
ScopeLike programs in many other programming languages, Common Lisp programs make use of names to refer to variables, functions, and many other kinds of entities. Named references are subject to scope. The association between a name and the entity which the name refers to is called a binding. Scope refers to the set of circumstances in which a name is determined to have a particular binding. Determiners of scopeThe circumstances which determine scope in Common Lisp include:
To understand what a symbol refers to, the Common Lisp programmer must know what kind of reference is being expressed, what kind of scope it uses if it is a variable reference (dynamic versus lexical scope), and also the run-time situation: in what environment is the reference resolved, where was the binding introduced into the environment, et cetera. Kinds of environmentGlobalSome environments in Lisp are globally pervasive. For instance, if a new type is defined, it is known everywhere thereafter. References to that type look it up in this global environment. DynamicOne type of environment in Common Lisp is the dynamic environment. Bindings established in this environment have dynamic extent, which means that a binding is established at the start of the execution of some construct, such as a Common Lisp has support for dynamically scoped variables, which are also called special variables. Certain other kinds of bindings are necessarily dynamically scoped also, such as restarts and catch tags. Function bindings cannot be dynamically scoped using Dynamic scope is extremely useful because it adds referential clarity and discipline to global variables. Global variables are frowned upon in computer science as potential sources of error, because they can give rise to ad-hoc, covert channels of communication among modules that lead to unwanted, surprising interactions. In Common Lisp, a special variable which has only a top-level binding behaves just like a global variable in other programming languages. A new value can be stored into it, and that value simply replaces what is in the top-level binding. Careless replacement of the value of a global variable is at the heart of bugs caused by use of global variables. However, another way to work with a special variable is to give it a new, local binding within an expression. This is sometimes referred to as "rebinding" the variable. Binding a dynamically scoped variable temporarily creates a new memory location for that variable, and associates the name with that location. While that binding is in effect, all references to that variable refer to the new binding; the previous binding is hidden. When execution of the binding expression terminates, the temporary memory location is gone, and the old binding is revealed, with the original value intact. Of course, multiple dynamic bindings for the same variable can be nested. In Common Lisp implementations which support multithreading, dynamic scopes are specific to each thread of execution. Thus special variables serve as an abstraction for thread local storage. If one thread rebinds a special variable, this rebinding has no effect on that variable in other threads. The value stored in a binding can only be retrieved by the thread which created that binding. If each thread binds some special variable Dynamic variables can be used to extend the execution context with additional context information which is implicitly passed from function to function without having to appear as an extra function parameter. This is especially useful when the control transfer has to pass through layers of unrelated code, which simply cannot be extended with extra parameters to pass the additional data. A situation like this usually calls for a global variable. That global variable must be saved and restored, so that the scheme doesn't break under recursion: dynamic variable rebinding takes care of this. And that variable must be made thread-local (or else a big mutex must be used) so the scheme doesn't break under threads: dynamic scope implementations can take care of this also. In the Common Lisp library, there are many standard special variables. For instance, all standard I/O streams are stored in the top-level bindings of well-known special variables. The standard output stream is stored in *standard-output*. Suppose a function foo writes to standard output: To capture its output in a character string, *standard-output* can be bound to a string stream and called: LexicalCommon Lisp supports lexical environments. Formally, the bindings in a lexical environment have lexical scope and may have either indefinite extent or dynamic extent, depending on the type of namespace. Lexical scope means that visibility is physically restricted to the block in which the binding is established. References which are not textually (i.e. lexically) embedded in that block simply do not see that binding. The tags in a TAGBODY have lexical scope. The expression (GO X) is erroneous if it is not actually embedded in a TAGBODY which contains a label X. However, the label bindings disappear when the TAGBODY terminates its execution, because they have dynamic extent. If that block of code is re-entered by the invocation of a lexical closure, it is invalid for the body of that closure to try to transfer control to a tag via GO: When the TAGBODY is executed, it first evaluates the setf form which stores a function in the special variable *stashed*. Then the (go end-label) transfers control to end-label, skipping the code (print "Hello"). Since end-label is at the end of the tagbody, the tagbody terminates, yielding NIL. Suppose that the previously remembered function is now called: This situation is erroneous. One implementation's response is an error condition containing the message, "GO: tagbody for tag SOME-LABEL has already been left". The function tried to evaluate (go some-label), which is lexically embedded in the tagbody, and resolves to the label. However, the tagbody isn't executing (its extent has ended), and so the control transfer cannot take place. Local function bindings in Lisp have lexical scope, and variable bindings also have lexical scope by default. By contrast with GO labels, both of these have indefinite extent. When a lexical function or variable binding is established, that binding continues to exist for as long as references to it are possible, even after the construct which established that binding has terminated. References to lexical variables and functions after the termination of their establishing construct are possible thanks to lexical closures. Lexical binding is the default binding mode for Common Lisp variables. For an individual symbol, it can be switched to dynamic scope, either by a local declaration, by a global declaration. The latter may occur implicitly through the use of a construct like DEFVAR or DEFPARAMETER. It is an important convention in Common Lisp programming that special (i.e. dynamically scoped) variables have names which begin and end with an asterisk sigil Lexical scope is useful for several reasons. Firstly, references to variables and functions can be compiled to efficient machine code, because the run-time environment structure is relatively simple. In many cases it can be optimized to stack storage, so opening and closing lexical scopes has minimal overhead. Even in cases where full closures must be generated, access to the closure's environment is still efficient; typically each variable becomes an offset into a vector of bindings, and so a variable reference becomes a simple load or store instruction with a base-plus-offset addressing mode. Secondly, lexical scope (combined with indefinite extent) gives rise to the lexical closure, which in turn creates a whole paradigm of programming centered around the use of functions being first-class objects, which is at the root of functional programming. Thirdly, perhaps most importantly, even if lexical closures are not exploited, the use of lexical scope isolates program modules from unwanted interactions. Due to their restricted visibility, lexical variables are private. If one module A binds a lexical variable X, and calls another module B, references to X in B will not accidentally resolve to the X bound in A. B simply has no access to X. For situations in which disciplined interactions through a variable are desirable, Common Lisp provides special variables. Special variables allow for a module A to set up a binding for a variable X which is visible to another module B, called from A. Being able to do this is an advantage, and being able to prevent it from happening is also an advantage; consequently, Common Lisp supports both lexical and dynamic scope. MacrosA macro in Lisp superficially resembles a function in usage. However, rather than representing an expression which is evaluated, it represents a transformation of the program source code. The macro gets the source it surrounds as arguments, binds them to its parameters and computes a new source form. This new form can also use a macro. The macro expansion is repeated until the new source form does not use a macro. The final computed form is the source code executed at runtime. Typical uses of macros in Lisp:
Various standard Common Lisp features also need to be implemented as macros, such as:
Macros are defined by the defmacro macro. The special operator macrolet allows the definition of local (lexically scoped) macros. It is also possible to define macros for symbols using define-symbol-macro and symbol-macrolet. Paul Graham's book On Lisp describes the use of macros in Common Lisp in detail. Doug Hoyte's book Let Over Lambda extends the discussion on macros, claiming "Macros are the single greatest advantage that lisp has as a programming language and the single greatest advantage of any programming language." Hoyte provides several examples of iterative development of macros. Example using a macro to define a new control structureMacros allow Lisp programmers to create new syntactic forms in the language. One typical use is to create new control structures. The example macro provides an The macro definition for until: tagbody is a primitive Common Lisp special operator which provides the ability to name tags and use the go form to jump to those tags. The backquote ` provides a notation that provides code templates, where the value of forms preceded with a comma are filled in. Forms preceded with comma and at-sign are spliced in. The tagbody form tests the end condition. If the condition is true, it jumps to the end tag. Otherwise the provided body code is executed and then it jumps to the start tag. An example form using above until macro: The code can be expanded using the function macroexpand-1. The expansion for above example looks like this: During macro expansion the value of the variable test is (= (random 10) 0) and the value of the variable body is ((write-line "Hello")). The body is a list of forms. Symbols are usually automatically upcased. The expansion uses the TAGBODY with two labels. The symbols for these labels are computed by GENSYM and are not interned in any package. Two go forms use these tags to jump to. Since tagbody is a primitive operator in Common Lisp (and not a macro), it will not be expanded into something else. The expanded form uses the when macro, which also will be expanded. Fully expanding a source form is called code walking. In the fully expanded (walked) form, the when form is replaced by the primitive if: All macros must be expanded before the source code containing them can be evaluated or compiled normally. Macros can be considered functions that accept and return S-expressions - similar to abstract syntax trees, but not limited to those. These functions are invoked before the evaluator or compiler to produce the final source code. Macros are written in normal Common Lisp, and may use any Common Lisp (or third-party) operator available. Variable capture and shadowingCommon Lisp macros are capable of what is commonly called variable capture, where symbols in the macro-expansion body coincide with those in the calling context, allowing the programmer to create macros wherein various symbols have special meaning. The term variable capture is somewhat misleading, because all namespaces are vulnerable to unwanted capture, including the operator and function namespace, the tagbody label namespace, catch tag, condition handler and restart namespaces. Variable capture can introduce software defects. This happens in one of the following two ways:
The Scheme dialect of Lisp provides a macro-writing system which provides the referential transparency that eliminates both types of capture problem. This type of macro system is sometimes called "hygienic", in particular by its proponents (who regard macro systems which do not automatically solve this problem as unhygienic). {{Citation needed|date=May 2011}} In Common Lisp, macro hygiene is ensured one of two different ways. One approach is to use gensyms: guaranteed-unique symbols which can be used in a macro-expansion without threat of capture. The use of gensyms in a macro definition is a manual chore, but macros can be written which simplify the instantiation and use of gensyms. Gensyms solve type 2 capture easily, but they are not applicable to type 1 capture in the same way, because the macro expansion cannot rename the interfering symbols in the surrounding code which capture its references. Gensyms could be used to provide stable aliases for the global symbols which the macro expansion needs. The macro expansion would use these secret aliases rather than the well-known names, so redefinition of the well-known names would have no ill effect on the macro. Another approach is to use packages. A macro defined in its own package can simply use internal symbols in that package in its expansion. The use of packages deals with type 1 and type 2 capture. However, packages don't solve the type 1 capture of references to standard Common Lisp functions and operators. The reason is that the use of packages to solve capture problems revolves around the use of private symbols (symbols in one package, which are not imported into, or otherwise made visible in other packages). Whereas the Common Lisp library symbols are external, and frequently imported into or made visible in user-defined packages. The following is an example of unwanted capture in the operator namespace, occurring in the expansion of a macro: The Common Lisp solves the problem of the shadowing of standard operators and functions by forbidding their redefinition. Because it redefines the standard operator Condition systemThe condition system is responsible for exception handling in Common Lisp.[17] It provides conditions, handlers and restarts. Conditions are objects describing an exceptional situation (for example an error). If a condition is signaled, the Common Lisp system searches for a handler for this condition type and calls the handler. The handler can now search for restarts and use one of these restarts to automatically repair the current problem, using information such as the condition type and any relevant information provided as part of the condition object, and call the appropriate restart function. These restarts, if unhandled by code, can be presented to users (as part of a user interface, that of a debugger for example), so that the user can select and invoke one of the available restarts. Since the condition handler is called in the context of the error (without unwinding the stack), full error recovery is possible in many cases, where other exception handling systems would have already terminated the current routine. The debugger itself can also be customized or replaced using the In the following example (using Symbolics Genera) the user tries to open a file in a Lisp function test called from the Read-Eval-Print-LOOP (REPL), when the file does not exist. The Lisp system presents four restarts. The user selects the Retry OPEN using a different pathname restart and enters a different pathname (lispm-init.lisp instead of lispm-int.lisp). The user code does not contain any error handling code. The whole error handling and restart code is provided by the Lisp system, which can handle and repair the error without terminating the user code. Common Lisp Object System (CLOS){{Main|Common Lisp Object System}}Common Lisp includes a toolkit for object-oriented programming, the Common Lisp Object System or CLOS, which is one of the most powerful object systems available in any language. For example, Peter Norvig explains how many Design Patterns are simpler to implement in a dynamic language with the features of CLOS (Multiple Inheritance, Mixins, Multimethods, Metaclasses, Method combinations, etc.).[18] Several extensions to Common Lisp for object-oriented programming have been proposed to be included into the ANSI Common Lisp standard, but eventually CLOS was adopted as the standard object-system for Common Lisp. CLOS is a dynamic object system with multiple dispatch and multiple inheritance, and differs radically from the OOP facilities found in static languages such as C++ or Java. As a dynamic object system, CLOS allows changes at runtime to generic functions and classes. Methods can be added and removed, classes can be added and redefined, objects can be updated for class changes and the class of objects can be changed. CLOS has been integrated into ANSI Common Lisp. Generic functions can be used like normal functions and are a first-class data type. Every CLOS class is integrated into the Common Lisp type system. Many Common Lisp types have a corresponding class. There is more potential use of CLOS for Common Lisp. The specification does not say whether conditions are implemented with CLOS. Pathnames and streams could be implemented with CLOS. These further usage possibilities of CLOS for ANSI Common Lisp are not part of the standard. Actual Common Lisp implementations use CLOS for pathnames, streams, input–output, conditions, the implementation of CLOS itself and more. Compiler and interpreterSeveral implementations of earlier Lisp dialects provided both an interpreter and a compiler. Unfortunately often the semantics were different. These earlier Lisps implemented lexical scoping in the compiler and dynamic scoping in the interpreter. Common Lisp requires that both the interpreter and compiler use lexical scoping by default. The Common Lisp standard describes both the semantics of the interpreter and a compiler. The compiler can be called using the function compile for individual functions and using the function compile-file for files. Common Lisp allows type declarations and provides ways to influence the compiler code generation policy. For the latter various optimization qualities can be given values between 0 (not important) and 3 (most important): speed, space, safety, debug and compilation-speed. There is also a function to evaluate Lisp code: The file compiler is invoked using the function compile-file. The generated file with compiled code is called a fasl (from fast load) file. These fasl files and also source code files can be loaded with the function load into a running Common Lisp system. Depending on the implementation, the file compiler generates byte-code (for example for the Java Virtual Machine), C language code (which then is compiled with a C compiler) or, directly, native code. Common Lisp implementations can be used interactively, even though the code gets fully compiled. The idea of an Interpreted language thus does not apply for interactive Common Lisp. The language makes distinction between read-time, compile-time, load-time and run-time, and allows user code to also make this distinction to perform the wanted type of processing at the wanted step. Some special operators are provided to especially suit interactive development; for instance, Some features are also provided to help writing compilers and interpreters. Symbols consist of first-level objects and are directly manipulable by user code. The Code examplesBirthday paradoxThe following program calculates the smallest number of people in a room for whom the probability of completely unique birthdays is less than 50% (the birthday paradox, where for 1 person the probability is obviously 100%, for 2 it is 364/365, etc.). The answer is 23. By convention, constants in Common Lisp are enclosed with + characters. Calling the example function using the REPL (Read Eval Print Loop): Sorting a list of person objectsWe define a class Next we define a group of persons as a list of Then we iterate over the sorted list. It prints the three names with descending age. Exponentiating by squaringUse of the LOOP macro is demonstrated: Example use: Compare with the built in exponentiation: Find the list of available shellsWITH-OPEN-FILE is a macro that opens a file and provides a stream. When the form is returning, the file is automatically closed. FUNCALL calls a function object. The LOOP collects all lines that match the predicate. The function AVAILABLE-SHELLS calls above function LIST-MATCHING-LINES with a pathname and an anonymous function as the predicate. The predicate returns the pathname of a shell or NIL (if the string is not the filename of a shell). Example results (on Mac OS X 10.6): Comparison with other LispsCommon Lisp is most frequently compared with, and contrasted to, Scheme—if only because they are the two most popular Lisp dialects. Scheme predates CL, and comes not only from the same Lisp tradition but from some of the same engineers—Guy L. Steele, with whom Gerald Jay Sussman designed Scheme, chaired the standards committee for Common Lisp. Common Lisp is a general-purpose programming language, in contrast to Lisp variants such as Emacs Lisp and AutoLISP which are extension languages embedded in particular products (GNU Emacs and AutoCAD, respectively). Unlike many earlier Lisps, Common Lisp (like Scheme) uses lexical variable scope by default for both interpreted and compiled code. Most of the Lisp systems whose designs contributed to Common Lisp—such as ZetaLisp and Franz Lisp—used dynamically scoped variables in their interpreters and lexically scoped variables in their compilers. Scheme introduced the sole use of lexically scoped variables to Lisp; an inspiration from ALGOL 68 which was widely recognized as a good idea. CL supports dynamically scoped variables as well, but they must be explicitly declared as "special". There are no differences in scoping between ANSI CL interpreters and compilers. Common Lisp is sometimes termed a Lisp-2 and Scheme a Lisp-1, referring to CL's use of separate namespaces for functions and variables. (In fact, CL has many namespaces, such as those for go tags, block names, and CL also differs from Scheme in its handling of boolean values. Scheme uses the special values #t and #f to represent truth and falsity. CL follows the older Lisp convention of using the symbols T and NIL, with NIL standing also for the empty list. In CL, any non-NIL value is treated as true by conditionals, such as Lastly, the Scheme standards documents require tail-call optimization, which the CL standard does not. Most CL implementations do offer tail-call optimization, although often only when the programmer uses an optimization directive. Nonetheless, common CL coding style does not favor the ubiquitous use of recursion that Scheme style prefers—what a Scheme programmer would express with tail recursion, a CL user would usually express with an iterative expression in ImplementationsSee the Category Common Lisp implementations. Common Lisp is defined by a specification (like Ada and C) rather than by one implementation (like Perl before version 6). There are many implementations, and the standard details areas in which they may validly differ. In addition, implementations tend to come with extensions, which provide functionality not covered in the standard:
Free and open-source software libraries have been created to support extensions to Common Lisp in a portable way, and are most notably found in the repositories of the Common-Lisp.net [19] and CLOCC (Common Lisp Open Code Collection) [20] projects. Common Lisp implementations may use any mix of native code compilation, byte code compilation or interpretation. Common Lisp has been designed to support incremental compilers, file compilers and block compilers. Standard declarations to optimize compilation (such as function inlining or type specialization) are proposed in the language specification. Most Common Lisp implementations compile source code to native machine code. Some implementations can create (optimized) stand-alone applications. Others compile to interpreted bytecode, which is less efficient than native code, but eases binary-code portability. There are also compilers that compile Common Lisp code to C code. The misconception that Lisp is a purely interpreted language is most likely because Lisp environments provide an interactive prompt and that code is compiled one-by-one, in an incremental way. With Common Lisp incremental compilation is widely used. Some Unix-based implementations (CLISP, SBCL) can be used as a scripting language; that is, invoked by the system transparently in the way that a Perl or Unix shell interpreter is.[21] List of implementationsCommercial implementations
Freely redistributable implementations
Other implementations{{Refimprove section|date=July 2018}}
ApplicationsSee the Category Common Lisp software. Common Lisp is used to develop research applications (often in Artificial Intelligence), for rapid development of prototypes or for deployed applications Common Lisp is used in many commercial applications, including the Yahoo! Store web-commerce site, which originally involved Paul Graham and was later rewritten in C++ and Perl.[46] Other notable examples include:
There also exist open-source applications written in Common Lisp, such as:
LibrariesSince 2011, Zach Beane, with support of the Common Lisp Foundation, has maintained the Quicklisp library manager. It allows automatic download, installing, and loading[61] of over 3600 [62] libraries, all of which are required to work on more than just one implementation of Common Lisp and to have a license that allows their redistribution.[63] See also{{Portal|Computer Science|Computer programming}}
References1. ^Quoted from cover of cited standard. ANSI INCITS 226-1994 (R2004), for sale on standard's document page {{webarchive|url=https://web.archive.org/web/20140101204441/http://webstore.ansi.org/RecordDetail.aspx?sku=ANSI+INCITS+226-1994+(R2004) |date=2014-01-01 }}. 2. ^{{cite web|url=http://www.lispworks.com/documentation/HyperSpec/Front/Help.htm#Authorship|title=CLHS: About the Common Lisp HyperSpec (TM)|author=|date=|website=www.lispworks.com}} 3. ^{{cite web|url=http://www.lispworks.com/documentation/HyperSpec/Body/01_ab.htm|title=CLHS: Section 1.1.2|author=|date=|website=www.lispworks.com}} 4. ^Common Lisp Implementations: A Survey 5. ^{{cite web | url = http://www.informatimago.com/develop/lisp/com/informatimago/small-cl-pgms/wang.html | title = Old LISP programs still run in Common Lisp | accessdate = 2015-05-13}} 6. ^{{cite web|url=http://www.cs.cmu.edu/afs/cs/project/ai-repository/ai/lang/lisp/doc/history/cl.txt|title=Roots of "Yu-Shiang Lisp", Mail from Jon L White, 1982|author=|date=|website=cmu.edu}} 7. ^{{cite web|url=http://cl-su-ai.lisp.se/maillist.html|title=Mail Index|author=|date=|website=cl-su-ai.lisp.se}} 8. ^Knee-jerk Anti-LOOPism and other E-mail Phenomena: Oral, Written, and Electronic Patterns in Computer-Mediated Communication, JoAnne Yates and Wanda J. Orlikowski., 1993 {{webarchive|url=https://web.archive.org/web/20120808032049/http://ccs.mit.edu/papers/CCSWP150.html |date=2012-08-08 }} 9. ^{{cite book|url=http://dl.acm.org/citation.cfm?id=800068.802140|title=An overview of COMMON LISP|first1=Steele|last1=Jr|first2=Guy|last2=L|date=15 August 1982|publisher=ACM|pages=98–107|via=dl.acm.org|doi=10.1145/800068.802140|isbn=9780897910828|series=Lfp '82}} 10. ^{{cite web | url = http://random-state.net/features-of-common-lisp.html | title = Features of Common Lisp | first = Abhishek | last = Reddy | date = 2008-08-22}} 11. ^{{cite web | url = http://www.cliki.net/Unicode%20Support | title = Unicode support | work = The Common Lisp Wiki | accessdate = 2008-08-21}} 12. ^{{cite journal |title=Technical Issues of Separation in Function Cells and Value Cells |url=http://www.nhplace.com/kent/Papers/Technical-Issues.html |authors=Richard P. Gabriel, Kent M. Pitman |journal=Lisp and Symbolic Computation |date = June 1988|volume=1 |issue=1 |pages=81–101 |doi=10.1007/bf01806178}} 13. ^{{cite web|title=Common Lisp Hyperspec: Section 3.1.7|url=http://www.lispworks.com/documentation/HyperSpec/Body/03_ag.htm}} 14. ^{{cite web|title=Common Lisp Hyperspec: Function FLOOR|url=http://www.lispworks.com/documentation/HyperSpec/Body/f_floorc.htm}} 15. ^{{cite web|title=Common Lisp Hyperspec: Accessor GETHASH|url=http://www.lispworks.com/documentation/HyperSpec/Body/f_gethas.htm}} 16. ^{{cite web|url=http://letoverlambda.com/index.cl/guest/chap2.html|title=Let Over Lambda|author=|date=|website=letoverlambda.com}} 17. ^{{cite book|author=Peter Seibel|title=Practical Common Lisp|url=http://www.gigamonkeys.com/book/beyond-exception-handling-conditions-and-restarts.html|date=7 April 2005|publisher=Apress|isbn=978-1-59059-239-7}} 18. ^{{cite web|url=http://norvig.com/design-patterns/ppframe.htm|title=Design Patterns in Dynamic Programming|author=|date=|website=norvig.com}} 19. ^Common-Lisp.net 20. ^Common Lisp Open Code Collection 21. ^{{cite web|url=http://clisp.cons.org/impnotes/quickstart.html#quickstart-unix|title=32.6. Quickstarting delivery with CLISP|author=|date=|website=clisp.cons.org}} 22. ^{{cite web | url = http://common-lisp.net/project/armedbear/ | title = Armed Bear Common Lisp }} 23. ^{{cite web|title=Corman Lisp sources are now available|url=http://lispblog.xach.com/post/107215169193/corman-lisp-sources-are-now-available}} 24. ^{{cite web | url = http://sbcl.sourceforge.net/history.html | title = History and Copyright | work = Steel Bank Common Lisp}} 25. ^{{cite web | url = http://www.sbcl.org/platform-table.html | title = Platform Table | work = Steel Bank Common Lisp}} 26. ^{{cite web|url=http://benchmarksgame.alioth.debian.org/u32q/benchmark.php?test=all&lang=all|archive-url=https://web.archive.org/web/20130520184339/http://benchmarksgame.alioth.debian.org/u32q/benchmark.php?test=all&lang=all|dead-url=yes|archive-date=20 May 2013|title=Which programs are fastest? - Computer Language Benchmarks Game|author=|date=20 May 2013}} 27. ^{{cite web|url=https://www.cs.cmu.edu/afs/cs/project/ai-repository/ai/lang/lisp/impl/bbn/0.html|title=Package: lang/lisp/impl/bbn/|author=|date=|website=www.cs.cmu.edu}} 28. ^{{cite web|url=http://www.aaai.org/Papers/AAAI/1987/AAAI87-001.pdf|title= Recent Developments in Butterfly Lisp, 1987, AAAI Proceedings|author=|date=|website=aaai.org}} 29. ^{{cite journal|title=CLICC: A New Approach to the Compilation of Common Lisp Programs to C|first1=O.|last1=Burkart|first2=W.|last2=Goerigk|first3=H.|last3=Knutzen|date=22 June 1992|citeseerx = 10.1.1.38.1282}} 30. ^{{cite web|url=http://lisp.codemist.co.uk|title=codemist.co.uk|author=|date=|website=lisp.codemist.co.uk}} 31. ^Axiom, the 30 year horizon, page 43 32. ^{{cite web|url=http://www.goldhill-inc.com/developer.html|title=Golden Common Lisp Developer|author=|date=|website=goldhill-inc.com}} 33. ^Golden Common LISP: A Hands-On Approach, David J. Steele, June 2000 by Addison Wesley Publishing Company 34. ^{{cite journal|title=L -- A Common Lisp for Embedded Systems|first1=Rodney A.|last1=Brooks|first2=et|last2=al. |date=22 June 1995|citeseerx = 10.1.1.2.1953}} 35. ^TI Explorer Programming Concepts 36. ^TI Explorer Lisp Reference 37. ^Medley Lisp Release Notes 38. ^{{cite web|url=http://bitsavers.trailing-edge.com/pdf/symbolics/software/open_genera/Symbolics_Common_Lisp_Dictionary.pdf |title=Symbolics Common Lisp Dictionary|author=|date=|website=trailing-edge.com}} 39. ^{{cite web|url=http://bitsavers.trailing-edge.com/pdf/symbolics/software/open_genera/Symbolics_Common_Lisp_Language_Concepts.pdf|title=Symbolics Common Lisp Language Concepts|author=|date=|website=trailing-edge.com}} 40. ^{{cite web|url=http://bitsavers.trailing-edge.com/pdf/symbolics/software/open_genera/Symbolics_Common_Lisp_Programming_Constructs.pdf|title=Symbolics Common Lisp Programming Constructs|author=|date=|website=trailing-edge.com}} 41. ^{{cite web|url=http://www.cyc.com/documentation/subl-reference/|title=SubL Reference – Cycorp|author=|date=|website=www.cyc.com}} 42. ^{{cite web|url=http://www.softwarepreservation.org/projects/LISP/toplevel|title=Top Level Inc. - Software Preservation Group |author= |date= |website=www.softwarepreservation.org}} 43. ^WCL: Delivering efficient Common Lisp applications under Unix , Proceedings of the 1992 ACM conference on LISP and functional programming, Pages 260-269 44. ^{{cite web|url=http://pgc.com/commonlisp/|title=commonlisp.net :: WCL|author=|date=|website=pgc.com}} 45. ^{{cite web|url=https://www.cs.cmu.edu/afs/cs/project/ai-repository/ai/lang/lisp/impl/xlisp/0.html|title=Package: lang/lisp/impl/xlisp/|author=|date=|website=www.cs.cmu.edu}} 46. ^{{cite web|url=http://www.paulgraham.com/avg.html|title=Beating the Averages|author=|date=|website=www.paulgraham.com}} 47. ^{{cite web|url=http://www.aaai.org/Papers/IAAI/1989/IAAI89-031.pdf|title=Authorizer's Assistant|author=|date=|website=aaai.org}} 48. ^American Express Authorizer's Assistant {{webarchive|url=https://web.archive.org/web/20091212141726/http://www.prenhall.com/divisions/bp/app/alter/student/useful/ch9amex.html |date=2009-12-12 }} 49. ^Real-time Application Development. Gensym. Retrieved on 2016-08-16. 50. ^PWGL - Home. . Retrieved on 2013-07-17. 51. ^1 {{cite web|url=http://lisp-lang.org/success/aero/|title=Aerospace - Common Lisp|author=|date=|website=lisp-lang.org}} 52. ^ Piano Users, retrieved from manufacturer page. 53. ^[https://tech.grammarly.com/blog/running-lisp-in-production] Grammarly.com, Running Lisp in Production 54. ^{{cite web|url=https://ti.arc.nasa.gov/tech/asr/groups/planning-and-scheduling/remote-agent/|title=Remote Agent|author=|date=|website=ti.arc.nasa.gov}} 55. ^http://www.flownet.com/gat/jpl-lisp.html 56. ^{{cite web|url=https://franz.com/success/customer_apps/scheduling/nasa.lhtml|title=Franz Inc Customer Applications: NASA|author=|date=|website=franz.com}} 57. ^Spike Planning and Scheduling System. Stsci.edu. Retrieved on 2013-07-17. 58. ^{{cite web|url=https://franz.com/success/customer_apps/scheduling/sti.lhtml|title=Franz Inc Customer Applications: Space Telescope Institute|author=|date=|website=franz.com}} 59. ^{{cite web|url=https://blogs.msdn.microsoft.com/patrick_dussud/2006/11/21/how-it-all-startedaka-the-birth-of-the-clr/|title=How It All Started…AKA the Birth of the CLR|author=|date=|website=microsoft.com}} 60. ^https://tapoueh.org/blog/2014/05/why-is-pgloader-so-much-faster/ 61. ^[https://www.quicklisp.org/beta/] Quicklisp description 62. ^Library count can be directly obtained by executing (length (ql:system-list)) in a Lisp REPL that has loaded the Quicklisp system. Count as of 2019-03-11 is 4087 packages. 63. ^ Getting a library into Quicklisp BibliographyA chronological list of books published (or about to be published) about Common Lisp (the language) or about programming with Common Lisp (especially AI programming). {{Refbegin|2}}
External links{{Wikibooks}}
15 : Articles with example Lisp code|Class-based programming languages|Common Lisp|Cross-platform free software|Cross-platform software|Dynamic programming languages|Dynamically typed programming languages|Extensible syntax programming languages|Functional languages|Lisp (programming language)|Lisp programming language family|Multi-paradigm programming languages|Object-oriented programming languages|Procedural programming languages|Programming languages created in 1984 |
随便看 |
|
开放百科全书收录14589846条英语、德语、日语等多语种百科知识,基本涵盖了大多数领域的百科知识,是一部内容自由、开放的电子版国际百科全书。