SlideShare a Scribd company logo
1 of 27
Download to read offline
(GENTLE) INTRODUCTION TO LISP
Functional Programming Meetup
Bordeaux – Node
2016-03-30
Damien Garaud / @jazzydag
WHO AM I?
Damien Garaud
Scientist Programmer
Trainer & learning-addict
@jazzydag
https://github.com/garaud
A LITTLE STORY
Dimitri Fontaine aka @tapoueh
a PostgreSQL expert and Lisper-friendly
loads data into PostgreSQL fastpgloader
"I switched from Python to Common Lisp
because I wanted to use a modern
language" - @tapoueh
7th European Lisp Symposium
More than 20x faster than the previous Python version [1]
LISP?
( )
TINY DEMO
It's gonna be legen... wait for it
M‐x irony‐mode
HISTORY
1958 John McCarthy MIT
LISP: LISt Processing
Not "Lots of Irritating and Silly Parentheses"
1970: Lisp Machines
Artificial Intelligence
1980: need for standardization (Common
Lisp)
1994: ANSI Common Lisp
WHICH LISP?
Common Lisp
Scheme (1970)
Emacs Lisp (1976)
Racket (1996)
Arc (2001 Paul Graham)
Clojure (2007 JVM)
LFE as Lisp Flavored Erlang (2008
BEAM)
Hylang (2013 Lisp & Python)
LANGUAGES FEATURES
Dynamic Typing
Functional & Imperative
High-order Functions
Object-oriented
Prefix (polish) Notation
Macros
Garbage Collector
Source as a data
structure
... of course, it's just a list
S-EXPRESSION
List () or an atom
Each element is separated by a
whitespace
An element can be:
a list
an atom
ATOMS
Basic Type
string
integer
float
nil
A symbol
variable
name
function
name
EXAMPLES
(1 "two" ­5 "jazz" 4.2) 
(hello­world "John") 
(fibo 12) 
(/ (+ a b) (* c d)) 
(foo (bar "baz") "quz") 
FUNCTION DEFINITION
defun keyword
(defun hello (name) 
  "print hello" 
  (format t "Hello ~a!~%" name)) 
(hello "lambda meetup") 
This is a S-expression
with two nested S-exprs, 4 symbols, two strings and one
boolean
EVALUATION: HOW DOES IT WORK
Just read the S-expression
Valid S-expression
Valid Lisp expression
Suppose the first element is a function or an
operator
Left to the right
Evaluate all but first, then apply the first
EXAMPLES
(+ (* 2 15) (* 6 2)) 
42
(hello "you")
"Hello you!"
(let ((name "lambda meetup")) 
  (hello name)) 
"Hello lambda meetup!"
(mapcar 'evenp (list 0 1 2 3 4)) 
(T nil T nil T)
REPL
Read
Eval
Print
Loop
RETURNED VALUE
The last S-expression
(if (zerop 0) 
  (+ 5 3) 
  (* 2 2)) 
Which value?
8
"IF" AND THE STANDARD
EVALUATION RULE
(if (zerop 0) 
  (+ 1 3) 
  (* 3 2)) 
Can you see the problem?
Special operators
Not really evaluated as
usual
NOT ALWAYS EVALUATION
You saw the if. What's else?
(+ 2 5) 
(let ((a 2) 
      (b 21)) 
  (* a b)) 
Variables evaluation: it's OK
What about the high-order functions
You want to pass a name of a
function
Not evaluate me please
HIGHER-ORDER FUNCTIONS
(defun algo (pred struct) 
  "docstring" 
  (impl)) 
(algo pred (list "coltrane" "davis" "hancock")) 
pred shouldn't be evaluated as
is
variable name error
Special "quote"
SPECIAL QUOTE
There is a function for that:
(quote (a b c d)) 
(defun my­pred (lhs rhs) 
  "my predicate func" 
  (> lhs rhs)) 
(algo (quote my­pred) struct) 
special ' syntax
(algo 'my­pred struct) 
TAKE A BREATH
What did we see:
Evaluation rules
S-expressions, S-expressions everywhere!
Source code as a data structure
(defun foo (arg) (body)) is a S-
expression
Thus arg can be a simple list or...
... a function definition
Don't worry... the end is coming
MACROS
It's about code generation
... but not really like C macros
The programmable programming language
MACROS BY EXAMPLE
Make a list as Python does:
seq = [] 
for elt in range(10): 
    if elt % 2 == 0: 
        seq.append(elt) 
# use comprehension list
seq = [x for x in range(10) if x % 2 == 0] 
Comprehension Lists
And you want to implement this feature in Common Lisp
MACROS BY EXAMPLE
(lcomp x for x in (range 10) if (= (mod x 2) 0)) 
You can define your own language extension
(defmacro lcomp (expression for var in list cond cond­test) 
  "doc here" 
  (body)) 
Lisp code generation writing Lisp code
FURTHER
CLOS: Common Lisp Object
System
Quicklisp: a package manager
Compilation: SBCL or Clozure CL
Make a Lisp
REFERENCES
SICP
The Little Schemer
Practical Common
Lisp
Common Lisp Recipes
THANKS
https://xkcd.com/224/

More Related Content

What's hot

Real World Haskell: Lecture 7
Real World Haskell: Lecture 7Real World Haskell: Lecture 7
Real World Haskell: Lecture 7
Bryan O'Sullivan
 
Real World Haskell: Lecture 1
Real World Haskell: Lecture 1Real World Haskell: Lecture 1
Real World Haskell: Lecture 1
Bryan O'Sullivan
 

What's hot (19)

Advance LISP (Artificial Intelligence)
Advance LISP (Artificial Intelligence) Advance LISP (Artificial Intelligence)
Advance LISP (Artificial Intelligence)
 
Lisp
LispLisp
Lisp
 
(Ai lisp)
(Ai lisp)(Ai lisp)
(Ai lisp)
 
Introduction To Lisp
Introduction To LispIntroduction To Lisp
Introduction To Lisp
 
Prolog & lisp
Prolog & lispProlog & lisp
Prolog & lisp
 
LISP: Introduction to lisp
LISP: Introduction to lispLISP: Introduction to lisp
LISP: Introduction to lisp
 
LISP: Data types in lisp
LISP: Data types in lispLISP: Data types in lisp
LISP: Data types in lisp
 
LISP: Input And Output
LISP: Input And OutputLISP: Input And Output
LISP: Input And Output
 
Basic lisp
Basic lispBasic lisp
Basic lisp
 
Introduction to Python Part-1
Introduction to Python Part-1Introduction to Python Part-1
Introduction to Python Part-1
 
BayFP: Concurrent and Multicore Haskell
BayFP: Concurrent and Multicore HaskellBayFP: Concurrent and Multicore Haskell
BayFP: Concurrent and Multicore Haskell
 
Real World Haskell: Lecture 7
Real World Haskell: Lecture 7Real World Haskell: Lecture 7
Real World Haskell: Lecture 7
 
Functional Programming Concepts for Imperative Programmers
Functional Programming Concepts for Imperative ProgrammersFunctional Programming Concepts for Imperative Programmers
Functional Programming Concepts for Imperative Programmers
 
Introduction to functional programming (In Arabic)
Introduction to functional programming (In Arabic)Introduction to functional programming (In Arabic)
Introduction to functional programming (In Arabic)
 
Scheme language
Scheme languageScheme language
Scheme language
 
Scheme Programming Language
Scheme Programming LanguageScheme Programming Language
Scheme Programming Language
 
Real World Haskell: Lecture 1
Real World Haskell: Lecture 1Real World Haskell: Lecture 1
Real World Haskell: Lecture 1
 
AI Programming language (LISP)
AI Programming language (LISP)AI Programming language (LISP)
AI Programming language (LISP)
 
Lisp and scheme i
Lisp and scheme iLisp and scheme i
Lisp and scheme i
 

Viewers also liked (13)

LISP Programming Language (Artificial Intelligence)
LISP Programming Language (Artificial Intelligence)LISP Programming Language (Artificial Intelligence)
LISP Programming Language (Artificial Intelligence)
 
Redesigning Common Lisp
Redesigning Common LispRedesigning Common Lisp
Redesigning Common Lisp
 
Expert systems
Expert systemsExpert systems
Expert systems
 
Application of expert system
Application of expert systemApplication of expert system
Application of expert system
 
Introduction and architecture of expert system
Introduction  and architecture of expert systemIntroduction  and architecture of expert system
Introduction and architecture of expert system
 
LISP:Program structure in lisp
LISP:Program structure in lispLISP:Program structure in lisp
LISP:Program structure in lisp
 
LISP:Control Structures In Lisp
LISP:Control Structures In LispLISP:Control Structures In Lisp
LISP:Control Structures In Lisp
 
Lecture5 Expert Systems And Artificial Intelligence
Lecture5 Expert Systems And Artificial IntelligenceLecture5 Expert Systems And Artificial Intelligence
Lecture5 Expert Systems And Artificial Intelligence
 
Expert Systems
Expert SystemsExpert Systems
Expert Systems
 
Expert Systems
Expert SystemsExpert Systems
Expert Systems
 
Expert Systems
Expert SystemsExpert Systems
Expert Systems
 
6.expert systems
6.expert systems6.expert systems
6.expert systems
 
Topic 8 expert system
Topic 8 expert systemTopic 8 expert system
Topic 8 expert system
 

Similar to Gentle Introduction To Lisp

Rcpp: Seemless R and C++
Rcpp: Seemless R and C++Rcpp: Seemless R and C++
Rcpp: Seemless R and C++
Romain Francois
 
Haskell retrospective
Haskell retrospectiveHaskell retrospective
Haskell retrospective
chenge2k
 
Rcpp: Seemless R and C++
Rcpp: Seemless R and C++Rcpp: Seemless R and C++
Rcpp: Seemless R and C++
Romain Francois
 

Similar to Gentle Introduction To Lisp (20)

LISP: Introduction To Lisp
LISP: Introduction To LispLISP: Introduction To Lisp
LISP: Introduction To Lisp
 
AutoDesk
AutoDeskAutoDesk
AutoDesk
 
Elm kyivfprog 2015
Elm kyivfprog 2015Elm kyivfprog 2015
Elm kyivfprog 2015
 
Slides
SlidesSlides
Slides
 
Scala @ TomTom
Scala @ TomTomScala @ TomTom
Scala @ TomTom
 
Rcpp: Seemless R and C++
Rcpp: Seemless R and C++Rcpp: Seemless R and C++
Rcpp: Seemless R and C++
 
[Codemotion 2015] patrones de diseño con java8
[Codemotion 2015] patrones de diseño con java8[Codemotion 2015] patrones de diseño con java8
[Codemotion 2015] patrones de diseño con java8
 
Introduction to Matlab
Introduction to MatlabIntroduction to Matlab
Introduction to Matlab
 
Demystifying functional programming with Scala
Demystifying functional programming with ScalaDemystifying functional programming with Scala
Demystifying functional programming with Scala
 
Lisp Primer Key
Lisp Primer KeyLisp Primer Key
Lisp Primer Key
 
Haskell retrospective
Haskell retrospectiveHaskell retrospective
Haskell retrospective
 
Rcpp: Seemless R and C++
Rcpp: Seemless R and C++Rcpp: Seemless R and C++
Rcpp: Seemless R and C++
 
Scala Back to Basics: Type Classes
Scala Back to Basics: Type ClassesScala Back to Basics: Type Classes
Scala Back to Basics: Type Classes
 
Labreportofai
LabreportofaiLabreportofai
Labreportofai
 
Coding convention
Coding conventionCoding convention
Coding convention
 
LR(1) and SLR(1) parsing
LR(1) and SLR(1) parsingLR(1) and SLR(1) parsing
LR(1) and SLR(1) parsing
 
Advance python programming
Advance python programming Advance python programming
Advance python programming
 
ScalaDays 2013 Keynote Speech by Martin Odersky
ScalaDays 2013 Keynote Speech by Martin OderskyScalaDays 2013 Keynote Speech by Martin Odersky
ScalaDays 2013 Keynote Speech by Martin Odersky
 
Let's LISP like it's 1959
Let's LISP like it's 1959Let's LISP like it's 1959
Let's LISP like it's 1959
 
There's a Prolog in your Scala!
There's a Prolog in your Scala!There's a Prolog in your Scala!
There's a Prolog in your Scala!
 

Recently uploaded

If this Giant Must Walk: A Manifesto for a New Nigeria
If this Giant Must Walk: A Manifesto for a New NigeriaIf this Giant Must Walk: A Manifesto for a New Nigeria
If this Giant Must Walk: A Manifesto for a New Nigeria
Kayode Fayemi
 
No Advance 8868886958 Chandigarh Call Girls , Indian Call Girls For Full Nigh...
No Advance 8868886958 Chandigarh Call Girls , Indian Call Girls For Full Nigh...No Advance 8868886958 Chandigarh Call Girls , Indian Call Girls For Full Nigh...
No Advance 8868886958 Chandigarh Call Girls , Indian Call Girls For Full Nigh...
Sheetaleventcompany
 
Chiulli_Aurora_Oman_Raffaele_Beowulf.pptx
Chiulli_Aurora_Oman_Raffaele_Beowulf.pptxChiulli_Aurora_Oman_Raffaele_Beowulf.pptx
Chiulli_Aurora_Oman_Raffaele_Beowulf.pptx
raffaeleoman
 
Uncommon Grace The Autobiography of Isaac Folorunso
Uncommon Grace The Autobiography of Isaac FolorunsoUncommon Grace The Autobiography of Isaac Folorunso
Uncommon Grace The Autobiography of Isaac Folorunso
Kayode Fayemi
 

Recently uploaded (20)

My Presentation "In Your Hands" by Halle Bailey
My Presentation "In Your Hands" by Halle BaileyMy Presentation "In Your Hands" by Halle Bailey
My Presentation "In Your Hands" by Halle Bailey
 
If this Giant Must Walk: A Manifesto for a New Nigeria
If this Giant Must Walk: A Manifesto for a New NigeriaIf this Giant Must Walk: A Manifesto for a New Nigeria
If this Giant Must Walk: A Manifesto for a New Nigeria
 
Introduction to Prompt Engineering (Focusing on ChatGPT)
Introduction to Prompt Engineering (Focusing on ChatGPT)Introduction to Prompt Engineering (Focusing on ChatGPT)
Introduction to Prompt Engineering (Focusing on ChatGPT)
 
Mohammad_Alnahdi_Oral_Presentation_Assignment.pptx
Mohammad_Alnahdi_Oral_Presentation_Assignment.pptxMohammad_Alnahdi_Oral_Presentation_Assignment.pptx
Mohammad_Alnahdi_Oral_Presentation_Assignment.pptx
 
Air breathing and respiratory adaptations in diver animals
Air breathing and respiratory adaptations in diver animalsAir breathing and respiratory adaptations in diver animals
Air breathing and respiratory adaptations in diver animals
 
lONG QUESTION ANSWER PAKISTAN STUDIES10.
lONG QUESTION ANSWER PAKISTAN STUDIES10.lONG QUESTION ANSWER PAKISTAN STUDIES10.
lONG QUESTION ANSWER PAKISTAN STUDIES10.
 
ICT role in 21st century education and it's challenges.pdf
ICT role in 21st century education and it's challenges.pdfICT role in 21st century education and it's challenges.pdf
ICT role in 21st century education and it's challenges.pdf
 
Dreaming Marissa Sánchez Music Video Treatment
Dreaming Marissa Sánchez Music Video TreatmentDreaming Marissa Sánchez Music Video Treatment
Dreaming Marissa Sánchez Music Video Treatment
 
The workplace ecosystem of the future 24.4.2024 Fabritius_share ii.pdf
The workplace ecosystem of the future 24.4.2024 Fabritius_share ii.pdfThe workplace ecosystem of the future 24.4.2024 Fabritius_share ii.pdf
The workplace ecosystem of the future 24.4.2024 Fabritius_share ii.pdf
 
Re-membering the Bard: Revisiting The Compleat Wrks of Wllm Shkspr (Abridged)...
Re-membering the Bard: Revisiting The Compleat Wrks of Wllm Shkspr (Abridged)...Re-membering the Bard: Revisiting The Compleat Wrks of Wllm Shkspr (Abridged)...
Re-membering the Bard: Revisiting The Compleat Wrks of Wllm Shkspr (Abridged)...
 
No Advance 8868886958 Chandigarh Call Girls , Indian Call Girls For Full Nigh...
No Advance 8868886958 Chandigarh Call Girls , Indian Call Girls For Full Nigh...No Advance 8868886958 Chandigarh Call Girls , Indian Call Girls For Full Nigh...
No Advance 8868886958 Chandigarh Call Girls , Indian Call Girls For Full Nigh...
 
Thirunelveli call girls Tamil escorts 7877702510
Thirunelveli call girls Tamil escorts 7877702510Thirunelveli call girls Tamil escorts 7877702510
Thirunelveli call girls Tamil escorts 7877702510
 
AWS Data Engineer Associate (DEA-C01) Exam Dumps 2024.pdf
AWS Data Engineer Associate (DEA-C01) Exam Dumps 2024.pdfAWS Data Engineer Associate (DEA-C01) Exam Dumps 2024.pdf
AWS Data Engineer Associate (DEA-C01) Exam Dumps 2024.pdf
 
SaaStr Workshop Wednesday w/ Lucas Price, Yardstick
SaaStr Workshop Wednesday w/ Lucas Price, YardstickSaaStr Workshop Wednesday w/ Lucas Price, Yardstick
SaaStr Workshop Wednesday w/ Lucas Price, Yardstick
 
VVIP Call Girls Nalasopara : 9892124323, Call Girls in Nalasopara Services
VVIP Call Girls Nalasopara : 9892124323, Call Girls in Nalasopara ServicesVVIP Call Girls Nalasopara : 9892124323, Call Girls in Nalasopara Services
VVIP Call Girls Nalasopara : 9892124323, Call Girls in Nalasopara Services
 
BDSM⚡Call Girls in Sector 93 Noida Escorts >༒8448380779 Escort Service
BDSM⚡Call Girls in Sector 93 Noida Escorts >༒8448380779 Escort ServiceBDSM⚡Call Girls in Sector 93 Noida Escorts >༒8448380779 Escort Service
BDSM⚡Call Girls in Sector 93 Noida Escorts >༒8448380779 Escort Service
 
Chiulli_Aurora_Oman_Raffaele_Beowulf.pptx
Chiulli_Aurora_Oman_Raffaele_Beowulf.pptxChiulli_Aurora_Oman_Raffaele_Beowulf.pptx
Chiulli_Aurora_Oman_Raffaele_Beowulf.pptx
 
Uncommon Grace The Autobiography of Isaac Folorunso
Uncommon Grace The Autobiography of Isaac FolorunsoUncommon Grace The Autobiography of Isaac Folorunso
Uncommon Grace The Autobiography of Isaac Folorunso
 
Call Girl Number in Khar Mumbai📲 9892124323 💞 Full Night Enjoy
Call Girl Number in Khar Mumbai📲 9892124323 💞 Full Night EnjoyCall Girl Number in Khar Mumbai📲 9892124323 💞 Full Night Enjoy
Call Girl Number in Khar Mumbai📲 9892124323 💞 Full Night Enjoy
 
BDSM⚡Call Girls in Sector 97 Noida Escorts >༒8448380779 Escort Service
BDSM⚡Call Girls in Sector 97 Noida Escorts >༒8448380779 Escort ServiceBDSM⚡Call Girls in Sector 97 Noida Escorts >༒8448380779 Escort Service
BDSM⚡Call Girls in Sector 97 Noida Escorts >༒8448380779 Escort Service
 

Gentle Introduction To Lisp