26
LISP: Power and Elegance LISP: Power and Elegance in ONE in ONE

LISP: Power and Elegance in ONE. Overview n The History of Lips n Lisp, Mathematics and Elegance n The Power of Lisp n Lisp in Commercial Use

Embed Size (px)

Citation preview

Page 1: LISP: Power and Elegance in ONE. Overview n The History of Lips n Lisp, Mathematics and Elegance n The Power of Lisp n Lisp in Commercial Use

LISP: Power and Elegance in LISP: Power and Elegance in ONEONE

Page 2: LISP: Power and Elegance in ONE. Overview n The History of Lips n Lisp, Mathematics and Elegance n The Power of Lisp n Lisp in Commercial Use

Overview Overview

The History of LipsThe History of Lips Lisp, Mathematics and EleganceLisp, Mathematics and Elegance The Power of LispThe Power of Lisp Lisp in Commercial UseLisp in Commercial Use

Page 3: LISP: Power and Elegance in ONE. Overview n The History of Lips n Lisp, Mathematics and Elegance n The Power of Lisp n Lisp in Commercial Use

Some Interesting QuotationsSome Interesting Quotations

““Lisp is worth learning for the profound Lisp is worth learning for the profound enlightenment experience you will have when enlightenment experience you will have when you finally get it; that experience will make you a you finally get it; that experience will make you a better programmer for the rest of your days, better programmer for the rest of your days, even if you never actually use Lisp itself a lot”even if you never actually use Lisp itself a lot”

-Eric Raymond, “How to Become a Hacker”-Eric Raymond, “How to Become a Hacker”

Page 4: LISP: Power and Elegance in ONE. Overview n The History of Lips n Lisp, Mathematics and Elegance n The Power of Lisp n Lisp in Commercial Use

““I have heard more than one Lisp advocate state such I have heard more than one Lisp advocate state such subjective comments as, “Lisp is the most powerful subjective comments as, “Lisp is the most powerful and elegant programming language in the world” and and elegant programming language in the world” and expect such comments to be taken as objective truth. I expect such comments to be taken as objective truth. I have never heard a Java, C++, C, Perl, or Python have never heard a Java, C++, C, Perl, or Python advocate make the same claim about their own advocate make the same claim about their own language of choice”language of choice”

- A guy on Slashdot.com- A guy on Slashdot.com

““Lisp… made me aware that software could be close to Lisp… made me aware that software could be close to executable mathematics.”executable mathematics.”

-L. Peter Deutsch-L. Peter Deutsch

More QuotationsMore Quotations

Page 5: LISP: Power and Elegance in ONE. Overview n The History of Lips n Lisp, Mathematics and Elegance n The Power of Lisp n Lisp in Commercial Use

History of LispHistory of Lisp

In 1960 John McCarthy published a paper where he In 1960 John McCarthy published a paper where he outlined that given some simple operations and outlined that given some simple operations and notation for functions, one can build a whole notation for functions, one can build a whole programming language. programming language. – Primitive operation were either an atom or a list of atoms. Primitive operation were either an atom or a list of atoms.

So, So, foo, (), (foo) , (foo bar) , foo, (), (foo) , (foo bar) , were all considered expressions.were all considered expressions.– Functions were denoted as Functions were denoted as (lambda (p..) e) a..).(lambda (p..) e) a..).

This was more of a theoretical exercise, in an This was more of a theoretical exercise, in an effort to define a more convenient alternative to effort to define a more convenient alternative to the Turning Machine. the Turning Machine.

Page 6: LISP: Power and Elegance in ONE. Overview n The History of Lips n Lisp, Mathematics and Elegance n The Power of Lisp n Lisp in Commercial Use

Lisp as TheoryLisp as Theory

““Another way to show that Lisp was neater than Another way to show that Lisp was neater than Turning machines was to write a universal Lisp function Turning machines was to write a universal Lisp function and show that it is briefer and more comprehensible and show that it is briefer and more comprehensible than the description of a universal Turning Machine. than the description of a universal Turning Machine. This was the Lisp function This was the Lisp function evaleval…, which computes the …, which computes the value of a Lisp expression… Writing value of a Lisp expression… Writing evaleval requires requires inventing a notation representing Lisp functions as Lisp inventing a notation representing Lisp functions as Lisp data, and such a notation was devised for the purposes data, and such a notation was devised for the purposes of the paper with no thought that I would used to of the paper with no thought that I would used to express Lisp programs in practice.”express Lisp programs in practice.”

-John McCarthy-John McCarthy

Page 7: LISP: Power and Elegance in ONE. Overview n The History of Lips n Lisp, Mathematics and Elegance n The Power of Lisp n Lisp in Commercial Use

Theory turns to Practice: the Theory turns to Practice: the birth of Lisp the languagebirth of Lisp the language

Later that year one of McCarthy’s graduate students, Later that year one of McCarthy’s graduate students, Steve Russell, figured out a way to translate the eval Steve Russell, figured out a way to translate the eval function into machine language. function into machine language.

““Steve Russell said, look, why don’t I program this Steve Russell said, look, why don’t I program this eval… and I said to him, ho, ho, you’re confusing eval… and I said to him, ho, ho, you’re confusing theory with practice, this eval is intended for reading, theory with practice, this eval is intended for reading, not for computing, But he went ahead and did it. That not for computing, But he went ahead and did it. That is, he compiled the eval in my paper into [IBM] 704 is, he compiled the eval in my paper into [IBM] 704 machine code, fixing bugs, and then advertised this as machine code, fixing bugs, and then advertised this as a Lisp interpreter, which it certainly was . So at that a Lisp interpreter, which it certainly was . So at that point Lisp had essentially the form that it has today….”point Lisp had essentially the form that it has today….”

-John McCarthy -John McCarthy

Page 8: LISP: Power and Elegance in ONE. Overview n The History of Lips n Lisp, Mathematics and Elegance n The Power of Lisp n Lisp in Commercial Use

What made Lisp DifferentWhat made Lisp Different Conditionals: such as if-then-else construct.Conditionals: such as if-then-else construct. Function types: where functions are just like Function types: where functions are just like

integers and stringsintegers and strings Recursion: first language to support it.Recursion: first language to support it. Dynamic typing: all variable are pointers. Dynamic typing: all variable are pointers. Garbage-Collection.Garbage-Collection. Programs composed of expressions.Programs composed of expressions. A symbol type.A symbol type. A notations for code using trees of symbols and A notations for code using trees of symbols and

constants.constants. The whole language is there all the time.The whole language is there all the time.

Page 9: LISP: Power and Elegance in ONE. Overview n The History of Lips n Lisp, Mathematics and Elegance n The Power of Lisp n Lisp in Commercial Use

Lisp, Mathematics and Lisp, Mathematics and EleganceElegance

““Lisp is the only computer Lisp is the only computer programming language that is programming language that is mathematically respectable, mathematically respectable, because its the only one that I can because its the only one that I can prove theorems about”prove theorems about”

-G.J. Chaitin-G.J. Chaitin

Page 10: LISP: Power and Elegance in ONE. Overview n The History of Lips n Lisp, Mathematics and Elegance n The Power of Lisp n Lisp in Commercial Use

Lisp and MathematicsLisp and Mathematics

Lisp is Set Theory for computable Lisp is Set Theory for computable mathematics rather than for abstract mathematics rather than for abstract mathematics.mathematics.– A set is made up of objects.A set is made up of objects.

In mathematics a set is represented like so In mathematics a set is represented like so {A, B, C,}. {A, B, C,}.

In lisp, this simple set would look like (A B In lisp, this simple set would look like (A B C).C).

A more complex set- (A (B C) 123)A more complex set- (A (B C) 123)

Page 11: LISP: Power and Elegance in ONE. Overview n The History of Lips n Lisp, Mathematics and Elegance n The Power of Lisp n Lisp in Commercial Use

More on Lisp and More on Lisp and MathematicsMathematics

Why Lips is mathematical:Why Lips is mathematical:– time is not a constrainttime is not a constraint– a program is essentially an a program is essentially an

expressionexpression– expressions are evaluated returning a expressions are evaluated returning a

valuevalue– the programmer is not forced to the programmer is not forced to

assign value to variablesassign value to variables

Page 12: LISP: Power and Elegance in ONE. Overview n The History of Lips n Lisp, Mathematics and Elegance n The Power of Lisp n Lisp in Commercial Use

Elegant Lisp ProgramsElegant Lisp Programs

Lisp can be used to prove interesting Lisp can be used to prove interesting mathematical problems dealing with formal mathematical problems dealing with formal axiomatic systems.axiomatic systems.– Gödel’s Incompleteness Theorem: which states that Gödel’s Incompleteness Theorem: which states that

within any formal system, there are truths which may within any formal system, there are truths which may be expressed though they are not provable within the be expressed though they are not provable within the system.system.

Gödel's original proof of the incompleteness theorem is Gödel's original proof of the incompleteness theorem is based on the paradox of the liar: “This statement is based on the paradox of the liar: “This statement is

false.''false.'' e.g., try to prove that a Lisp expression is elegant if no e.g., try to prove that a Lisp expression is elegant if no

smaller expression gives the same value that it does. smaller expression gives the same value that it does. (YOU CAN’T!!!!)(YOU CAN’T!!!!)

Page 13: LISP: Power and Elegance in ONE. Overview n The History of Lips n Lisp, Mathematics and Elegance n The Power of Lisp n Lisp in Commercial Use

The Power of LispThe Power of Lisp

The Power of SimplicityThe Power of Simplicity Rapid PrototypingRapid Prototyping Unique FunctionalityUnique Functionality High-Performance: Lisp vs. Java, C, C++High-Performance: Lisp vs. Java, C, C++

Page 14: LISP: Power and Elegance in ONE. Overview n The History of Lips n Lisp, Mathematics and Elegance n The Power of Lisp n Lisp in Commercial Use

The Power of SimplicityThe Power of Simplicity

Lisp is syntactically clean and Lisp is syntactically clean and simplesimple– symbolically designedsymbolically designed– faster learning-curvefaster learning-curve– more time spend on codingmore time spend on coding

Page 15: LISP: Power and Elegance in ONE. Overview n The History of Lips n Lisp, Mathematics and Elegance n The Power of Lisp n Lisp in Commercial Use

Rapid PrototypingRapid Prototyping

Lisp is comprehensiveLisp is comprehensive It supports modular design.It supports modular design.

– Using complex constants in codeUsing complex constants in code– MacrosMacros– Optional Declaration Optional Declaration – Higher Order FunctionHigher Order Function

Page 16: LISP: Power and Elegance in ONE. Overview n The History of Lips n Lisp, Mathematics and Elegance n The Power of Lisp n Lisp in Commercial Use

Lisp is ComprehensiveLisp is Comprehensive

Lisp includes an extraordinary powerful set of Lisp includes an extraordinary powerful set of pre-defined tools:pre-defined tools:– NumbersNumbers– CharactersCharacters– ArraysArrays– ConesCones– Symbols, Packages, and ReadtablesSymbols, Packages, and Readtables– FunctionsFunctions– Hash TablesHash Tables– StreamsStreams– Classes, Methods, and Generic FunctionsClasses, Methods, and Generic Functions– PathnamesPathnames– Conditions and RestartsConditions and Restarts

Page 17: LISP: Power and Elegance in ONE. Overview n The History of Lips n Lisp, Mathematics and Elegance n The Power of Lisp n Lisp in Commercial Use

Lisp Supports Modular DesignLisp Supports Modular Design

Using complex literals in code:Using complex literals in code:– in production code, you might want to make a global variable to in production code, you might want to make a global variable to

keep track of a quantity shared by several modules, keep track of a quantity shared by several modules, >(defvar *club-members* ‘()) >(defvar *club-members* ‘())

>(defun add-club-member >(defun add-club-member (who) (pushnew who *club-member*)) (who) (pushnew who *club-member*)) >(defun is-club->(defun is-club-member? (who) (member who *club-member*))member? (who) (member who *club-member*))

– in prototyping doing minimal amount of work is needed to in prototyping doing minimal amount of work is needed to make the program run,make the program run, >(defun is-club-member (who) >(defun is-club-member (who) (member who ‘(joe sally fred))(member who ‘(joe sally fred))

Page 18: LISP: Power and Elegance in ONE. Overview n The History of Lips n Lisp, Mathematics and Elegance n The Power of Lisp n Lisp in Commercial Use

ContinuationContinuation

MMacrosacros– Macros is what makes Lisp superior compared all Macros is what makes Lisp superior compared all

other languages.other languages.– Macros introduce a unique functionality that allows Macros introduce a unique functionality that allows

programs to write other programs.programs to write other programs.– It’s a real boon to rapid prototyping. It’s a real boon to rapid prototyping.

Instead of writing Instead of writing >(setf x nil)>(setf x nil)

We can write a macro We can write a macro >(defmacro nil! (x) (list ‘setf x nil))>(defmacro nil! (x) (list ‘setf x nil))

>(nil! x)>(nil! x) NILNIL

Page 19: LISP: Power and Elegance in ONE. Overview n The History of Lips n Lisp, Mathematics and Elegance n The Power of Lisp n Lisp in Commercial Use

ContinuationContinuation

Higher Order FunctionsHigher Order Functions– Lisp posses the ability to pass functions as Lisp posses the ability to pass functions as

arguments to other functions.arguments to other functions.

Optional DeclarationsOptional Declarations– Lisp does not enforce declarations, so writing a Lisp does not enforce declarations, so writing a

function such as,function such as, >(defun twice (x) (* 2 x))>(defun twice (x) (* 2 x))

will suffice for prototyping.will suffice for prototyping.

Page 20: LISP: Power and Elegance in ONE. Overview n The History of Lips n Lisp, Mathematics and Elegance n The Power of Lisp n Lisp in Commercial Use

Lisp vs. Java, C++Lisp vs. Java, C++

In a recent study Prechelt (1999) In a recent study Prechelt (1999) compared the relative compared the relative performance of Java and C++ in performance of Java and C++ in execution time and memory execution time and memory usage.usage.

Page 21: LISP: Power and Elegance in ONE. Overview n The History of Lips n Lisp, Mathematics and Elegance n The Power of Lisp n Lisp in Commercial Use

Lisp vs. Java, C++Lisp vs. Java, C++

Lisp’s performance is comparable to or better Lisp’s performance is comparable to or better than C++ in execution speed.than C++ in execution speed.

Significantly lower variability, which translates Significantly lower variability, which translates into reduced project risk.into reduced project risk.

Development time was found to be Development time was found to be significantly lower and less variable than either significantly lower and less variable than either C++ or Java.C++ or Java.

Memory consumption is comparable to Java.Memory consumption is comparable to Java.

Page 22: LISP: Power and Elegance in ONE. Overview n The History of Lips n Lisp, Mathematics and Elegance n The Power of Lisp n Lisp in Commercial Use

Some DataSome Data

Development time for Lisp ranged from low of Development time for Lisp ranged from low of 2 hours to high of 8.5 hours, compared to a 2 hours to high of 8.5 hours, compared to a range of 3 to 25 hours for C and 4 to 63 hours range of 3 to 25 hours for C and 4 to 63 hours for Java. for Java.

Lisp programs were significantly shorter than Lisp programs were significantly shorter than C, C++, and Java programsC, C++, and Java programs– Lisp programs ranged from 51 to 182 lines of code, Lisp programs ranged from 51 to 182 lines of code,

median was 134 lines.median was 134 lines.– C, C++, and Java programs ranged from 107 to 614 C, C++, and Java programs ranged from 107 to 614

lines of code, with the median of 244 lines. lines of code, with the median of 244 lines.

Page 23: LISP: Power and Elegance in ONE. Overview n The History of Lips n Lisp, Mathematics and Elegance n The Power of Lisp n Lisp in Commercial Use
Page 24: LISP: Power and Elegance in ONE. Overview n The History of Lips n Lisp, Mathematics and Elegance n The Power of Lisp n Lisp in Commercial Use

The Power is in the CodeThe Power is in the Code

Consider the following problem, where we want to write a Consider the following problem, where we want to write a function that generates accumulators,i.e, a function that function that generates accumulators,i.e, a function that takes a number n, and returns a function that takes takes a number n, and returns a function that takes another number i and returns n incremented by i.another number i and returns n incremented by i.– In Common Lisp this would be:In Common Lisp this would be:

>(defun foo (n) #’ (lambda (i) (incf n i)))>(defun foo (n) #’ (lambda (i) (incf n i)))

– In Java we get:In Java we get: public interface Inttoint { public int call(int i);}public interface Inttoint { public int call(int i);} public static Inttoint foo(final int n) {public static Inttoint foo(final int n) {

return new Inttoint() {return new Inttoint() { int s = n;int s = n; public int call(int i) {s = s+i; return s; }};} public int call(int i) {s = s+i; return s; }};}

Page 25: LISP: Power and Elegance in ONE. Overview n The History of Lips n Lisp, Mathematics and Elegance n The Power of Lisp n Lisp in Commercial Use

Lisp in Commercial UseLisp in Commercial Use

Yahoo Store, used to be called Viaweb.Yahoo Store, used to be called Viaweb.– Founded by Paul GrahamFounded by Paul Graham– Lisp was the primary development language for the server-Lisp was the primary development language for the server-

based applications.based applications.– 20-25% of the source code for Viaweb was made up macros.20-25% of the source code for Viaweb was made up macros.

Orbitz.comOrbitz.com– came in rather late into the online travel market, with came in rather late into the online travel market, with

competitors such as Travelocity and Expedia already competitors such as Travelocity and Expedia already dominating the industry.dominating the industry.

– Completely rewrote the entire flight search engine package in Completely rewrote the entire flight search engine package in Lisp, giving greater functionality and searching capabilities Lisp, giving greater functionality and searching capabilities than with the standard legacy systems used by its than with the standard legacy systems used by its competitors. competitors.

– Using Lisp, made Orbitz almost completely self-sufficient, with Using Lisp, made Orbitz almost completely self-sufficient, with minimal dependence on third-party vendors.minimal dependence on third-party vendors.

Page 26: LISP: Power and Elegance in ONE. Overview n The History of Lips n Lisp, Mathematics and Elegance n The Power of Lisp n Lisp in Commercial Use

QUESTIONS?QUESTIONS?