Fundamentals of Computing
-
Upload
jan-wedekind -
Category
Software
-
view
194 -
download
0
description
Transcript of Fundamentals of Computing
http://wedesoft.de/downloads/cambridge2014.pdf
Fundamentals of Computing
1/18c© 2014 Jan Wedekind, Digital Science
http://wedesoft.de/downloads/cambridge2014.pdf
motivationThe Hundred-Year Language
2/18c© 2014 Jan Wedekind, Digital Science
Paul Graham
http://wedesoft.de/downloads/cambridge2014.pdf
motivationnot fundamentals of computing
3/18c© 2014 Jan Wedekind, Digital Science
http://wedesoft.de/downloads/cambridge2014.pdf
motivationBuilding Your Own Dynamic Language
4/18c© 2014 Jan Wedekind, Digital Science
Ian Piumarta
http://piumarta.com/papers/EE380-2007-slides.pdf
http://wedesoft.de/downloads/cambridge2014.pdf
motivationBuilding Your Own Dynamic Language
5/18c© 2014 Jan Wedekind, Digital Science
Application
System
Hardware
Libraries
Compiler
SyntaxSemanticsSource
Runtime
Language
Environment
malleable(underprogrammercontrol)
rigid (imposed fromoutside)
"blackbox" (hermetically sealed)
Pragmatics
UDP
http://wedesoft.de/downloads/cambridge2014.pdf
λ-calculuscore
6/18c© 2014 Jan Wedekind, Digital Science
x, y, z, . . . ∈ LM ∈ L ⇒ λx.M ∈ LM,N ∈ L ⇒ (MN) ∈ Lrecursive definition
x, y, z
lambda { |x| M }
M.call(N)
Ruby
x y z
(lambda (x) M)
(M N)
Scheme
abbreviations:• λab.M ≡ λa.λb.M
• MNO . . . = ((. . . (MN)O) . . .)
http://wedesoft.de/downloads/cambridge2014.pdf
λ-calculusChurch encoding
7/18c© 2014 Jan Wedekind, Digital Science
id ≡ λx.x
true ≡ λa.λb.a
nil ≡ false ≡ λa.λb.b
if1 ≡ λabc.abc
and ≡ λmn.mnm
or ≡ λmn.mmn
not ≡ λm.λab.mba
=bool ≡ λab.ab(not b)
1lazy evaluation
pair ≡ λhtx.(if xht)
head ≡ λl.(l true)
tail ≡ λl.(l false)
empty ≡ λl.(l (λhtb.false) true)
http://wedesoft.de/downloads/cambridge2014.pdf
λ-calculusbinary numbers
8/18c© 2014 Jan Wedekind, Digital Science
0 ≡ nil
1 ≡ (pair true nil)
2 ≡ (pair true (pair false nil))
3 ≡ (pair true (pair true nil))
...
http://wedesoft.de/downloads/cambridge2014.pdf
Schemevariable definitions ⇔ λ-expressions
9/18c© 2014 Jan Wedekind, Digital Science
Scheme uses eager evaluation
((lambda (f)
((lambda (x y)
(f x y))
2 3))
(lambda (a b) (+ a b)))
; 5
(let ((f (lambda (a b) (+ a b)))
(x 2) (y 3))
(f x y))
; 5
; (define f (lambda (a b) (+ a b)))
(define (f a b) (+ a b))
(define x 2) (define y 3)
(f x y)
; 5
http://wedesoft.de/downloads/cambridge2014.pdf
Schemerecursion ⇔ higher-order function
10/18c© 2014 Jan Wedekind, Digital Science
(define (neg l)
(if (null? l)
’()
(cons (- (car l))
(neg (cdr l)))))
(neg (list 1 2 3))
; (-1 -2 -3)
(sum (list 1 2 3))
(define (sum l)
(if (null? l)
0
(+ (car l)
(sum (cdr l)))))
(sum (list 1 2 3))
; 6
(use-modules (srfi srfi-1))
(map - (list 1 2 3))
; (-1 -2 -3)
(fold + 0 (list 1 2 3))
; 6
http://wedesoft.de/downloads/cambridge2014.pdf
Schemecurrying
11/18c© 2014 Jan Wedekind, Digital Science
(use-modules (srfi srfi-1))
(use-modules (srfi srfi-26))
(map (cut + <> 1) (list 1 2 3))
; 2 3 4
http://wedesoft.de/downloads/cambridge2014.pdf
Schemequote, eval & apply
12/18c© 2014 Jan Wedekind, Digital Science
(quote +)
; +
(quote (+ 1 2))
; (+ 1 2)
(car (quote (+ 1 2)))
; +
(eval (quote (+ 1 2)) (current-module))
; 3
(eval (car (quote (+ 1 2))) (current-module))
; #<procedure + (#:optional _ _ . _)>
(apply + (list 1 2))
; 3
http://wedesoft.de/downloads/cambridge2014.pdf
Scheme(hygienic) macros ⇔ lazy evaluation
13/18c© 2014 Jan Wedekind, Digital Science
(define-syntax-rule (lazy expr) (lambda () expr))
(define-syntax-rule (force expr) (expr))
(define y (let ((x 2)) (lazy (+ x 3))))
y
; #<procedure 105992de0 at <current input>:10:0 ()>
(force y)
; 5
http://wedesoft.de/downloads/cambridge2014.pdf
14/18c© 2014 Jan Wedekind, Digital Science
closures, monads, prompts, delimitedcontinuations, combinators, reification, multiple
dispatch, generics using functions,Y-combinator, Iota & Jot, reflection,inspection, readers, Factor, Haskell
http://wedesoft.de/downloads/cambridge2014.pdf
More ReferencesBinary Lambda Calculus
15/18c© 2014 Jan Wedekind, Digital Science
John Tromp
http://wedesoft.de/downloads/cambridge2014.pdfMore ReferencesStructure and Interpretation of Computer
Programs
16/18c© 2014 Jan Wedekind, Digital Science
Harold Abelson & Gerald Sussman
http://wedesoft.de/downloads/cambridge2014.pdf
More ReferencesUnderstanding Computation
17/18c© 2014 Jan Wedekind, Digital Science
Tom Stuart
http://wedesoft.de/downloads/cambridge2014.pdf
More ReferencesSchemer books
18/18c© 2014 Jan Wedekind, Digital Science
The
Little
Seasoned
Reasoned
Schemer: Q&A-style books