-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebdev2013.rkt
More file actions
47 lines (33 loc) · 1.23 KB
/
webdev2013.rkt
File metadata and controls
47 lines (33 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
; Se dau a) un numar intreg i si b) o colectie arbitrar de lunga
; (f1, f2, ..., fn) de functii care accepta ca argument un numar intreg
; si intorc tot un numar intreg. Sa se scrie un program care intoarce
; o colectie de numere intregi reprezentand rezultatele aplicarii
; acelor functii asupra valorii i.
; Exemplu de input: 4 si [add_one, multiply_by_five] => output-ul va fi [5, 20].
; Alt exemplu de input: 7 si [subtract_three, add_two, multiply_by_three] => output-ul va fi [4, 9, 21].
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(define multiply_by_five
(lambda (x)
(* x 5)))
(define add_two
(lambda (x)
(+ x 2)))
(define substract_one
(lambda (x)
(- x 1)))
(define substract_three
(lambda (x)
(- x 3)))
(define fList_1 (list multiply_by_five add_two))
(define fList_2 (list add_two multiply_by_five substract_one substract_three))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(define main_function
(lambda (x listf)
(aux_function x listf '())))
(define aux_function
(lambda (x listf result)
(if(null? listf) (reverse result)
(aux_function x (cdr listf) (cons ((car listf) x) result)))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(main_function 3 fList_1)
(main_function 3 fList_2)