Lisp (programming language)

Asniashiq
4 min readAug 7, 2023

--

“LISP” redirects here. For the speech impediment, see Lisp.

source: ITNEXT

Lisp:

source: Wikipedia

Lisp (historically LISP, an acronym for list processing) is a family of programming languages with a long history and a distinctive, fully parenthesis prefix notation. Originally specified in 1960, Lisp is the second-oldest high-level programming language still in common use, after Fortran Lisp has changed since its early days, and many dialects have existed over its history. Today, the best-known general-purpose Lisp dialects are Common Lisp, Scheme, Racket, and Clojure.

source: CEAT

Lisp is a family of programming languages known for their unique and distinctive syntax, as well as their powerful support for symbolic computation and code as data. The name “Lisp” stands for “LISt Processing,” as the language primarily operates on linked lists. It was originally developed in the late 1950s by John McCarthy at the Massachusetts Institute of Technology (MIT).

Key features of Lisp include:

  1. S-expressions: Lisp code is written in S-expressions, which are nested lists composed of atoms and other S-expressions. The basic syntax consists of parentheses, which can represent both data and code.
  2. Code as data: In Lisp, programs can be manipulated as data, allowing metaprogramming and the creation of powerful macros. This feature is often referred to as “code is data” or “homoiconicity.”
  3. Dynamic typing: Lisp is dynamically typed, meaning that variables can hold values of any type, and their type is determined at runtime.
  4. Garbage collection: Lisp implementations typically include automatic memory management through garbage collection, which handles memory allocation and deallocation.
  5. Symbolic computation: Lisp is widely used in artificial intelligence and symbolic computation due to its expressive power and support for symbolic manipulation.
  6. Functional programming: Lisp supports functional programming paradigms, where functions are first-class citizens, allowing higher-order functions and functional composition.
  7. Interactive development: Lisp systems often feature interactive development environments, which facilitate incremental development and real-time debugging.

Common Lisp and Scheme are two prominent dialects of Lisp, each with its own distinctive features and use cases.

  • Common Lisp: Common Lisp is a standardized and feature-rich dialect of Lisp. It has a large standard library, object-oriented programming capabilities through the CLOS (Common Lisp Object System), and is suitable for large-scale software development.
  • Scheme: Scheme is a minimalist dialect of Lisp, known for its simplicity and adherence to a small set of core principles. It has a strong focus on lexical scoping and tail recursion, making it a popular choice for teaching programming concepts.

Symbolic expressions (S-expressions):

Lisp is an expression_oriented language. Unlike most other languages, no distinction is made between “expressions” and “statements”;[debuius_dicuss] all code and data are written as expressions. When an expression is evaluated, it produces a value (possibly multiple values), which can then be embedded into other expressions. Each value can be any data type.

Lists:

A Lisp list is written with its elements separated by whitespace, and surrounded by parentheses. For example, (1 2 foo) is a list whose elements are the three atoms 1, 2, and foo. These values are implicitly typed: they are respectively two integers and a Lisp-specific data type called a "symbol", and do not have to be declared as such.

(list 1 2 (quote foo))

evaluates to the list (1 2 foo).

(list 1 2 (list 3 4))

evaluates to the list (1 2 (3 4)). Note that the third argument is a list; lists can be nested.

Operators:

Arithmetic operators are treated similarly. The expression

(+ 1 2 3 4)

evaluates to 10. The equivalent under infix notation would be “1 + 2 + 3 + 4".

(inc x)

equivalent to (setq x (+ x 1)), returning the new value of x.

Examples:

Here are examples of Common Lisp code.

The basic “Hello, World!” program:

(print "Hello, World!")

For example, to evaluate a number’s factorial:

(defun factorial (n)
(if (zerop n) 1
(* n (factorial (1- n)))))

An alternative implementation takes less stack space than the previous version if the underlying Lisp system optimizes tail recursion:

(defun factorial (n &optional (acc 1))
(if (zerop n) acc
(factorial (1- n) (* acc n))))

Contrast the examples above with an iterative version which uses Common Lisp’s loop macro:

(defun factorial (n)
(loop for i from 1 to n
for fac = 1 then (* fac i)
finally (return fac)))

The following function reverses a list. (Lisp’s built-in reverse function does the same thing.)

(defun -reverse (list)
(let ((return-value))
(dolist (e list) (push e return-value))
return-value))

Lisp has influenced many other programming languages and paradigms, and its impact can be seen in areas such as functional programming, metaprogramming, and domain-specific languages. Although not as widely used as mainstream languages like Python, Java, or C++, Lisp remains an influential and respected language in the history of computing.

--

--