LISP

Lisp (historically, LISP) is a family of computer programming languages with a long history and a distinctive, fully parenthesized Polish prefix notation.[1] Originally specified in 1958, Lisp is the second-oldest high-level programming language in widespread use today; only Fortran is older (by one year). Like Fortran, Lisp has changed a great deal since its early days, and a number of dialects have existed over its history. Today, the most widely known general-purpose Lisp dialects are Common Lisp and Scheme.

Lisp was originally created as a practical mathematical notation for computer programs, influenced by the notation of Alonzo Church‘s lambda calculus. It quickly became the favored programming language for artificial intelligence (AI) research. As one of the earliest programming languages, Lisp pioneered many ideas in computer science, including tree data structures, automatic storage management, dynamic typing, conditionals, higher-order functions, recursion, and the self-hosting compiler.[2]

The name LISP derives from “LISt Processing”. Linked lists are one of Lisp language’s major data structures, and Lisp source code is itself made up of lists. As a result, Lisp programs can manipulate source code as a data structure, giving rise to the macro systems that allow programmers to create new syntax or even new domain-specific languages embedded in Lisp.

The interchangeability of code and data also gives Lisp its instantly recognizable syntax. All program code is written as s-expressions, or parenthesized lists. A function call or syntactic form is written as a list with the function or operator’s name first, and the arguments following; for instance, a function f that takes three arguments might be called using (f arg1 arg2 arg3).

Lisp was invented by John McCarthy in 1958 while he was at the Massachusetts Institute of Technology (MIT). McCarthy published its design in a paper in Communications of the ACM in 1960, entitled “Recursive Functions of Symbolic Expressions and Their Computation by Machine, Part I”[3] (“Part II” was never published). He showed that with a few simple operators and a notation for functions, one can build a Turing-complete language for algorithms.

Information Processing Language was the first AI language, from 1955 or 1956, and already included many of the concepts, such as list-processing and recursion, which came to be used in Lisp.

McCarthy’s original notation used bracketed “M-expressions” that would be translated into S-expressions. As an example, the M-expression car[cons[A,B]] is equivalent to the S-expression (car (cons A B)). Once Lisp was implemented, programmers rapidly chose to use S-expressions, and M-expressions were abandoned. M-expressions surfaced again with short-lived attempts of MLISP[4] by Horace Enea and CGOL by Vaughan Pratt.

After having declined somewhat in the 1990s, Lisp has recently experienced a resurgence of interest. Most new activity is focused around open source implementations of Common Lisp, and includes the development of new portable libraries and applications. A new print edition of Practical Common Lisp by Peter Seibel, a tutorial for new Lisp programmers, was published in 2005.[20]

Many new Lisp programmers were inspired by writers such as Paul Graham and Eric S. Raymond to pursue a language others considered antiquated. New Lisp programmers often describe the language as an eye-opening experience and claim to be substantially more productive than in other languages.[21] This increase in awareness may be contrasted to the “AI winter” and Lisp’s brief gain in the mid-1990s.[22]

Dan Weinreb lists in his survey of Common Lisp implementations[23] eleven actively maintained Common Lisp implementations. Scieneer Common Lisp is a new commercial implementation forked from CMUCL with a first release in 2002.

The open source community has created new supporting infrastructure: CLiki is a wiki that collects Common Lisp related information, the Common Lisp directory lists resources, #lisp is a popular IRC channel (with support by a Lisp-written Bot), lisppaste supports the sharing and commenting of code snippets, Planet Lisp collects the contents of various Lisp-related blogs, on LispForum users discuss Lisp topics, Lispjobs is a service for announcing job offers and there is a weekly news service, Weekly Lisp News. Common-lisp.net is a hosting site for open source Common Lisp projects.

50 years of Lisp (1958–2008) has been celebrated at LISP50@OOPSLA.[24] There are regular local user meetings in Boston, Vancouver, and Hamburg. Other events include the European Common Lisp Meeting, the European Lisp Symposium and an International Lisp Conference.

The Scheme community actively maintains over twenty implementations. Several significant new implementations (Chicken, Gambit, Gauche, Ikarus, Larceny, Ypsilon) have been developed in the last few years. The Revised5 Report on the Algorithmic Language Scheme[25] standard of Scheme was widely accepted in the Scheme community. The Scheme Requests for Implementation process has created a lot of quasi standard libraries and extensions for Scheme. User communities of individual Scheme implementations continue to grow. A new language standardization process was started in 2003 and led to the R6RS Scheme standard in 2007. Academic use of Scheme for teaching computer science seems to have declined somewhat. Some universities are no longer using Scheme in their computer science introductory courses.[citation needed]

There are several new dialects of Lisp: Arc, Nu, and Clojure.

The two major dialects of Lisp used for general-purpose programming today are Common Lisp and Scheme. These languages represent significantly different design choices.

Common Lisp is a successor to MacLisp. The primary influences were Lisp Machine Lisp, MacLisp, NIL, S-1 Lisp, Spice Lisp, and Scheme.[26] It has many of the features of Lisp Machine Lisp (a large Lisp dialect used to program Lisp Machines), but was designed to be efficiently implementable on any personal computer or workstation. Common Lisp has a large language standard including many built-in data types, functions, macros and other language elements, as well as an object system (Common Lisp Object System or shorter CLOS). Common Lisp also borrowed certain features from Scheme such as lexical scoping and lexical closures.

Scheme (designed earlier) is a more minimalist design, with a much smaller set of standard features but with certain implementation features (such as tail-call optimization and full continuations) not necessarily found in Common Lisp.

Scheme is a statically scoped and properly tail-recursive dialect of the Lisp programming language invented by Guy Lewis Steele Jr. and Gerald Jay Sussman. It was designed to have exceptionally clear and simple semantics and few different ways to form expressions. A wide variety of programming paradigms, including imperative, functional, and message passing styles, find convenient expression in Scheme. Scheme continues to evolve with a series of standards (Revisedn Report on the Algorithmic Language Scheme) and a series of Scheme Requests for Implementation.

Clojure is a recent dialect of Lisp that principally targets the Java Virtual Machine, as well as the CLR, the Python VM, the Ruby VM YARV, and compiling to JavaScript. It is designed to be a pragmatic general-purpose language. Clojure draws considerable influences from Haskell and places a very strong emphasis on immutability.[27] Clojure is a compiled language, as it compiles directly to JVM bytecode, yet remains completely dynamic. Every feature supported by Clojure is supported at runtime. Clojure provides access to Java frameworks and libraries, with optional type hints and type inference, so that calls to Java can avoid reflection and enable fast primitive operations.

In addition, Lisp dialects are used as scripting languages in a number of applications, with the most well-known being Emacs Lisp in the Emacs editor, AutoLisp and later Visual Lisp in AutoCAD, Nyquist in Audacity. The small size of a minimal but useful Scheme interpreter makes it particularly popular for embedded scripting. Examples include SIOD and TinyScheme, both of which have been successfully embedded in the GIMP image processor under the generic name “Script-fu”.[28] LIBREP, a Lisp interpreter by John Harper originally based on the Emacs Lisp language, has been embedded in the Sawfish window manager.[29] The Guile interpreter is used in GnuCash. Within GCC, the MELT plugin provides a Lisp-y dialect, translated into C, to extend the compiler by coding additional passes (in MELT).

Lisp was the first homoiconic programming language: the primary representation of program code is the same type of list structure that is also used for the main data structures. As a result, Lisp functions can be manipulated, altered or even created within a Lisp program without extensive parsing or manipulation of binary machine code. This is generally considered one of the primary advantages of the language with regard to its expressive power, and makes the language amenable to metacircular evaluation.

The ubiquitous if-then-else structure, now taken for granted as an essential element of any programming language, was invented by McCarthy for use in Lisp, where it saw its first appearance in a more general form (the cond structure). It was inherited by ALGOL, which popularized it.

Lisp deeply influenced Alan Kay, the leader of the research on Smalltalk, and then in turn Lisp was influenced by Smalltalk, by adopting object-oriented programming features (classes, instances, etc.) in the late 1970s. The Flavours object system (later CLOS) introduced multiple inheritance.

Lisp introduced the concept of automatic garbage collection, in which the system walks the heap looking for unused memory. Most of the modern sophisticated garbage collection algorithms such as generational garbage collection were developed for Lisp.

Largely because of its resource requirements with respect to early computing hardware (including early microprocessors), Lisp did not become as popular outside of the AI community as Fortran and the ALGOL-descended C language. Because of its suitability to complex and dynamic applications, Lisp is currently enjoying some resurgence of popular interest.

Emacs (pron.: /ˈmæks/) and its derivatives are a family of text editors that are characterized by their extensibility. The manual for one variant describes it as “the extensible, customizable, self-documenting, real-time display editor.”[2] Development began in the mid-1970s and continues actively as of 2013. Emacs has over 2,000 built-in commands and allows the user to combine these commands into macros to automate work. The use of Emacs Lisp, a variant of the Lisp programming language, provides a deep extension capability.

The original EMACS was written in 1976 by Richard Stallman and Guy L. Steele, Jr. as a set of Editor MACroS for the TECO editor.[3][4][5][6] It was inspired by the ideas of the TECO-macro editors TECMAC and TMACS.[7]

Emacs became, along with vi, one of the two main contenders in the traditional editor wars of Unix culture. The word “emacs” is often pluralized as emacsen by analogy with boxen and VAXen.[8]

The most popular, and most ported, version of Emacs is GNU Emacs, which was created by Stallman for the GNU Project.[9] XEmacs is a common variant that branched from GNU Emacs in 1991. Both of the variants use Emacs Lisp and are for the most part compatible with each other.

SLIME, the Superior Lisp Interaction Mode for Emacs, is an Emacs mode for developing Common Lisp applications. SLIME originates in an Emacs mode called SLIM written by Eric Marsden and developed as an open-source project by Luke Gorrie and Helmut Eller. Over 100 Lisp developers have contributed code to SLIME since the project was started in 2003. SLIME uses a backend called SWANK that is loaded into Common Lisp.

SLIME works with the following Common Lisp implementations:

Some implementations of other programming languages are using SLIME:

There’s a remarkable amount of Emacs Lisp programs out there, and they do just about everything, from providing handy mail quoting utilities to providing an Emacs interface to IMDB and more! And while many such elisp hacks come bundled with Emacs, there are even more out there on the Internet, just waiting for you to try them out. The Emacs Lisp List and the EmacsWiki are both great resources for finding interesting and useful elisp.

So, you’ve gone and downloaded some elisp file (foo.el, say). Now, what do you do with it? Well, the community convetion on the matter is to toss .el files in, say, ~/elisp/ (an elisp directory in your home directory). Once you have such a directory you need to ensure that it’s present in Emacs’ load-path variable. This is typically done by adding something like this to your ~/.emacs file:

(add-to-list 'load-path "~/elisp")

Next, you’ll need to configure Emacs to load the new file. Most of the time, you should be able to add (require 'foo) to ~/.emacs (where foo means foo.el).

Simplify! Use install.el

That’s often all you have to do, but there are lots of exceptions. Fortunately, Stefan Monnier’s install.el handles the vast majority of elisp files you’ll run into, and is very easy to use itself. Install it by following my directions above. Now, whenever you’d like to install an elisp file, simply invoke the install-file command (via M-x install-file RET). That’s it!

NEWS: EMACS 24.3 is finally available!

– emacs24 will be updated only when I change the build process or when new emacs24 versions are realeased
– emacs-snapshot are updated between once a week and once every two weeks on average. These versions are created from those of Julien Danjou for Debian unstable: http://emacs.naquadah.org/.

To build this PPA, I created this script: https://gist.github.com/2360655

Please report bugs to https://bugs.launchpad.net/emacs-snapshot/, but before reporting, please follow these steps that will ensure a clean installation:

$ sudo apt-get update
$ sudo apt-get install
$ sudo apt-get purge emacs-snapshot-common emacs-snapshot-bin-common emacs-snapshot emacs-snapshot-el emacs-snapshot-gtk emacs23 emacs23-bin-common emacs23-common emacs23-el emacs23-nox emacs23-lucid auctex emacs24 emacs24-bin-common emacs24-common emacs24-common-non-dfsg

To add this PPA:
$ sudo add-apt-repository ppa:cassou/emacs
$ sudo apt-get update

Then, for emacs-snapshot:
$ sudo apt-get install emacs-snapshot-el emacs-snapshot-gtk emacs-snapshot

*Or*, for emacs24:
$ sudo apt-get install emacs24 emacs24-el emacs24-common-non-dfsg

Adding this PPA to your system

You can update your system with unsupported packages from this untrusted PPA by adding ppa:cassou/emacs to your system’s Software Sources. (Read about installing)

Lisp y Scheme

Una de las cosas que me llaman la atención es la convicción tan grande que los programadores de Lisp tienen en el poder de sus paréntesis.

Aún en el contexto de desarrollo Web Paul Graham ha llamado a Lisp su arma secreta, y en el manual de como convertirse en un Hacker de Eric Steven Raymond Lisp se presenta como un experiencia mística. Peter Norvig, en Teach Yourself Programming in Ten Years recomienda aprender lenguajes que soporten abstracción de clases (como Java), abstracción funcional (como Lisp), abstracción sintáctica (como Lisp), especificación declarativa (como Prolog), corutinas (como Scheme), y paralelismo (como Sisal).

El enfoque funcional parece ser fundamental y, por ejemplo, el equipo de desarrollo de C# ha hecho un esfuerzo por soportar este paradigma en la nueva versión a través del mecanismo de delegados.

Es claro que el río suena porque agua lleva. Para el interesado hay material introductorio abundante pero lograr la iluminación requerirá tiempo y esfuerzo.

Para Lisp, como lo indica su nombre, todo son listas y los comando básicos (constructors, selectors y recognizers) son para manipular las mismas:

quote para diferenciar una lista de una llamada a función.
first y rest para separar listas en sus partes.
cons para construir listas.
null y consp para ver si una lista esta vacía.
member para verificar si un elemento es miembro de una lista.
append para unir listas.

Lisp tiene varios dialectos: Common Lisp y Scheme son algunos de los más difundidos. CLisp es un implementación de Common Lisp y Visual CLisp es un puerto a Windows con un GUI. Otra alternativa es CMUCL.

Dorai Sitaram tiene un sitio con ligas a recursos sobre Scheme y Common Lisp, incluyendo un tutorial bastante bueno.

drscheme incluye varias implementaciones de Scheme bajo una interfaz común orientada a un ambiente académico.
Las funciones de Scheme para manipular listas son:

cons
toma dos argumentos y regresa un par o lista.
(cons '1 '2)              is   (1 . 2)

 

El primer ejemplo es un par y los otros son listas. Pares o listas se pueden utilizar para implementar registros.

carregresa el primer miembro de una lista o par.

(car '(123 245 564 898))             is   123

 

cdrregresa la lista sin el primer elemento.

(cdr '(7 6 5))               is  (6 5)

 

null?regresa #t si el objeto es la lista nula. En cualquier otro caso regresa la lista nula.listregresa un alista construida de los argumentos.

(list 'a)                          is  (a)

 

lengthregresa la longitud de la lista.

     (length '(1 3 5 9 11)) is  5

 

reverseregresa la lista invertida.

     (reverse '(1 3 5 9 11)) is  (11 9 5 3 1)

 

appendregresa la concatenación de dos listas.

     (append '(1 3 5)  '(9 11))  is  (1 3 5 9 11)

 

Expresiones condicionales son de la forma:

(if test-exp then-exp)
(if test-exp then-exp else-exp).

Definiciones son de la forma:

     (define id exp)

 

Expresiones Lambda son funciones anónimas de la forma:

         (lambda (id...) exp )

 

Definiciones locales se introducen con las funciones let, let* y letrec. let se aplica en paralelo, let* es secuencial, y letrec permite definiciones recursivas.

 

  • apply regresa el resultado de aplicar el primer argumento al segundo.

 

1 ]=>  (apply + '(7 5)) 

;Value:   12 

1 ]=>  (apply max '(3 7 2 9))
 

;Value:   9

 

  • map regresa una lista que es el resultado de aplicar el primer argumento a cada elemento del segundo.

 

1 ]=>   (map odd? '(2 3 4 5 6)) 

;Value: (() #T () #T ())

Referencias:

The Allegro Common Lisp Open Source Center

Allegro CL

http://www.cs.berkeley.edu/~fateman/generic/

Richard J. Fateman

Algoritmos en Scheme

Taller sobre Scheme

Hobbit versión 5 compila R4RS Scheme a código C, que se puede usar con SCM Scheme Implementation

El paquete SLIB es una librería portable del lenguaje Scheme que funciona en varias plataformas e implementaciones, incluyendo Guile.

null nil

Language null true false
Java null true false
Python None True False
Objective-C nil, or NULL, or [NSNull null],
depending on context
YES NO
C NULL anything except 0 0
Lisp NIL T NIL

Objective-C is psychotic. It’s a Smalltalk dialect built on top of C (and for the most part, it got the good bits of both and left out the bad bits). Obj-C lets you instantiate arrays like [NSArray arrayWithObjects:@"Hello", @"World", nil], using nil as an end-of-array marker because C’s varargs implementation doesn’t know how many args you passed. So it has this extra “null” object that’s not really null.