diff.txt 4.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. December 2001 (rev. May 2002)
  2. (This article came about in response to some questions on
  3. the LL1 mailing list. It is now
  4. incorporated in Revenge of the Nerds.)When McCarthy designed Lisp in the late 1950s, it was
  5. a radical departure from existing languages,
  6. the most important of which was Fortran.Lisp embodied nine new ideas:
  7. 1. Conditionals. A conditional is an if-then-else
  8. construct. We take these for granted now. They were
  9. invented
  10. by McCarthy in the course of developing Lisp.
  11. (Fortran at that time only had a conditional
  12. goto, closely based on the branch instruction in the
  13. underlying hardware.) McCarthy, who was on the Algol committee, got
  14. conditionals into Algol, whence they spread to most other
  15. languages.2. A function type. In Lisp, functions are first class
  16. objects-- they're a data type just like integers, strings,
  17. etc, and have a literal representation, can be stored in variables,
  18. can be passed as arguments, and so on.3. Recursion. Recursion existed as a mathematical concept
  19. before Lisp of course, but Lisp was the first programming language to support
  20. it. (It's arguably implicit in making functions first class
  21. objects.)4. A new concept of variables. In Lisp, all variables
  22. are effectively pointers. Values are what
  23. have types, not variables, and assigning or binding
  24. variables means copying pointers, not what they point to.5. Garbage-collection.6. Programs composed of expressions. Lisp programs are
  25. trees of expressions, each of which returns a value.
  26. (In some Lisps expressions
  27. can return multiple values.) This is in contrast to Fortran
  28. and most succeeding languages, which distinguish between
  29. expressions and statements.It was natural to have this
  30. distinction in Fortran because (not surprisingly in a language
  31. where the input format was punched cards) the language was
  32. line-oriented. You could not nest statements. And
  33. so while you needed expressions for math to work, there was
  34. no point in making anything else return a value, because
  35. there could not be anything waiting for it.This limitation
  36. went away with the arrival of block-structured languages,
  37. but by then it was too late. The distinction between
  38. expressions and statements was entrenched. It spread from
  39. Fortran into Algol and thence to both their descendants.When a language is made entirely of expressions, you can
  40. compose expressions however you want. You can say either
  41. (using Arc syntax)(if foo (= x 1) (= x 2))or(= x (if foo 1 2))7. A symbol type. Symbols differ from strings in that
  42. you can test equality by comparing a pointer.8. A notation for code using trees of symbols.9. The whole language always available.
  43. There is
  44. no real distinction between read-time, compile-time, and runtime.
  45. You can compile or run code while reading, read or run code
  46. while compiling, and read or compile code at runtime.Running code at read-time lets users reprogram Lisp's syntax;
  47. running code at compile-time is the basis of macros; compiling
  48. at runtime is the basis of Lisp's use as an extension
  49. language in programs like Emacs; and reading at runtime
  50. enables programs to communicate using s-expressions, an
  51. idea recently reinvented as XML.
  52. When Lisp was first invented, all these ideas were far
  53. removed from ordinary programming practice, which was
  54. dictated largely by the hardware available in the late 1950s.Over time, the default language, embodied
  55. in a succession of popular languages, has
  56. gradually evolved toward Lisp. 1-5 are now widespread.
  57. 6 is starting to appear in the mainstream.
  58. Python has a form of 7, though there doesn't seem to be
  59. any syntax for it.
  60. 8, which (with 9) is what makes Lisp macros
  61. possible, is so far still unique to Lisp,
  62. perhaps because (a) it requires those parens, or something
  63. just as bad, and (b) if you add that final increment of power,
  64. you can no
  65. longer claim to have invented a new language, but only
  66. to have designed a new dialect of Lisp ; -)Though useful to present-day programmers, it's
  67. strange to describe Lisp in terms of its
  68. variation from the random expedients other languages
  69. adopted. That was not, probably, how McCarthy
  70. thought of it. Lisp wasn't designed to fix the mistakes
  71. in Fortran; it came about more as the byproduct of an
  72. attempt to axiomatize computation.