What made Lisp special

Β«The greatest programming language ever createdΒ«
β€” Alan Kay, "on Lisp"

What made Lisp special

When McCarthy developed Lisp in the late 1950s, it was radically different from existing languages, the most important of which was Fortran.

Lisp introduced nine new ideas:

1. Conditionals. Conditional statements are if-then-else constructions. Now we take them for granted. They were invented McCarthy during the development of Lisp. (Fortran at the time only had goto statements, closely coupled to a branch instruction on the underlying hardware.) McCarthy, while on the Algol committee, contributed conditionals to Algol, from where they spread to other languages.

2. A function type. In Lisp, functions are first-class objects - they are a data type, just like numbers, strings, etc., and have a literal representation, can be stored in variables, can be passed as arguments, etc.

3. Recursion. Recursion, of course, existed as a mathematical concept before Lisp, but Lisp was the first programming language to support it. (This is perhaps implied in creating functions as first-class objects.)

4. A new concept of variables. In Lisp, all variables are effective pointers. Values ​​are what types have, not variables, and assigning or binding variables means copying pointers, not what they point to.

5. Garbage collection.

6. Programs composed of expressions. Lisp programs are trees of expressions, each of which returns a value. (Some Lisp expressions can return multiple values.) This contrasts with Fortran and many other successful languages ​​that distinguish between β€œexpressions” and β€œstatements.”

It was natural to have this distinction in Fortran because the language was line-oriented (not surprising for a language whose input format was a punched card). You couldn't have nested statements. And as long as you needed mathematical expressions to work, there was no point in having anything else return a value because there might not be anything waiting to be returned.

The restrictions were lifted with the advent of block-structured languages, but by then it was too late. The distinction between expressions and statements has already been established. It passed from Fortran to Algol and further to their descendants.

When a language is made entirely of expressions, you can compose expressions any way you want. You can write either (using the syntax Arc)

(if foo (= x 1) (= x 2))

or

(= x (if foo 1 2))

7. A symbol type. Characters are different from strings, in which case you can check for equality by comparing pointers.

8. A notation for code using symbol trees.

9. The whole language is always available. There is no obvious difference between read time, compile time and run time. You can compile or run code while you read, or read or run code while you compile, or read or compile code while it runs.

Running code while reading allows users to reprogram Lisp's syntax; running code at compile time is the basis for macros; runtime compilation is the basis for using Lisp as an extension language in programs such as Emacs; and finally, runtime reading allows programs to communicate using s-expressions, an idea recently reinvented in XML.

Conclusion

When Lisp was first invented, these ideas were a far cry from conventional programming practices dictated by the hardware available in the late 1950s.

Over time, the default language, embodied by the success of popular languages, gradually evolved towards Lisp. Points 1-5 are now widely accepted. Point 6 is starting to appear in the mainstream. In Python, there is a clause 7 in some form, although there is no suitable syntax. Item 8, which (with item 9) makes macros possible in Lisp, is still only in Lisp, probably because (a) it requires those parentheses or something equally bad, and (b) if you add this latest increase in power, you can no longer claim to have invented a new language, but only to have developed a new dialect of Lisp; -)

Although this is useful for modern programmers, it is strange to describe Lisp in terms of its difference from the random techniques adopted in other languages. This may not be what McCarthy was thinking. Lisp was not designed to correct Fortran's errors; it appeared more as a by-product of trying axiomatize calculations.

Source: habr.com

Add a comment