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
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Igor Wiedler
November 20, 2013
Programming
360
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
950
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
【やさしく解説 設計編 #0】DDDのコード、読めるのに分からない人へ
panda728
PRO
2
280
Hatena Engineer Seminar #37「言語モデルの活用に関する研究」
slashnephy
0
540
1年で人数1.5倍、PR数5.5倍増。 品質とアウトカムはどうなったか、 何が効いたか
ike002jp
0
150
数百円から始めるRuby電子工作
tarosay
0
100
광주소프트웨어마이스터고등학교 DevFest 특강 - 바이브 코딩 시대에서 주니어 개발자로 살아남는 방법
utilforever
1
150
GitHubCopilotCLIのスラッシュコマンドを自作してみる
htkym
0
100
全PRの83%がAIレビューだけでマージできるようになった開発組織はその後どうなったか
athug
0
350
【やさしく解説 設計編・中級 #4】ルールの寿命と、システムの年輪
panda728
PRO
2
170
act1-costs.pdf
sumedhbala
0
250
AI時代のPHPer生存戦略 ~「言語、もうなんでもよくない?」に本気で向き合う~
vivion
0
160
コーディングルールの鮮度を保ちたい for SRE NEXT 2026 / keep-fresh-go-internal-conventions-sre-next-2026
handlename
0
150
PostgreSQL 18で考えるUUID主キー
kazuhiro1982
0
320
Featured
See All Featured
Measuring & Analyzing Core Web Vitals
bluesmoon
9
910
The Language of Interfaces
destraynor
162
27k
What Being in a Rock Band Can Teach Us About Real World SEO
427marketing
0
1.1k
The Impact of AI in SEO - AI Overviews June 2024 Edition
aleyda
5
1.1k
The untapped power of vector embeddings
frankvandijk
2
1.8k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.8k
How to optimise 3,500 product descriptions for ecommerce in one day using ChatGPT
katarinadahlin
PRO
1
3.7k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
659
62k
Fantastic passwords and where to find them - at NoRuKo
philnash
52
3.8k
Mind Mapping
helmedeiros
PRO
1
290
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
34
2.8k
For a Future-Friendly Web
brad_frost
183
10k
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