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
200
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
ローカルLLMでどこまでコードが書けるか -拡張版 / How much code can be written on a local LLM Extended
kishida
12
4.5k
これからAgentCoreを触る方へトレンドはGatewayです
har1101
6
440
例外の正しい扱い方 そのエラー try-catchして大丈夫?
jinwatanabe
0
300
生成AI時代にこそ効くGo | Why Go Works in the Age of Generative AI
mom0tomo
8
3.4k
Contextとはなにか
chiroruxx
1
380
Dataformのリポジトリを立ち上げるときにまずやること / dataform-day0-2026
snhryt
0
200
コンテキストの使い捨てをやめる — ビジネスルール駆動開発と miko —
ioki
0
250
A2UI という光を覗いてみる
satohjohn
1
170
JavaDoc 再入門
nagise
1
430
Even G2とAWSで推しのエージェントを召喚しよう!
har1101
1
140
PHPで使える日時の表現と、その知り方 #frontend_phpcon_do
o0h
PRO
0
280
さぁV100、メモリをお食べ・・・
nilpe
0
160
Featured
See All Featured
Designing Dashboards & Data Visualisations in Web Apps
destraynor
231
55k
技術選定の審美眼(2025年版) / Understanding the Spiral of Technologies 2025 edition
twada
PRO
118
120k
Art, The Web, and Tiny UX
lynnandtonic
304
22k
Claude Code のすすめ
schroneko
67
230k
Navigating Algorithm Shifts & AI Overviews - #SMXNext
aleyda
1
1.3k
Measuring & Analyzing Core Web Vitals
bluesmoon
9
870
The State of eCommerce SEO: How to Win in Today's Products SERPs - #SEOweek
aleyda
2
11k
[RailsConf 2023] Rails as a piece of cake
palkan
59
6.7k
Ten Tips & Tricks for a 🌱 transition
stuffmc
0
150
Designing for humans not robots
tammielis
254
26k
We Have a Design System, Now What?
morganepeng
55
8.2k
The Mindset for Success: Future Career Progression
greggifford
PRO
0
370
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