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 (dpc13)
Search
Igor Wiedler
June 07, 2013
Programming
1.2k
3
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Introduction to Lisp (dpc13)
Igor Wiedler
June 07, 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
AIで効率化できた業務・日常
ochtum
0
150
ランチタイムLT会3周年!ランチタイムLT会を3年間続けられたお話
y0hgi
1
120
1B+ /day規模のログを管理する技術
broadleaf
0
120
肥大化するレガシーコードに立ち向かうためのインターフェース分離と依存の逆転 / JJUG CCC 2026 Spring
hirokunimaeta
0
640
その問い、本当に正しいですか?AI時代のエンジニアに必要な哲学と認知科学 / ai-philosophy-cognitive-science
minodriven
14
6.5k
気圧・高度・GPSを記録&可視化するアプリ「Koudo」を作った話
hjmkth
1
330
AI時代のUIはどこへ行く?その2!
yusukebe
22
7.6k
これからAgentCoreを触る方へトレンドはGatewayです
har1101
5
430
生成AI時代にこそ効くGo | Why Go Works in the Age of Generative AI
mom0tomo
8
3.4k
TAKTでAI駆動開発の品質を設計する
j5ik2o
7
1.6k
決定論的オーケストレーションの設計と実装 / Design and Implementation of Deterministic Orchestration
nrslib
4
1.5k
The NotImplementedError Problem in Ruby
koic
1
980
Featured
See All Featured
Abbi's Birthday
coloredviolet
3
8.3k
The Organizational Zoo: Understanding Human Behavior Agility Through Metaphoric Constructive Conversations (based on the works of Arthur Shelley, Ph.D)
kimpetersen
PRO
0
370
svc-hook: hooking system calls on ARM64 by binary rewriting
retrage
2
320
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
128
56k
Effective software design: The role of men in debugging patriarchy in IT @ Voxxed Days AMS
baasie
0
440
Deep Space Network (abreviated)
tonyrice
0
220
We Are The Robots
honzajavorek
0
260
What's in a price? How to price your products and services
michaelherold
247
13k
The Director’s Chair: Orchestrating AI for Truly Effective Learning
tmiket
1
200
Imperfection Machines: The Place of Print at Facebook
scottboms
270
14k
Agile Leadership in an Agile Organization
kimpetersen
PRO
0
170
Marketing to machines
jonoalderson
1
5.5k
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 "dpc13")
(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)
retry (5) { failing_call(); } catch ($e) { // ...
whoops }
class Foo ($bar) { } => class Foo { private
$bar; function __construct($bar) { $this->bar = $bar; } }
($x): $x => fn ($x) { return $x; } =>
function ($x) { return $x; }
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 After lunch, E102
PHPPHP: 6208 LOC github.com/ircmaxell/PHPPHP After lunch, E102 (parser +6169 LOC)
)
None
None
None
• www.lisperati.com/logo.html • codon.com/programming-with-nothing • fogus.me/static/preso/magnificent7/
Questions? • joind.in/8442 • clojure.org • @igorwesome