| Common Lisp | |
|---|---|
| Paradigm | multi-paradigm: functional, procedural, reflective, object-oriented |
| Appeared in | 1984, 1994 for ANSI Common Lisp |
| Developer | ANSI X3J13 committee |
| Typing discipline | dynamic, strong |
| Major implementations | Allegro Common Lisp, Armed Bear Common Lisp, CLISP, CMUCL, Corman Lisp, Embeddable Common Lisp, GNU Common Lisp, LispWorks, Macintosh Common Lisp, Movitz, OpenMCL, Poplog, Scieneer Common Lisp, Steel Bank Common Lisp, Symbolics Common Lisp |
| Dialects | CLtL1, CLtL2, ANSI Common Lisp |
| Influenced by | Lisp Machine Lisp, MacLisp, Scheme, InterLisp |
| Influenced | Dylan, Eulisp, ISLisp |
| OS | Cross-platform |
Common Lisp, commonly abbreviated CL, is a dialect of the Lisp programming language, published in ANSI standard document Information Technology - Programming Language - Common Lisp, formerly X3. A programming paradigm is a fundamental style of Computer programming. A multi-paradigm programming language is a Programming language that supports more than one Programming paradigm. In Computer science, functional programming is a Programming paradigm that treats Computation as the evaluation of mathematical functions and Procedural programming can sometimes be used as a synonym for Imperative programming (specifying the steps the program must take to reach the desired state but can also In Computer science, reflection is the process by which a Computer program can observe and modify its own structure and behavior Object-oriented programming (OOP is a Programming paradigm that uses " objects " and their interactions to design applications and computer programs A software developer is a person or organization concerned with facets of the software development process wider than design and coding a somewhat broader scope of In Computer science, a type system defines how a Programming language classifies values and expressions into '''types''', how it can In Computer science, a type system defines how a Programming language classifies values and expressions into '''types''', how it can In Computer science and Computer programming, the term strong typing is used to describe those situations where Programming languages specify one or more Implementation is the realization of an application or execution of a Plan, idea Model, Design, Specification, standard, Algorithm Allegro Common Lisp is an Integrated development environment for the Common Lisp programming language developed by Franz Inc. Armed Bear Common Lisp is an implementation of Common Lisp that runs on the Java Virtual Machine. In Computing, CLISP is a Programming language originally developed by Bruno Haible and Michael Stoll for the Atari ST. CMUCL is a free Common Lisp implementation originally developed at Carnegie Mellon University. ECL is a free Common Lisp implementation aimed at producing a small-footprint Lisp system that can be embedded into existing C -based applications GNU Common Lisp (GCL is the GNU Project 's Common Lisp compiler an evolutionary development of Kyoto Common Lisp. LispWorks is a commercial implementation and IDE for the Common Lisp Programming language. Movitz is an implementation of the Common Lisp Programming language for X86 computers Poplog is a powerful multi- language, multiparadigm, reflective, incrementally compiled software development environment Steel Bank Common Lisp ( SBCL) is a free Common Lisp implementation that features ahigh performance native compiler Unicode support and Common Lisp, commonly abbreviated CL, is a dialect of the Lisp Programming language, published in ANSI standard document Information Lisp Machine Lisp is a dialect of the Lisp programming language, a direct descendant of Maclisp, and was initially developed in the mid to late 1970s as the systems MACLISP (or Maclisp) is a dialect of the Lisp Programming language. Scheme is a Multi-paradigm programming language. It is one of the two main dialects of Lisp and supports a number of programming paradigms but is Interlisp (also seen with a variety of capitalizations was a programming environment built around a version of the Lisp programming language. The Dylan Programming language is a multi-paradigm language that includes support for functional EuLisp is a statically and dynamically scoped Lisp dialect developed as name suggests in Europe. ISLISP (also capitalized as ISLisp) is a Programming language in the LISP family standardized by the ISO. An operating system (commonly abbreviated OS and O/S) is the software component of a Computer system that is responsible for the management and coordination In computing cross-platform (also known as multi-platform) is a term used to refer to Computer software or computing methods and concepts that are implemented Lisp (or LISP) is a family of Computer Programming languages with a long history and a distinctive fully parenthesized syntax A programming language is an Artificial language that can be used to write programs which control the behavior of a machine particularly a Computer. 226-1994 (R1999). [1] Developed to standardize the divergent variants of Lisp which predated it, it is not an implementation but rather a language specification. Several implementations of the Common Lisp standard are available, including commercial products and open source software. Open source software (OSS began as a marketing campaign for Free software.
Common Lisp is a multiparadigm, general-purpose programming language that:
Contents |
Common Lisp is a dialect of Lisp; it uses S-expressions to denote both code and data structure. The term S-expression or sexp (where S stands for symbolic refers to a convention for representing Semi-structured data in human-readable textual form Function and macro calls are written as lists, with the name of the function first, as in these examples:
(+ 2 2) ; adds 2 and 2, yielding 4.
(setf p 3. 1415) ; sets the variable p equal to 3. 1415 ; note: "pi" is a built-in constant - can't setf it
;; Define a function that squares a number: (defun square (x) (* x x))
;; Execute the function: (square 3) ; Returns 9
;; the 'let' construct creates a lexical scope for local variables. Here ;; the lexical variable 'a' is bound to 6 and the lexical variable 'b' is bound ;; to 4. Inside the 'let' is a 'body', where the last computed value is returned. ;; Here the result of adding a and b is returned from the 'let' expression. (let ((a 6) (b 4)) (+ a b)) ; returns 10
Common Lisp has many data types, more than many other languages.
Number types include integers, ratios, floating-point numbers, and complex numbers. The integers (from the Latin integer, literally "untouched" hence "whole" the word entire comes from the same origin but via French A ratio is an expression which compares quantities relative to each other In Computing, floating point describes a system for numerical representation in which a string of digits (or Bits represents a Real number. Complex plane In Mathematics, the complex numbers are an extension of the Real numbers obtained by adjoining an Imaginary unit, denoted Common Lisp uses bignums to represent numerical values of arbitrary size and precision. On a Computer, arbitrary-precision arithmetic, also called bignum arithmetic is a technique whereby Computer programs perform Calculations on 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 -- unsurprising, as Lisp predates ASCII. For other uses see Character. In Computer and machine-based Telecommunications terminology a character is a unit of American Standard Code for Information Interchange ( ASCII) Most modern implementations allow Unicode characters. In Computing, Unicode is an Industry standard allowing Computers to consistently represent and manipulate text expressed in most of the world's [1]
The symbol type is common to Lisp languages, but largely unknown outside them. The musical instrument is spelled Cymbal. A symbol is something --- such as an object, Picture, written word a sound a piece 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 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 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'.
Sequence types in Common Lisp include lists, vectors, bit-vectors, and strings. There are many operations which 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. 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, whose cdr refers to the nil value. Conses can also easily be used to implement trees and other complex data structures; though it is usually advised to use structure or class instances instead. It is also possible to create circular data structures with conses.
Common Lisp supports multidimensional arrays, and can dynamically resize 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 integers. 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. A bit is a binary digit, taking a value of either 0 or 1 Binary digits are a basic unit of Information storage and communication
Hash tables store associations between data objects. In Computer science, a hash table, or a hash map, is a Data structure that associates keys with values. Any object may be used as key or value. Hash tables, like arrays, are automatically resized as needed.
Packages are collections of symbols, used chiefly to separate the parts of a program into namespaces. A namespace is an abstract container or environment created to hold a logical grouping of unique identifiers (i 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). tags please moot on the talk page first! --> In Computing, C is a general-purpose cross-platform block structured Pascal is an influential imperative and procedural Programming language, designed in 1968/9 and published in 1970 by Niklaus Wirth as a small Structures allow single-inheritance.
Classes are similar to structures, but offer more dynamic features and multiple-inheritance CLOS. The Common Lisp Object System (CLOS is the facility for Object-oriented programming which is part of ANSI Common Lisp. 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.
Common Lisp supports first-class functions. In Computer science, a Programming language is said to support first-class functions (or function literal) if it treats functions as 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 sort function takes a relational operator as an argument and key function as an optional keyword argument. In Computer science a relational operator is a Programming language construct or operator that tests some kind of relation between two entities This can be used not only to sort any type of data, but also to sort data structures according to a key.
(sort (list 5 2 6 3 1 4) #'>) ; Sorts the list using the > function as the relational operator. ; Returns (6 5 4 3 2 1).
(sort (list '(9 A) '(3 B) '(4 C)) #'< :key #'first) ; Sorts the list according to the first element of each sub-list. ; Returns ((3 B) (4 C) (9 A)).
The evaluation model for functions is very simple. When the evaluator encounters a form (F A1 A2. . . ) then it is to assume that the symbol named F is one of the following:
lambda. 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.
The macro defun defines functions. A function definition gives the name of the function, the names of any arguments, and a function body:
(defun square (x) (* x x))
Function definitions may include 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:
(defun square (x) "Calculates the square of the single-float x. " (declare (single-float x) (optimize (speed 3) (debug 0) (safety 1))) (* x x))
Anonymous functions (function literals) are defined using lambda expressions, e. In Computer science, a Programming language is said to support first-class functions (or function literal) if it treats functions as g. (lambda (x) (* x x)) for a function that squares its argument. Lisp programming style frequently uses higher-order functions for which it is useful to provide anonymous functions as arguments.
Local functions can be defined with flet and labels.
(flet ((square (x) (* x x))) (square 3))
There are a number of other operators related to the definition and manipulation of functions. For instance, a function may be recompiled with the compile operator. (Some Lisp systems run functions in an interpreter by default unless instructed to compile; others compile every entered function on the fly. )
The macro defgeneric defines generic functions. The macro defmethod defines methods. Generic functions are a collection of methods.
Methods can specialize their parameters over classes or objects.
When a generic function is called, multiple-dispatch will determine the correct method to use.
(defgeneric add (a b))
(defmethod add ((a number) (b number)) (+ a b))
(defmethod add ((a string) (b string)) (concatenate 'string a b))
(add "Zippy" "Pinhead") ; returns "ZippyPinhead"
Generic Functions are also a first class data type. There are many more features to Generic Functions and Methods than described above.
The namespace for function names is separate from the namespace for data variables. This is a key difference between Common Lisp and Scheme. Scheme is a Multi-paradigm programming language. It is one of the two main dialects of Lisp and supports a number of programming paradigms but is Operators which define names in the function namespace include defun, flet, labels, defmethod and defgeneric.
To pass a function by name as an argument to another function, one must use the function special operator, commonly abbreviated as #'. The first sort example above refers to the function named by the symbol > in the function namespace, with the code #'>.
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. Scheme is a Multi-paradigm programming language. It is one of the two main dialects of Lisp and supports a number of programming paradigms but is Code written in one dialect is therefore sometimes confusing to programmers more experienced in the other. For instance, many CL 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. These names were coined in a 1988 paper by Richard P. Gabriel and Kent Pitman, which extensively compares the two approaches. Richard P Gabriel (born 1949 is a noted expert on the Lisp programming language (and especially Common Lisp) in computing Kent M Pitman is the President of HyperMeta Inc and has been involved for many years in the design implementation and use of Lisp and Scheme systems [2]
Other data types in Common Lisp include:
A macro in Lisp superficially resembles a function in usage. A macro (from the Greek 'μάκρο' for long or far in Computer science is a rule or Pattern that specifies how a certain input sequence (often a sequence However, rather than representing an expression which is evaluated, it represents a transformation of the program source code.
Macros allow Lisp programmers to create new syntactic forms in the language. For instance, this macro provides the until loop form, which may be familiar from languages such as Perl:
(defmacro until (test &body body) `(do () (,test) ,@body)) ;; example (until (= (random 10) 0) (write-line "Hello"))
All macros must be expanded before the source code containing them can be evaluated or compiled normally. NOTES FOR EDITORS "Perl" is not an acronym (read the "Name" section below Macros can be considered functions that accept and return abstract syntax trees (Lisp S-expressions). In Computer science, an abstract syntax tree (AST or just syntax tree, is a tree representation of the Syntax of some Source code 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. The backquote notation used above is provided by Common Lisp specifically to simplify the common case of substitution into a code template.
Common Lisp macros are capable of 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.
Variable capture can introduce unexpected and unusual errors. Some Lisp systems, such as Scheme, avoid variable capture by using macro syntax — so-called "hygienic macros" — that does not allow it. In Common Lisp, one can avoid unwanted capture by using gensyms: guaranteed-unique symbols which can be used in a macro-expansion without threat of capture.
Another issue is the inadvertent shadowing of operators used in a macroexpansion. For example, consider the following (incorrect) code:
(macrolet ((do (. . . ) . . . something else . . . )) (until (= (random 10) 0) (write-line "Hello")))
The UNTIL macro will expand into a form which calls DO which is intended to refer to the built-in macro DO. However, in this context, DO may have a completely different meaning.
Common Lisp ameliorates the problem of operator shadowing by forbidding the redefinition of built-in operators, such as DO in this example. Moreover, users may separate their own code into packages. Built-in symbols are found in the COMMON-LISP package, which will not be shadowed by a symbol in a user package.
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. The Common Lisp Object System (CLOS is the facility for Object-oriented programming which is part of ANSI Common Lisp. Object-oriented programming (OOP is a Programming paradigm that uses " objects " and their interactions to design applications and computer programs The Common Lisp Object System (CLOS is the facility for Object-oriented programming which is part of ANSI Common Lisp. Originally proposed as an add-on, CLOS was adopted as part of the ANSI standard 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. This article is about a class of programming languages for the method for reducing the runtime of algorithms see Dynamic programming. Multiple dispatch or multimethods is the feature of some Object-oriented Programming languages in which a function or method can be Multiple inheritance refers to a feature of some object-oriented Programming languages in which a class can inherit behaviors and features from C++ (" C Plus Plus " ˌsiːˌplʌsˈplʌs is a general-purpose Programming language. 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 are using CLOS for pathnames, streams, input/output, conditions, the implementation of CLOS itself and more.
Common Lisp is most frequently compared with, and contrasted to, Scheme—if only because they are the two most popular Lisp dialects. Scheme is a Multi-paradigm programming language. It is one of the two main dialects of Lisp and supports a number of programming paradigms but is 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. Guy Lewis Steele Jr, (ˈstiːl as in steel) also known as "The Great Quux" and GLS (glis is an American Computer scientist Gerald Jay Sussman is the Panasonic Professor of Electrical Engineering at the Massachusetts Institute of Technology (MIT
Common Lisp is a general-purpose programming language, in contrast to Lisp variants such as Emacs Lisp and AutoLISP which are embedded extension languages in particular products. Emacs is a class of feature-rich Text editors usually characterized by their extensibility Emacs Lisp is a dialect of the Lisp programming language used by the GNU Emacs and XEmacs Text editors (which will be collectively referred to AutoLISP is a dialect of Lisp programming language built specifically for use with the full version of AutoCAD and its derivatives which include Autodesk Unlike many earlier Lisps, Common Lisp (like Scheme) uses lexical variable scope. Scheme is a Multi-paradigm programming language. It is one of the two main dialects of Lisp and supports a number of programming paradigms but is In Computer programming, scope is an enclosing context where values and expressions are associated
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. ZetaLisp was the name Symbolics gave to their dialect of Lisp on their Lisp Machine models to distinguish it from the MIT version which was In Computer programming, scope is an enclosing context where values and expressions are associated Scheme introduced the sole use of lexically-scoped variables to Lisp; an inspiration from ALGOL 68 which was widely recognized as a good idea. Time-line of ALGOL 68 The Algorithmic Language ALGOL 68 Reports Mar 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 loop keywords. ) There is a long-standing controversy between CL and Scheme advocates over the tradeoffs involved in multiple namespaces. In Scheme, it is (broadly) necessary to avoid giving variables names which clash with functions; Scheme functions frequently have arguments named lis, lst, or lyst so as not to conflict with the system function list. However, in CL it is necessary to explicitly refer to the function namespace when passing a function as an argument -- which is also a common occurrence, as in the sort example above.
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 if as are non-#f values in Scheme. This allows some operators to serve both as predicates (answering a boolean-valued question) and as returning a useful value for further computation.
Lastly, the Scheme standards documents require tail-call optimization, which the CL standard does not. In Computer science, tail recursion (or tail-end recursion) is a special case of recursion in which the last operation of the function is a recursive call 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 do, dolist, loop, or (more recently) with the iterate package.
See the Category Common Lisp implementations.
Common Lisp is defined by a specification (like Ada and C) rather than by a single implementation (like Perl). Ada is a structured, Statically typed, imperative, and object-oriented high-level computer Programming language tags please moot on the talk page first! --> In Computing, C is a general-purpose cross-platform block structured NOTES FOR EDITORS "Perl" is not an acronym (read the "Name" section below There are many implementations, and the standard spells out areas in which they may validly differ.
In addition, implementations tend to come with library packages, which provide functionality not covered in the standard. Free Software libraries have been created to support such features in a portable way, most notably Common-Lisp.net and the Common Lisp Open Code Collection project. Free software or software libre is Software that can be used studied and modified without restriction and which can be copied and redistributed in modified or unmodified
Common Lisp has been designed to be implemented by incremental compilers. Generally a Compiler for a Programming language is a piece of software that reads in one or more program files in a source language and outputs one or more files containing Standard declarations to optimize compilation (such as function inlining) are proposed in the language specification. Most Common Lisp implementations compile source code to native machine code. Machine code or machine language is a system of instructions and data executed directly by a Computer 's Central processing unit. Some implementations offer block compilers. Some implementations can create (optimized) stand-alone applications. Others compile to bytecode, which reduces speed but eases binary-code portability. Bytecode is a term which has been used to denote various forms of Instruction sets designed for efficient execution by a software interpreter as well as being suitable There are also compilers that compile Common Lisp code to C code. The misconception that Lisp is a purely-interpreted language is most likely due to the fact that Lisp environments provide an interactive prompt and that functions are compiled one-by-one, in an incremental way. With Common Lisp incremental compilation is widely used.
Some Unix-based implementations, such as CLISP, can be used as script interpreters; that is, invoked by the system transparently in the way that a Perl or Unix shell interpreter is. Unix (officially trademarked as UNIX, sometimes also written as Unix with Small caps) is a computer In Computing, CLISP is a Programming language originally developed by Bruno Haible and Michael Stoll for the Atari ST. NOTES FOR EDITORS "Perl" is not an acronym (read the "Name" section below A Unix shell, is a command line shell that provides the traditional User interface for the Unix Operating system and for Unix-like
Commercial implementations include:
Further Commercial implementations include:
Freely redistributable implementations include:
Historical implementations include:
See the Category Common Lisp software.
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. Paul Graham (born 1964 is a Programmer, Venture capitalist and Essayist, known for his work on Lisp. [2] Other notable examples include:
There also exist open-source applications written in Common Lisp, such as:
As well, Common Lisp is used by many government and non-profit institutions. Examples of its use in NASA include: