What made Lisp special

" The greatest programming language ever created "

- Alan Kay, “on Lisp”






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



Lisp has implemented nine new ideas:



1. Conditionals . Conditional statements are an if-then-else construct. Now we take them for granted. They were invented by McCarthy during the development of Lisp. (Fortran at the time had only goto statements that were closely related to branch instructions on the underlying hardware.) McCarthy, while on the Algol committee, made conditional statements in Algol, from where they spread to other languages.



2. Function types (A function type) . In Lisp, functions are objects of the first class - they are a data type, 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 possibly implied in creating functions as first-class objects.)



4. A new concept of variables . In Lisp, all variables are efficient 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 are composed of expressions (Programs composed of expressions) . Lisp programs are expression trees, 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 such a difference in Fortran because the language was linearly oriented (not surprising for a language in which the input format was a punched card). You could not have nested statements. And while you needed mathematical expressions to work, there was no point in forcing something else to return a value, because there might not have been something that was waiting for a return.



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



When the language is made entirely of expressions, you can make expressions as you wish. You can write either (using Arc syntax)



(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 the pointers.



8. A notation for code using trees from characters.



9. The whole language always available . There is no apparent difference between read time, compile time, and runtime. You can compile or run code while reading, or read or run code while you compile, or read or compile code at runtime.



Running code while reading allows users to reprogram Lisp 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 like Emacs; and finally, run-time reading allows programs to interact using s-expressions, an idea recently reinvented in XML.



Conclusion



When Lisp was just invented, all of these ideas were very far from the usual programming practices that were dictated by the hardware available in the late 1950s.



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



Although it is useful for modern programmers, it is strange to describe Lisp in terms of how it differs from random tricks accepted in other languages. Perhaps this is not what McCarthy was thinking. Lisp was not designed to fix Fortran errors; it appeared more as a by-product of an attempt to axiomatize computations .



All Articles