Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #lang racket
- ;lista 11
- ;; zadanie 1
- (define/contract (suffixes xs)
- (parametric->/c [a] (-> (listof a) (listof (listof a))))
- (if (null? xs) (list xs)
- (cons xs(suffixes (cdr xs)))))
- ;; zadanie 2
- (define/contract (sublists xs)
- (parametric->/c [a] (-> (listof a) (listof (listof a))))
- (if (null? xs)
- (list null)
- (append-map
- (lambda (ys) (list (cons (car xs) ys) ys))
- (sublists (cdr xs)))))
- ;; testy
- ;; > (sublists '(1 2))
- ;; '((1 2) 2)
- ;; > (sublists '(1 2 3))
- ;; '((1 2 3) 2 3 (1 . 3) . 3)
- ;; zadanie 3
- (define/contract (task3-1 x y)
- (parametric->/c [a b] (-> a b a))
- x)
- (define/contract (task3-2 x y z)
- (parametric->/c [a b c] (-> (-> a b c) (-> a b) a c))
- (x z)(y z))
- (define/contract (task3-3 x y)
- (parametric->/c [a b c] (-> (-> b c) (-> a b) (-> a c)))
- (lambda(z) (x (y z))))
- (define (id x) x)
- (define/contract (task3-4 f)
- (parametric->/c [a] (-> (-> (-> a a) a) a))
- (f id))
- ;; >(task3-4 (lambda(x) (x 2)))
- ;; zadanie 4
- (define/contract (task4-loop x)
- (parametric->/c [a b] (-> a b))
- (task4-loop x))
- ;; zadanie 5
- (define/contract (foldl-map f a xs)
- (parametric->/c [a b c] (->(-> a b (cons/c c b)) b (listof a) (cons/c (listof c)b)))
- (define (it a xs ys)
- (if (null? xs)
- (cons (reverse ys) a)
- (let [(p (f (car xs) a))]
- (it (cdr p)
- (cdr xs)
- (cons (car p) ys)))))
- (it a xs null))
- ;;Pierwszy argument powinien być procedura przyjmujaca dwa argumenty, oznaczajace
- ;;(w kolejności) bieżacy element listy oraz bieżacy akumulator, zaś zwracajaca
- ;;pare złożona z nowego elementu listy oraz nowej wartości akumulatora.
- ;; Pozostałe dwa argumenty powinny zawierać startowa wartość akumulatora
- ;;oraz liste elementów do przetworzenia. Procedura foldl-map zwraca pare złożona
- ;;z listy wynikowej i końcowej wartości akumulatora.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement