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
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
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
200
The Power of 2
igorw
0
340
LISP 1.5 Programmer's Manual: A Dramatic Reading
igorw
0
490
The Moral Character of Software
igorw
1
320
interdisciplinary computing (domcode)
igorw
0
320
miniKanren (clojure berlin)
igorw
1
330
Other Decks in Programming
See All in Programming
20260623_Loop Engineeringで自分の分身の問い合わせBotを作る
ryugen04
0
160
使用 Meilisearch 建立新聞搜尋工具
johnroyer
0
100
LaravelLive Japan の裏方のすべて — 第188回 PHP勉強会@東京 (2026-06-24)
suguruooki
2
150
Vite+ Unified Toolchain for the Web
naokihaba
0
690
Go1.27で導入されるジェネリクスメソッドでできること
mackee
0
250
Snowflake Summitでの新機能 CoCo / CoWork / snowflake-summit-2026-overall-what-new-coco
tatsuhiro
1
210
OS アップデート対応の取り組み方がもっと共有されてほしい
andpad
0
110
dRuby over BLE
makicamel
2
410
Hatena Engineer Seminar #37「言語モデルの活用に関する研究」
slashnephy
0
500
気圧・高度・GPSを記録&可視化するアプリ「Koudo」を作った話
hjmkth
1
340
OSINT for SRE: 学術論文とポストモーテムから探る システム障害の共通パターン / SRE NEXT 2026
tomoyk
1
2.3k
AI駆動開発を妨げる技術的負債の解消アプローチ / ai-refactoring-approach
minodriven
17
8.7k
Featured
See All Featured
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
230
23k
Designing for Timeless Needs
cassininazir
1
270
BBQ
matthewcrist
89
10k
Everyday Curiosity
cassininazir
0
250
Why Mistakes Are the Best Teachers: Turning Failure into a Pathway for Growth
auna
0
180
Large-scale JavaScript Application Architecture
addyosmani
515
110k
Git: the NoSQL Database
bkeepers
PRO
432
67k
Become a Pro
speakerdeck
PRO
31
6k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
250
1.3M
Lightning talk: Run Django tests with GitHub Actions
sabderemane
0
220
Designing Powerful Visuals for Engaging Learning
tmiket
1
440
Testing 201, or: Great Expectations
jmmastey
46
8.2k
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