Professional Documents
Culture Documents
SESSIE 1
1
Les 1: De basiselementen
3
Elementen van een programmeertaal
Data Procedure
5 5.0 + -
Primitive -3 * /
3.14
(* 3 5)
Combination (+ 1 2 3 4 5)
(/ (* 3 5) (+ 1 2))
4
Terminologie (1)
getal number
uitdrukking expression
primitieve uitdrukking primitive expression
primitieve operator primitive operator
samengestelde uitdrukking compound expression
vertolker - evaluator interpreter
evaluatie evaluation
samenstelling of combinatie combination
operator - operanden operator - operands
proceduretoepassing - oproep procedure application - call
prefixnotatie prefix notation
geneste uitdrukking nested expression
variabele variable
waarde value
5
Terminologie (2)
omgeving environment
globale omgeving global environment
deeluitdrukking subexpression
recursie recursion
boom tree
knopen nodes
takken branches
terminale knopen terminal nodes
boom accumulatie tree accumulation
speciale vorm special form
proceduredefinitie procedure definition
formele parameters formal parameters
actuele parameters actual parameters
6
De evaluator
5 )
3
(*
15
7
De read-eval-print cyclus
>5
5
> (* 3 5)
15
> (+ 1 2 3 4 5)
15
8
Uitdrukkingen
>5 primitieve
5 uitdrukking
> -7
-7
> 3.14
3.14
> (* 3 5) samengestelde
15 uitdrukking
> (+ 1 2)
3
> (+ 1 2 3 4 5)
15
> (/ (+ 4 6) 2) geneste
5 samengestelde
> (+ (* 2 5) (- 7 2)) uitdrukking
15
> (- 6 (/ 12 4) (* 2 (+ 5 6)))
-19
9
Variabelen (1)
global environment
>n
⊗⊗ n: undefined;
cannot reference undefined identifier
> (define n 5) global environment
>n n: 5
5
> (* 4 n)
20
> (+ x 2)
⊗⊗ x: undefined;
cannot reference undefined identifier
global environment
> (define x 7)
> (+ x 2) n: 5
9 x: 7
global environment
> (define straal 10) straal: 10
> (define pi 3.14159) pi: 3.14159
> (define omtrek (* 2 pi straal)) omtrek: 62.8318
> omtrek
62.8318
11
Variabelen (3)
global environment
>+
+: +
#<procedure:+>
> (+ 2 3)
5
global environment
>$
⊗⊗ $: undefined; +: +
cannot reference undefined identifier
> (define $ +) $: +
>$
#<procedure:+>
> ($ 4 5)
9
12
Het omgevingsmodel voor evaluatie
global environment
> (define x 5) x: 5
y: 6
> (define y 6)
+: +
> (+ x y)
11 *: *
$:
> (define $ +) *
>$
#<procedure:+> (+ x y) ($ x y)
> ($ x y)
11 + 5 6 + 5 6
13
Evaluatie: Samenvatting
Number ! Number
Boolean ! Boolean
Symbol ! Object associated with symbol in environment
Combination ! Evaluate each subexpression and apply
value of leftmost subexpression to the values
of the other subexpressions
Special Form ! Dedicated behaviour
14
Les 1: De basiselementen
SESSIE 2
15
Procedurele abstractie
“om het kwadraat van ‘iets’ te berekenen,
vermenigvuldig ‘iets’ met zichzelf”
formele parameter
> (kwadraat 5)
25
procedure oproep
> (kwadraat (+ 2 5))
49
17
Parameter binding is ‘positioneel’
3 formele parameters in
de proceduredefinitie
(define (kwadraat x) x x2
(* x x))
(define (som-kwadraten x y) x, y x 2 + y2
(+ (kwadraat x) (kwadraat y)))
> (f 5)
definities ingetikt
136
in de editor
interacties
19
Het substitutiemodel voor
procedure evaluatie
applicative order normal order
(f 5) (f 5)
(som-kwadraten (+ x 1) (* x 2)) (som-kwadraten (+ x 1) (* x 2))
(som-kwadraten (+ 5 1) (* 5 2)) (som-kwadraten (+ 5 1) (* 5 2))
(+ (kwadraat x) (kwadraat y)) (+ (kwadraat x) (kwadraat y))
(+ (kwadraat 6) (kwadraat 10)) (+ (kwadraat (+ 5 1)) (kwadraat (* 5 2)))
(+ (* x x) (* x x)) (+ (* x x) (* x x))
(+ (* 6 6) (* 10 10)) (+ (* (+ 5 1) (+ 5 1)) (* (* 5 2) (* 5 2)))
(+ 36 100) (+ (* 6 6) (* 10 10))
136 (+ 36 100)
136
20
Het omgevingsmodel voor
procedure evaluatie (1)
global environment
kwadraat:
som-kwadraten:
f:
parameters: x
body: (* x x)
parameters: x y
body: (+ (kwadraat x) (kwadraat y))
parameters: x
body: (som-kwadraten (+ x 1) (* x 2))
21
Het omgevingsmodel voor
procedure evaluatie (2)
global environment
kwadraat:
som-kwadraten:
f:
local environment
(f 5)
x: 5
(som-kwadraten (+ x 1) (* x 2)) local environment
(som-kwadraten 6 10)
local environment local environment
x: 6 (kwadraat 6) (kwadraat 10)
y: 10 x: 6 x: 10
(+ (kwadraat x) (kwadraat y)) (* x x) (* x x)
36 100
136 136
22
Procedures als zwarte dozen:
Procedurele abstractie
SESSIE 1
24