Common Lisp

Common Lisp is a dialect of Lisp, standardised by ANSI X3.226-1994. Developed to standardize the divergent variants of Lisp which predated it, it is not an implementation but rather a language specification to which most Lisp implementations conform.

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. Unlike many earlier Lisps, but like Scheme, Common Lisp uses lexical scoping for variables.

Common Lisp is a multi-paradigm programming language that:

  • Supports programming techniques such as imperative, functional and object-oriented programming.
  • Is dynamically typed, but with optional type declarations that can improve efficiency or safety.
  • Is extensible through standard features such as macros and reader macros.

Table of contents
1 Syntax
2 Data types
3 Implementations
4 External links

Syntax

Common Lisp is a Lisp; it uses S-expressions to denote both code and data structure. 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
(setq pi 3.1415)  ; sets the variable "pi" equal to 3.1415

; Define a function that squares a number (defun square (x) (* x x)) ; Execute the function (square 3) ; Returns "9"

Data types

Common Lisp has a plethora of data types, more than many languages.

Scalar types

Number types include
integers, ratios, floating-point numbers, and complex numbers. 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; unsurprising, as Lisp predates ASCII. Some modern implementations allow Unicode characters. [1]

The symbol type is common to Lisp languages, but largely unknown outside them. A symbol is a unique, named data object. Symbols in Lisp are similar to identifiers in other languages, in that they can be used as variables to hold values; however, they are more general and can be used for themselves as well. Boolean values in Common Lisp are represented by the reserved symbols T and NIL.

Data structures

Sequence types in Common Lisp include arrays, vectors, bit-vectors, and strings. Common Lisp supports multidimensional arrays, and can dynamically resize arrays as needed. Multidimensional arrays can be used for matrix mathematics.

As in any other Lisp, lists in Common Lisp are composed of conses, sometimes called cons cells or pairs. A cons is a data structure of two elements, called its car and cdr. A list is a linked chain of conses wherein each cons's cdr points to the next element, and the last cdr points to the NIL value. Conses can also easily be used to implement trees and other complex data structures.

Hash tables store associations between data objects. 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 package may export some symbols, marking them as part of a public interface.

Structures, akin to C structs and Pascal records, represent arbitrary complex data structures with any number and type of fields (called slots).

Functions

In Common Lisp, functions are a data type. For instance, it is possible to write functions that take other functions as arguments. This makes it possible to make very general operations.

For instance, the sort function takes a comparison operator as an argument. This can be used not only to sort any type of data, but also to sort data structures according to a key.

(sort '(5 2 6 3 1 4) #'>)
; Returns (6 5 4 3 2 1), using the > function as the comparison operator

(sort '((9 a) (3 b) (4 c)) #'(lambda (x y) (< (car x) (car y)))) ; Returns ((3 b) (4 c) (9 a)), i.e. the list sorted by the first element

Common Lisp is a Lisp-2, meaning that there are separate namespaces for defined functions and for variables. (This differs from, for instance,
Scheme, which is a Lisp-1.) Lisp-2 has the advantage that a local variable name will never shadow a function name: One can call a variable cons or even if with no problems. However, to refer to a function variable one must use the #' notation, as in the above examples.

While a function definition (a defun form) is a list, functions are not generally internally represented as lists. Most Common Lisp systems compile functions individually to bytecode or machine code.

Other types

Other data types in Common Lisp include:

  • Pathnames represent files and directories in the filesystem. The Common Lisp pathname facility is more general than most operating systems' file naming conventions, making Lisp programs' access to files broadly portable across diverse systems.
  • Input and output streams represent sources and sinks of binary or textual data, such as the terminal or open files.
  • Common Lisp has a built-in pseudo-random number generator. Random state objects represent reusable sources of pseudo-random numbers, allowing the user to seed the PRNG or cause it to replay a sequence.
  • Conditions are a special type used to represent errors, exceptions, and other "interesting" events to which a program may respond.

Common Lisp also includes a toolkit for object-oriented programming, the Common Lisp Object System or CLOS.

Macros

A macro in Lisp superficially resembles a function. However, rather than representing an expression which is evaluated, it represents a transformation of the program text within the macro call.

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 &rest body)
  `(do ()
       (,test)
     ,@body))

This differs from a function in that it can repeatedly evaluate its arguments. A function's arguments are evaluated only once, before the function is called; a macro controls its arguments' evaluation or other use in the macro-expansion.

Variable capture

Common Lisp macros are capable of variable capture, a situation in which symbols in the macro-expansion body coincide with those in the calling context. Variable capture is sometimes a desired effect: it allows the programmer to create macros wherein various symbols have special meaning. However, it can also introduce unexpected and unusual errors.

Some Lisp systems, such as Scheme, avoid variable capture by using macro syntaxes -- so-called "hygienic macros" -- which do not allow it. In Common Lisp, one can avoid unwanted capture by using gensyms -- guaranteed-unique symbols which can be used in a macroexpansion without threat of capture.

Implementations

Common Lisp is defined by a specification (like Ada and C) rather than by a single implementation (like Perl). There are many implementations, and the standard spells out areas in which they may validly differ.

In addition, implementations tend to come with divergent sets of library packages, which provide functionality not covered in the standard. Some of these features have been rolled back into the standard, such as CLOS and the LOOP construct; others remain implementation-specific. Unfortunately, many valuable facilities for the modern programmer -- such as TCP/IP networking -- remain unstandardized.

It is a common misconception that Common Lisp implementations are all interpreters. In fact, compilation is part of the language specification. Most Common Lisp implementations compile functions to native machine code. Others compile to bytecode, which reduces speed but improves portability.

Some Unix-based implementations, such as CLISP, can be used as script interpreters.

List of implementations

Freely redistributable implementations include:

  • CMU Common Lisp (CMUCL), from Carnegie Mellon University. CMUCL is perhaps the most widely-used open source CL. It is available on Linux and BSD for Intel x86; Linux for Alpha; and Solaris, IRIX, and HP-UX on their native platforms.
  • GNU CLISP, a bytecode-compiling implementation. It is portable and runs on a number of Unix and Unix-like systems, as well as Microsoft Windows and several other systems.
  • Steel Bank Common Lisp (SBCL), a branch from CMUCL. "Broadly speaking, SBCL is distinguished from CMU CL by a greater emphasis on maintainability." [1] SBCL runs on the platforms CMUCL does, except HP/UX, and also on Linux for PowerPC, SPARC, and MIPS.
  • GNU Common Lisp (GCL), the GNU Project's Lisp compiler. Not yet fully ANSI-compliant, GCL is however the implementation of choice for several large projects including the mathematical tools Maxima and ACL2. GCL runs under GNU/Linux on eleven different architectures, and also under Windows, Solaris, and FreeBSD.
  • Embeddable Common Lisp (ECLS), designed to be embedded in C applications;
  • OpenMCL, an open source branch of Macintosh Common Lisp. As the name implies, OpenMCL is native to the Macintosh; it runs on Mac OS X, Darwin, and Linux for PowerPC.

There are also commercial implementations available from Franz, Xanalys, Digitool, Corman and Scieneer.

External links

see also: WCL, Kyoto Common Lisp.


In the News

The Mechanics Of Foot Travel: With So Many Silly Gaits To Choose From,
Despite having the bones and muscles to perform a variety of gaits, human beings have developed an overwhelming preference for just two: walking and running. Now, computer analysis that allows simulation of infinite two-legged locomotions has shown our favored modes of bi-pedal travel use the least amount of energy.

[Ironic] Professional beggars prowling about the streets of Moroccan c
The government plans to crack down on the scam used by faux beggars in growing numbers for a kind of "emotional blackmail", a cabinet minister was quoted as saying...

[Ironic] An Italian pensioner committed suicide after his wife fell in
Recalling the end of Romeo and Juliet, the 70-year-old man, Ettore, who had sat by his wife's bedside for four months after she slipped into a coma following a heart attack, finally gave up hope and gassed himself in the garage of his family home.Less than a day later, his wife, Rossana, woke up in her hospital bed in Padua and immediately asked for him.

Study Finds Continued Reduction In Breast Cancer Incidence Associated
Raloxifene (Evista) continues to be associated with more than a 50% reduction in breast cancer incidence beyond the first 4 years of treatment, according to a new study in the December 1 issue of the Journal of the National Cancer Institute.

Computer Program Learns Language Rules And Composes Sentences, All Wit
Shimon Edelman of Cornell University and colleagues have developed a method for enabling a computer program to scan text, infer the grammar behind it and generate new sentences. It works for different languages, music and protein sequences. (PNAS: Vol. 102:33, 2005)

New Approach Builds Better Proteins Inside A Computer
With the aid of more than 70,000 home computer users throughout the world, researchers have, for the first time, accurately predicted the 3-D structure of a small, naturally occurring globular protein using only its amino acid sequence. The accomplishment was achieved with a newly refined computational method for predicting protein structure.

A Potential New Disease-modifying Drug For Osteoarthritis
A new study indicates promise of bone-building calcitonin for protecting post-menopausal women against cartilage degradation and joint destruction. Calcitonin, an amino acid hormone produced by the thyroid gland, has been shown to decrease bone breakdown and increase bone density. Typically prescribed as a nasal spray, it is widely used in the treatment of Paget's disease and osteoporosis.

Strong Link Between Obesity And Colorectal Cancer
A clear, direct link between obesity and colorectal cancer has been shown in a new analysis. The report shows that obese individuals have a 20% greater risk of developing colorectal cancer compared with those of normal weight. The analyses also indicated that obese men are at 30% greater risk of developing the cancer compared with obese women. Findings from the study also showed that carrying even a few excess kilos substantially increases the risk of colorectal cancer; for every 5 kg weight gain the risk of developing the cancer increases by 7%.

We Can Detect Liquid Explosives
Scanning machines that can spot liquid or gel-based explosives exist already -- some based on 10-year-old technologies. But they're not in airports and probably won't be anytime soon.

[Ironic] An Italian pensioner committed suicide after his wife fell in
Recalling the end of Romeo and Juliet, the 70-year-old man, Ettore, who had sat by his wife's bedside for four months after she slipped into a coma following a heart attack, finally gave up hope and gassed himself in the garage of his family home.Less than a day later, his wife, Rossana, woke up in her hospital bed in Padua and immediately asked for him.


MP3 Music Downloads

Preview songs, Download Free Music,Burn CDs at ITunes.com
iTunes_RGB_9mm

 


Google




InformationQuickFind.com - Find Information Fast

Links