Programmation Fonctionnelle David Dyja - 12 f´evrier 2009
Programmation Fonctionnelle
R´
ep´
etition 1
11 f´
evrier 2010
Rappels
(cons ’a ’b) -> (a . b)
(cons ’a ’(b)) -> (a . (b)) ;;= (a b)
(list ’(a) ’b) -> ((a) b)
(append ’(a) ’(b)) -> (a b)
D´efinir une fonction:
(define f
(lambda (arg1 arg2 ...)
(... ))
ou
(define (f arg1 arg2 ...)
(... ))
´
Evaluations
Exercice 1
3 -------------------------------------------> 3
#t ---------------------------------------- -> #t
(+ 1 2) ----------------------------------- -> 3
(/ 2 3) ----------------------------------- -> 2/3
(+ (* 3 4) 10) ---------------------------- -> 22
(* 3 (- 12 5)) ---------------------------- -> 21
(+ (+ 5 8) (+ 2 4)) ----------------------- -> 19
(define a 4) ------------------------------ -> NS // non sp´ecifi´e
a ----------------------------------------- -> 4
(quote a) --------------------------------- -> a
’a ---------------------------------------- -> a
(define b a) ------------------------------ -> NS
b ----------------------------------------- -> 4
(define a 6) ------------------------------ -> NS
a ----------------------------------------- -> 6
b ----------------------------------------- -> 4
(define c (quote a)) ---------------------- -> NS
c ----------------------------------------- -> a
(define d #t) ----------------------------- -> NS
(define Robert ’Bob) ---------------------- -> NS
Robert ------------------------------------ -> Bob
(car ’(a b)) ------------------------------ -> a
(car (quote (a b))) ----------------------- -> a
(cdr ’(a b)) ------------------------------ -> (b)
(cdr (quote (a b))) ----------------------- -> (b)
(cons ’a ’()) ----------------------------- -> (a)
(cons ’a ’(b)) ---------------------------- -> (a b)
1