Talk done at the Ruby User Group Berlin, 4 June 2015
Dedicated to Guy Steele
Use the space bar or arrow keys to navigate
These slides will make more sense if you read the speaker notes.
0123456789
abcdefghijklmnopqrstuvwxyz
ABCDEFGHIJKLMNOPQRSTUVWXYZ
!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~
0123456789
abcdefghijklmnopqrstuvwxyz
ABCDEFGHIJKLMNOPQRSTUVWXYZ
!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~
0
1
11
42
8939247
"Do not go gentle!"
"Into that good night"
"R2D2"
"*@#%(^$#)(^$#"
true
false
12
"hello"
true
()"',;`
hello
*rug-b*
i-can-3/5/many-symbols
325352
hello-world
"Ruby is nice but"
"I miss my parentheses"
(23 . hello)
("my" . "word")
(car . cdr)
((7 . amazing) . ("head" . "lines"))
(1 . (2 . ( 3 . things)))
(nil . nil)
(nil . 5)
(1 . (2 . (3 . nil)))
nil
()
(car . cdr)
(first . rest)
()
(1 . ())
(2 . (1 . nil))
(3 . (2. (1 . ())))
(1 . (2 . (3 . nil)))
(1 2 3)
42
"smug"
(+ 2 3 5)
(filter (lambda (x) (> x 3))
(list 1 2 3 4 5))
(("name" "Arne") ("twitter" "@plexus"))
binding:
name: "Arne"
twitter: "@plexus"
drinks: "tea"
likes: ("programming" "juggling")
binding, s-expression -> result
12
"hello"
true
42
==> 42
"rug-b"
==> "rug-b"
true
==> true
hello
*rug-b*
i-can-3/5/many-symbols
binding:
name: "Arne"
twitter: "@plexus"
name
==> "Arne"
(function-pos
arg-pos1 arg-pos2 arg-pos3)
(quote (hello 123 ("world")))
==> (hello 123 ("world"))
'(hello 123 ("world"))
==> (hello 123 ("world"))
fn: input1, input2, ... -> output
eval: binding, s-expression -> result
apply: fn, args -> result
+
-
=
>
zero?
car
cdr
cons
list
(EVAL (> 9 (- 10 2)))
=> (APPLY > 9 (EVAL (- 10 2)))
=> (APPLY > 9 (APPLY - (10 2)))
=> (APPLY > 9 8)
==> true
(zero? 0) ==> true
(car '(1 2 3)) ==> 1
(cdr '(1 2 3)) ==> (2 3)
(list 1 2 3) ==> (1 2 3)
(car (list 1 2 3)) ==> 1
(car '(list 1 2 3)) ==> list
(cons 'a 'b) ==> (a . b)
(if (> 7 9)
"it's bigger"
"it's smaller")
==> "it's smaller"
(def x 3)
binding:
x: 3
(+ x 5)
==> 8
(lambda (x y)
(+ x y))
(x y) : argument list
(+ x y) : body
(lambda (x y) (+ x y))
==> {binding: b, args: (x y), body: (+ x y)}
(def add (lambda (x y) (+ x y)))
binding:
add: {bind: b, args:.. , body:.. }
(add 3 4)
=> (APPLY {bind: b, ...} 3 4)
Step 1. bind arguments
(APPLY add 3 4)
binding:
x: 3
y: 4
Step 2. evaluate body
binding:
x: 3
y: 4
(EVAL (+ x y))
=> (APPLY + (EVAL x) (EVAL y))
=> (APPLY + 3 4)
==> 7
(def map
(lambda (fn l)
(if (nil? l)
nil
(cons (fn (car l)) (map fn (cdr l))))))
(map (lambda (x) (* x x)) '(1 2 3))
==> (2 4 9)
(def reduce
(lambda (fn val l)
(if (nil? l)
val
(reduce fn (fn val (car l)) (cdr l)))))
(reduce + 0 '(1 2 3))
==> 6
(defmacro defun (name args body)
(list 'def name
(list 'lambda args body)))
(defun (x y) (+ x y))
=> (eval '(def name (lambda (x y) (+ x y))))
:trollface:
Saturday 11 July, 9:00 - 17:00
(InstallFest on Friday)
**Coaches Training**
Next Thursday, 19:30
6Wunderkinder (Alexanderplatz)