Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Introduction to Lisp (zceu)
Search
Igor Wiedler
November 20, 2013
Programming
350
4
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Introduction to Lisp (zceu)
Igor Wiedler
November 20, 2013
More Decks by Igor Wiedler
See All by Igor Wiedler
Redis Bedtime Stories
igorw
1
360
Wide Event Analytics (LISA19)
igorw
4
940
a day in the life of a request
igorw
0
170
production: an owner's manual
igorw
0
190
The Power of 2
igorw
0
340
LISP 1.5 Programmer's Manual: A Dramatic Reading
igorw
0
480
The Moral Character of Software
igorw
1
310
interdisciplinary computing (domcode)
igorw
0
320
miniKanren (clojure berlin)
igorw
1
330
Other Decks in Programming
See All in Programming
OSもどきOS
arkw
0
600
AIで効率化できた業務・日常
ochtum
0
150
Contextとはなにか
chiroruxx
1
380
Mujeres en SEO Summit 2026 - Greatest Disaster Hits en Web Performance
guaca
0
210
ECSアプリログをFireLensでコスト削減しようとしたけど諦めた話 in Fargate×Node.js
akihisaikeda
2
4.2k
AIキャラアプリkaiwaの低遅延音声通話基盤をどう作ったか - AWS Gravitonで支える低遅延・低コストAI Agent基盤
mogamit
0
130
Javaの型とAI時代に型が大事な理由 / java types and type in AI era
kishida
2
150
その問い、本当に正しいですか?AI時代のエンジニアに必要な哲学と認知科学 / ai-philosophy-cognitive-science
minodriven
14
6.5k
A2UI という光を覗いてみる
satohjohn
1
160
PHPで使える日時の表現と、その知り方 #frontend_phpcon_do
o0h
PRO
0
270
TypeScript+Orvalで実現する型安全かつ堅牢でスケーラブルなマルチチャネル通知基盤 / TSKaigi Night talks ~after conference~
d0riven
0
370
dRuby over BLE
makicamel
2
400
Featured
See All Featured
The State of eCommerce SEO: How to Win in Today's Products SERPs - #SEOweek
aleyda
2
11k
[SF Ruby Conf 2025] Rails X
palkan
2
1.1k
The AI Search Optimization Roadmap by Aleyda Solis
aleyda
1
5.9k
Abbi's Birthday
coloredviolet
3
8.3k
Winning Ecommerce Organic Search in an AI Era - #searchnstuff2025
aleyda
1
2.1k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
9
1.4k
Marketing to machines
jonoalderson
1
5.5k
Embracing the Ebb and Flow
colly
88
5.1k
エンジニアに許された特別な時間の終わり
watany
107
250k
How to build a perfect <img>
jonoalderson
1
5.7k
The innovator’s Mindset - Leading Through an Era of Exponential Change - McGill University 2025
jdejongh
PRO
1
210
The Language of Interfaces
destraynor
162
27k
Transcript
Introduction to
@igorwesome
(
John McCarthy
None
f o r g e t everything y o
u k n o w
(+ 1 2)
(+ 1 2) l i s t
(+ 1 2) symbol
(+ 1 2) number
(+ 1 2) number
(+ 1 2) a p p l i c a
t i o n
(+ 1 2) function
(+ 1 2) arguments
3
None
cons
car
first
cdr
rest
(a . b)
a b
(a . nil)
a
(a . (b . (c . nil)))
a b c
(a b c)
[:a :b :c]
(first [:a :b :c]) !
(first [:a :b :c]) ! :a
a b c
(rest [:a :b :c]) !
(rest [:a :b :c]) ! [:b :c]
a b c
(cons :a [:b :c]) !
(cons :a [:b :c]) ! [:a :b :c]
a b c
(+ 2 3 5 7 11 13)
(/ (+ (- b) (math.sqrt (- (math.expt b 2) (*
4 a c)))) (* 2 a)) ! (/ (- (- b) (math.sqrt (- (math.expt b 2) (* 4 a c)))) (* 2 a))
5 3.14 "fubar" variable :keyword
(fn [x] x)
(fn [x] x) arguments
(fn [x] x) body
(def answer 42)
(def hello (fn [name] (str "Hello " name)))
(defn hello [name] (str "Hello " name))
(hello "ZCEU")
(defn member? [x coll] (cond (empty? coll) false :else (or
(= (first coll) x) (member? x (rest coll)))))
(defn member? [x coll] (cond (empty? coll) false :else (or
(= (first coll) x) (member? x (rest coll)))))
(defn member? [x coll] (cond (empty? coll) false :else (or
(= (first coll) x) (member? x (rest coll)))))
(defn member? [x coll] (cond (empty? coll) false :else (or
(= (first coll) x) (member? x (rest coll)))))
(defn member? [x coll] (cond (empty? coll) false :else (or
(= (first coll) x) (member? x (rest coll)))))
(defn member? [x coll] (cond (empty? coll) false :else (or
(= (first coll) x) (member? x (rest coll)))))
(defn member? [x coll] (cond (empty? coll) false :else (or
(= (first coll) x) (member? x (rest coll)))))
(member? :c [:a :b :c :d])
(defn member? [x coll] (cond (empty? coll) false :else (or
(= (first coll) x) (member? x (rest coll))))) ! (member? :c [:a :b :c :d])
(defn member? [x coll] (cond (empty? coll) false :else (or
(= (first coll) x) (member? x (rest coll))))) ! (member? :c [:a :b :c :d])
(defn member? [x coll] (cond (empty? coll) false :else (or
(= (first coll) x) (member? x (rest coll))))) ! (member? :c [:a :b :c :d])
(defn member? [x coll] (cond (empty? coll) false :else (or
(= (first coll) x) (member? x (rest coll))))) ! (member? :c [:a :b :c :d])
(defn member? [x coll] (cond (empty? coll) false :else (or
(= (first coll) x) (member? x (rest coll))))) ! (member? :c [:a :b :c :d]) (member? :c [:b :c :d])
(defn member? [x coll] (cond (empty? coll) false :else (or
(= (first coll) x) (member? x (rest coll))))) ! (member? :c [:a :b :c :d]) (member? :c [:b :c :d])
(defn member? [x coll] (cond (empty? coll) false :else (or
(= (first coll) x) (member? x (rest coll))))) ! (member? :c [:a :b :c :d]) (member? :c [:b :c :d])
(defn member? [x coll] (cond (empty? coll) false :else (or
(= (first coll) x) (member? x (rest coll))))) ! (member? :c [:a :b :c :d]) (member? :c [:b :c :d])
(defn member? [x coll] (cond (empty? coll) false :else (or
(= (first coll) x) (member? x (rest coll))))) ! (member? :c [:a :b :c :d]) (member? :c [:b :c :d]) (member? :c [:c :d])
(defn member? [x coll] (cond (empty? coll) false :else (or
(= (first coll) x) (member? x (rest coll))))) ! (member? :c [:a :b :c :d]) (member? :c [:b :c :d]) (member? :c [:c :d])
(defn member? [x coll] (cond (empty? coll) false :else (or
(= (first coll) x) (member? x (rest coll))))) ! (member? :c [:a :b :c :d]) (member? :c [:b :c :d]) (member? :c [:c :d])
(defn member? [x coll] (cond (empty? coll) false :else (or
(= (first coll) x) (member? x (rest coll))))) ! (member? :c [:a :b :c :d]) (member? :c [:b :c :d]) (member? :c [:c :d]) => true
(defn member? [x coll] (cond (empty? coll) false :else (or
(= (first coll) x) (member? x (rest coll))))) ! (member? :c [:a :b :c :d]) (member? :c [:b :c :d]) => true
(defn member? [x coll] (cond (empty? coll) false :else (or
(= (first coll) x) (member? x (rest coll))))) ! (member? :c [:a :b :c :d]) => true
true
Collections
Filter
0 1 2 3 4 even?
0 1 2 3 4 even? 0
0 1 2 3 4 even? 0
0 1 2 3 4 even? 0 2
0 1 2 3 4 even? 0 2
0 1 2 3 4 even? 0 2 4
(filter even? [0 1 2 3 4])
Map
0 1 2 3 4 #(+ 5 %)
0 1 2 3 4 #(+ 5 %) 5
0 1 2 3 4 #(+ 5 %) 5 6
0 1 2 3 4 #(+ 5 %) 5 7
6
0 1 2 3 4 #(+ 5 %) 5 7
6 8
0 1 2 3 4 #(+ 5 %) 5 7
9 6 8
(map #(+ 5 %) [0 1 2 3 4])
Reduce
3 6 7 9 + 0 running total
3 6 7 9 + 0 3 running total
3 6 7 9 + 0 9 3 running total
3 6 7 9 + 0 9 3 16 running
total
3 6 7 9 + 0 9 25 3 16
running total
3 6 7 9 + 0 9 25 3 16
running total
(reduce + 0 [3 6 7 9])
0 1 2 3 4 even? 0 2 4 #(+
5 %) 5 7 9 + 5 12 21
Macros
(foo bar baz)
"(+ 1 2)" Reader + 1 2 + 1 2
Eval 3 Compile-time Runtime x 0 y 1 z 2
"(a 1 2)" Reader a 1 2 Compile-time Macro b
5 6 a 1 2
(defn id [x] x) => (def id (clojure.core/fn ([x] x)))
(-> [:foo :bar :baz] reverse first name string/reverse) (string/reverse (name
(first (reverse [:foo :bar :baz])))) =>
(defmacro unless [pred a b] `(if (not ~pred) ~a ~b))
(unless foo x y) => (if (not foo) x y)
unless ($foo) => if (!$foo)
class Foo ($bar) { } ! => ! class Foo
{ private $bar; function __construct($bar) { $this->bar = $bar; } }
($x): $x => fn ($x) { return $x; } =>
function ($x) { return $x; }
Backporting?
['foo', 'bar', 'baz'] => array('foo', 'bar', 'baz')
return function () { return $this->baz(); }; => $that =
$this; return function () use ($that) { return $that->baz(); };
5.5 5.4 5.3 5.2 FI ...
Y-Combinator
(defn Y [le] ((fn [f] (f f)) (fn [f] (le
#((f f) %)))))
(defn fac [f] (fn [x] (if (zero? x) 1 (*
x (f (dec x))))))
((Y fac) 5)
((Y ) 5) (fn [f] (fn [x] (if (zero? x)
1 (* x (f (dec x))))))
(( ) 5) (fn [f] (fn [x] (if (zero? x)
1 (* x (f (dec x)))))) (fn [le] ((fn [f] (f f)) (fn [f] (le #((f f) %)))))
Lambda Calculus
0: (fn [f] identity) 1: (fn [f] f) 2: (fn
[f] #(f (f %))) 3: (fn [f] #(f (f (f %))))
((n inc) 0)
(( inc) 0) (fn [f] identity)
( 0) identity
0
(( inc) 0) (fn [f] f)
( 0) inc
1
(( inc) 0) (fn [f] #(f (f %)))
( 0) #(inc (inc %))
2
(defn INC [n] (fn [p] (fn [x] (p ((n p)
x))))) ! ! (defn DEC [n] (fn [f] (fn [x] (((n (fn [g] (fn [h] (h (g f))))) (fn [y] x)) (fn [y] y))))) ! ! (defn ADD [m] (fn [n] ((n INC) m))) ! ! (defn MUL [m] (fn [n] ((n (ADD m)) ZERO)))
Meta-circular evaluator
• = • fn • cond • cons • first
• rest • quote
(defun null. (x) (eq x '())) ! (defun and. (x
y) (cond (x (cond (y 't) ('t '()))) ('t '()))) ! (defun not. (x) (cond (x '()) ('t 't))) ! (defun append. (x y) (cond ((null. x) y) ('t (cons (car x) (append. (cdr x) y))))) ! (defun list. (x y) (cons x (cons y '()))) ! (defun pair. (x y) (cond ((and. (null. x) (null. y)) '()) ((and. (not. (atom x)) (not. (atom y))) (cons (list. (car x) (car y)) (pair. (cdr x) (cdr y)))))) ! (defun assoc. (x y) (cond ((eq (caar y) x) (cadar y)) ('t (assoc. x (cdr y))))) (defun eval. (e a) (cond ((atom e) (assoc. e a)) ((atom (car e)) (cond ((eq (car e) 'quote) (cadr e)) ((eq (car e) 'atom) (atom (eval. (cadr e) a))) ((eq (car e) 'eq) (eq (eval. (cadr e) a) (eval. (caddr e) a))) ((eq (car e) 'car) (car (eval. (cadr e) a))) ((eq (car e) 'cdr) (cdr (eval. (cadr e) a))) ((eq (car e) 'cons) (cons (eval. (cadr e) a) (eval. (caddr e) a))) ((eq (car e) 'cond) (evcon. (cdr e) a)) ('t (eval. (cons (assoc. (car e) a) (cdr e)) a)))) ((eq (caar e) 'label) (eval. (cons (caddar e) (cdr e)) (cons (list. (cadar e) (car e)) a))) ((eq (caar e) 'lambda) (eval. (caddar e) (append. (pair. (cadar e) (evlis. (cdr e) a)) a))))) ! (defun evcon. (c a) (cond ((eval. (caar c) a) (eval. (cadar c) a)) ('t (evcon. (cdr c) a)))) (defun evlis. (m a) (cond ((null. m) '()) ('t (cons (eval. (car m) a) (evlis. (cdr m) a)))))
62 LOC
PHPPHP: 6208 LOC github.com/ircmaxell/PHPPHP
PHPPHP: 6208 LOC github.com/ircmaxell/PHPPHP (parser +6169 LOC)
)
None
None
None
None
• www.lisperati.com/logo.html • codon.com/programming-with-nothing • fogus.me/static/preso/magnificent7/
Questions? • clojure.org • github.com/igorw/ilias • github.com/igorw/galapagos ! • @igorwesome