- This FAQ should currently be read sequentially.
- Lisp General Frequently Asked Questions v0.01:
- Why should I learn Lisp?
- ================================
- Lisp is a commonly misunderstood language.
- There's a great deal of misinformation spread about it, which this FAQ will attempt to address.
- You would be best off to leave your current notions of what Lisp is behind.
- Lisp is a language designed to manipulate lists.
- Lisp stands for LISt Processing.
- As it would be, Lisp programs are stored as lists, which is the data that Lisp manipulates, making Lisp a language also targetted at metaprogramming.
- This is the main draw of Lisp, as it means that you can program the language itself and suit it to your needs and wants.
- Lisp is a much more powerful language than those commonly used, such as C/C++, Java, and Python.
- The difficulty for beginning users of Lisp is the very different syntax, which is largely not there, and the somewhat advanced concepts that it handles.
- Here is an essay by Paul Graham that, I believe, can explain this better:
- http://www.paulgraham.com/avg.html
- Why do people say Lisp is only good for AI?
- ================================
- John Mccarthy conceived Lisp between 1956 and 1958, when he worked as an AI researcher at MIT.
- Lisp became the language most commonly used in AI for its several advantages, including garbage collection, the symbol datatype, which is basically a datatype specifically for arbitrary labels for any datatype, its metaprogramming facilities, and the ease with which it could be used, as many languages require programming, compiling, and debugging, whereas Lisp encourages incremental programming.
- Lisp was commonly used as the notation to express algorithms in AI research papers, which works well considering the symbolic nature of it.
- Lisp also supports a lot of abstraction from the machine and versatile data structures which make coding easier for hard problems, such as those presented in artificial intelligence and machine learning.
- Is Lisp slow?
- ================================
- Back in the 60s, 70s, and even in the 80s, Lisp was slow.
- Lisp was not designed with current machines in mind, as languages like C were, leading to a greater focus on solving problems than other languages, which often bog the programmer down with irrelevent details and boilerplate, which is commonly repeated segments of code.
- Lisp programmers are expected to focus more on the algorithms and problems than exactly what the machine is doing, in contrast to languages like C and C++.
- Focus was never put so much on fast computation as on clear expression of computational ideas.
- But today, unless you *really* need very tight control over the machine or need to make computations as fast as possible, you shouldn't have much trouble with Lisp.
- Moreover, new implementations such as SBCL give you great control over the resulting binary, such as turning off the garbage collector, optimizing tail recursion, giving an interface to the assembler language, etc.
- Lisp is not inherently slow and is actually quite fast nowadays.
- Why don't companies use Lisp?
- ================================
- This is a touchy question, and it involves some history.
- Back in the 80's there was the "AI boom", and people at different companies tried to solve big problems in AI research.
- As computers grew stronger in memory and speed, they made the mistake of trivializing most of these problems, wasting the funds on unfounded promises.
- When people realized these problems were harder than they thought, there came a feeling of resentment towards AI (Conrad Barsky calls it the "AI winter"), and people abandoned the idea almost completely.
- As Lisp was mainly known for AI, Lisp was also dragged down by all of this.
- Then came the promise of Object Oriented Programming, and the mainstream teaching of it in universities, mostly using Java.
- It is now easy to see why companies use java and not Lisp.
- Rest assured, there are still Lisp jobs out there, but there are not nearly as much as for more mainstream languages.
- Here is just one relevant essay that addresses this:
- http://www.lambdassociates.org/blog/bipolar.htm
- A prominent Lisper, Erik Naggum, also has on opinion on this issue:
- neurosurgery is another field that requires an actual investment and lots of
- dedication to get into, is really rewarding to those who get good at it, but
- whose jobs are not advertised in regular newspapers. there is a shortage of
- neurosurgeons, but very little advertising in the media that the patients read.
- programming is both similar and different. whether you are a user or a
- programmer these days is often hard to tell (this has good qualities to it, too),
- but some programming tasks are still reserved to highly skilled people who are
- not afraid to take huge risks. ignoring for a moment the power of the American
- Medical Association, we still wouldn’t see a huge amount of books on
- neurosurgery for dummies in 21 days or whatever. it’s just plain inappropriate,
- and it’s intentionally out of people’s reach.
- Lisp is somewhat like that. people can get lots of medicines at the drugstore,
- but they can’t be trusted to carve out a malignant tumor in their child’s brain.
- all sorts of users can do lots of customization and cool stuff in their “apps”,
- but they really can’t be trusted to run actual flight control systems, configure
- the telephone network, write software for video-synchronized magnetic-resonance
- imaging for brain surgery, or write automated stock-trading systems. at some
- point, the risk of letting unskilled people do the task becomes too high. that’s
- when you can’t trust more than 1% of the programmers out there, and a
- surprisingly large number of them know and use Lisp and tools that are can be
- trusted. (consider an ATM that gets one of those frequent Windows crashes, or a
- naval warfare vessel that has to cold-boot because a certain display suddenly
- goes all blue, or any other story in comp.risks that would have been hilarious
- if it had been a joke.)
- Why is Lisp so different from every other language?
- ================================
- Lisp is often mistaken to be a functional programming language.
- Though most Lisp users adopt a relaxed functional style, Lisp itself is beyond these matters.
- Lisp itself is small and general enough to express any currently existing paradigm.
- What mostly shocks people who come to Lisp is the parentheses.
- There's a joke that Lisp stands for "Lots of Isolated Stupid Parentheses" or variations of such.
- It really stands for LISt Processing, and this is exactly the reason why Lisp uses a lot of parentheses, and only parentheses.
- The syntax is also expanded through reader macros, described further below.
- The list is Lisp's main data structure, so much that Lisp programs are lists themselves!
- All data, and thusly code, in Lisp is expressed by lists and the data lists hold.
- Due to this, Lisp is a language particularly suited to metaprogramming, since it's targetted domain is the same form it uses to express its programs.
- The extremely regular syntax also helps.
- This is the main power of Lisp and it led to some advanced concepts that algol-likes, such as C, don't have, such as safe runtime manipulation of code and safe interpretation of data as code.
- What is Lambda calculus?
- ================================
- Lambda calculus is a mathematical notation devised by logician Alonzo Church, which Alan Turing proved to be Turing-complete, meaning that it can do anything that a Turing Machine can.
- The main goal of lambda calculus was to make the smallest universal programming language.
- Of course it was developed in the 30s, when digital computers weren't even available for academics.
- The lambda calculus consists mainly of lambda expressions, which we call "anonymous functions", as they have no names.
- Such anonymous functions look sort of like this:
- λx.x
- This is the identity function in lambda notation.
- The greek letter lambda (λ) is how we know that a function comes next.
- The x is the parameter of the function, and everything after the dot is the value "returned" by the function.
- If you're interested, you should probably search the pastebin and elsewhere for some books on lambda calculus.
- So Lisp is a language?
- ================================
- It was originally, but now Lisp is a family of programing languages.
- Since it's inception, many people extended it adding new ideas and dozens of different dialects came to light.
- For quite a while, Lisp dialects existed as implementations that were not standardized, as many languages exist nowadays.
- There was a great deal of fragmentation and quirks in Lisp implementations that were beginning to cause problems in research and business communities.
- There was a need for standarization and Common Lisp was the fruit of the efforts to combine many of the popular and influential dialects of the time.
- Common Lisp is commonly regarded as one of the standard Lisps, along with Scheme and Emacs Lisp.
- Common Lisp was designed around the portability of code between implementations and "practicality".
- Scheme is mostly used in academia and research as well as providing powerful embedded extension and scripting languages for larger programs.
- Emacs Lisp is the dialect used to extend Emacs.
- Shen has a powerful type system and takes portability to the extreme by being able to be hosted on a variety of languages and runtimes.
- Clojure is a dialect lauded for its immutability by default and running on the JVM.
- Arc is a rather unpopular dialect created by Paul Graham for what he thinks of as hacking.
- PicoLisp is a small Lisp designed around simplicity; of interest is its database features.
- Which dialect should I learn?
- ================================
- Common Lisp, Scheme, and Emacs Lisp are currently regarded as the main Lisps.
- You should ignore the other Lisps for now unless you have a good reason not to.
- Emacs Lisp can be a good dialect to start with.
- Emacs is a particularly good editor for Lisp programming and the Emacs Lisp dialect is very well documented by GNU, including an introduction, a standard description, and an introduction to the Emacs editor.
- If you are adament about not using Emacs, then you have no reason to learn Emacs Lisp.
- If not, then it is a particularly good start.
- Emacs Lisp resembles Common Lisp in many ways; it would be easy to start with Emacs Lisp and later switch to Common Lisp if you wanted.
- Scheme is a less standardized dialect that has differing idioms in comparison.
- The different Lisp communities tend to be opinionated in how the basics are done with each dialect.
- Scheme is mostly commonly used for teaching and other academic purposes, due to its simplicity and advanced concepts, such as hygienic macros.
- Common Lisp was designed to be a large and "practical" language for general use.
- Common Lisp merged many of the features found in several older competing dialects of Lisp and has many features for code to be portable between implementations.
- The Scheme standard is very small by design and defines a core language from which everything is derived.
- The disadvantage of this approach is fragmentation with each Scheme implementation supplementing the nonstandard features, like networking, differently, making portable code impractical or impossible.
- GNU Guile is an implementation of Scheme designed by the GNU project as a standard extension language, mostly for C programs.
- Racket is one implementation derived from extensive programming language research and experimentation.
- Racket is said to resemble Common Lisp in terms of offered features.
- Common Lisp was designed to fix a fragmentation problem similar to Scheme's, but among the older dialects.
- Common Lisp defines many of the standard facilities in detail, such as debugging, filesystem interaction, etc.
- Scheme is usually considered to be friendlier than Common Lisp, due to its simplicity.
- The Scheme standard is less than 100 pages long.
- The Common Lisp standard is over 1,000 pages long.
- However, Common Lisp is used in many books and the standard can be used as more of a reference.
- Common Lisp is commonly considered to be "ugly" compared to a "beautiful" Lisp, like Scheme.
- Scheme is ultimately thought (mainly) as a pedagogical and research language, and the classical SICP (Structure and Interpretation of Computer Programs) uses Scheme to convey ideas about programming.
- Scheme is also notable for including uncommon but useful features, such as continuations and hygienic macros.
- It is important to note that every Lisp is capable of implementing any special features of any other Lisp.
- One important difference is highlighted next section; it is the distinction between a Lisp-1, such as Scheme, and a Lisp-2, such as Common Lisp and Emacs Lisp.
- What is a Lisp-1 and a Lisp-2?
- ================================
- These terms are usually derided as being confusing.
- A Lisp-1 is simply a Lisp where symbols use a single data slot for functions and variables.
- A Lisp-2 is a Lisp where a symbol has a value slot and a function slot.
- Here's an example:
- Lisp-1:
- (+ 1 2)
- The + symbol holds the addition function and that is what is used, since + is at the head of the list.
- Lisp-2:
- (let ((+ 1))
- (+ + 2))
- This let form binds the value slot of the + symbol to 1.
- The function slot of + is checked since + is at the head of the list and it finds the addition function.
- When + is found as an argument to the addition function, it's value slot is checked instead, which finds 1.
- This is the subject of a surprising amount of debate and your first Lisp will probably influence your preferences on this.
- Which Common Lisp implementation should I choose?
- ================================
- Common Lisp implementations tend to be similar in many respects.
- CLISP is an implementation praised for its portability and convenient interface.
- SBCL is an implementation that can compile to machine code; it is the fastest implementation and offers many features to get more performance and access to the lower levels of your computer.
- ECL is an implementation that compiles to C; it has many facilities for interoperability with C.
- ABCL is an implementation that runs on the JVM.
- Unlike Scheme, the Common Lisp standard has not changed in over 20 years.
- Which Scheme implementation should I choose?
- ================================
- There are quite a few Scheme implementations for a variety of purposes, but the top 3 are Racket, previously called PLT Scheme, Guile, and Chicken.
- As said above, Scheme implementations vary wildly in their nonstandard features, so you should pick one and stick with it.
- Racket is the most featureful of the bunch, albeit kind of slow.
- Racket supports many libraries and has a large community producing more.
- It has a module system in which modules can be considered individual Lisp dialects of their own.
- Guile is GNU's Ubiquitous Intelligent Extension Language.
- Guile's main purpose is to provide a library to interface Scheme and C code and make programs in C extensible with Scheme.
- This idea was drawn by the success of Emacs Lisp as an extension language.
- Chicken Scheme compiles Scheme code to C.
- This is not the same thing as what Guile does, since Guile actually interfaces both languages through a library.
- Chicken has a library facility by which bindings can be made to many libraries.
- Indeed, the "eggs", as they call them, are available for anyone to use and make it easy to do so.
- Other implementations worth mentioning include the Ikarus, which is almost r5rs compliant optimizing compiler, Scheme9 from empty space, which is notable for its thoroughly commented source code, and MIT Scheme, which is mostly of historical interest.
- What is this RNRS I hear about?
- ================================
- The Scheme standard is continually being improved in periodic releases named the "Revised^n Reports of Scheme", or RNRS.
- Currently, the latest report is R7RS.
- Due to differing ideas of what Scheme should be, R7RS has been split into R7RS-small and R7RS-big.
- R7RS-small aims to keep a minimal language.
- R7RS-big aims to standardize a larger amount of features, many of which are in Common Lisp, in order to improve program portability.
- Currently, most Scheme implementations implement R5RS or R6RS.
- As an example, MIT Scheme is R5RS while Guile is R5RS-complete and moving towards R6RS.
Pastebin PRO Accounts EASTER SPECIAL! For a limited time only get 40% discount on a LIFETIME PRO account! Offer Ends Soon!
RAW Paste Data


