diff options
| Commit | f7ef5548085eb4491e924ee63931f0c4c5142757 (patch) | |
|---|---|---|
| Author | 2022-11-10 11:54:20 +0200 | |
| Committer | 2022-11-10 11:54:20 +0200 | |
| Files | a5ee85ae7f3ff3cfaf5e26577ecf82abfc68b9e5 | |
| uni-projects-f7ef5548085eb4491e924ee63931f0c4c5142757.tar uni-projects-f7ef5548085eb4491e924ee63931f0c4c5142757.tar.gz uni-projects-f7ef5548085eb4491e924ee63931f0c4c5142757.zip | ||
| Parent | 3e62b4987d83343eb3f4c6ad3858214218ff8583 (diff) | |
[FP/P06] Added example usages
1 files changed, 11 insertions, 0 deletions
| -rw-r--r-- | Year 2/Functional Programming/06-Practice-10.11.2022.rkt | 11 |
diff --git a/Year 2/Functional Programming/06-Practice-10.11.2022.rkt b/Year 2/Functional Programming/06-Practice-10.11.2022.rkt index 07f89b3..6b35e19 100644 --- a/Year 2/Functional Programming/06-Practice-10.11.2022.rkt +++ b/Year 2/Functional Programming/06-Practice-10.11.2022.rkt @@ -7,6 +7,9 @@ [(not (pred (car xs) (car (cdr xs)))) #f] [else (ordered? (cdr xs) pred)])) +(ordered? '(1 2 3 4 5) <) ; -> #t +(ordered? '(1 2 3 6 5) <) ; -> #f + ;;; Задача 2 (define (max-ordered-sublist xs) @@ -17,6 +20,8 @@ [else (calc (cdr xs) biggest-sl (list (car xs)))])) (calc (cdr xs) (list (car xs)) (list (car xs)))) +(max-ordered-sublist '(1 2 3 4 5 1 0)) ; -> '(5 1) + ;;; Задача 3 (define (flatten xs) @@ -24,6 +29,8 @@ [(null? (cdr xs)) (flatten (car xs))] [else (append (flatten (car xs)) (flatten (cdr xs)))])) +(flatten '((1 2 3) (4 5 6) ((7 8) (9 10 (11 (12)))))) ; -> '(1 2 3 4 5 6 7 8 9 10 11 12) + ;;; Задача 4 (define (assoc key a-list) @@ -31,12 +38,16 @@ [(equal? key (caar a-list)) (cdar a-list)] [else (assoc key (cdr a-list))])) +(assoc 'b '((a 10) (c 6) (b 11) (b 45) (djf 9))) + ;;; Задача 5 (define (replace lst dict) (cond [(null? lst) lst] [else (append (assoc (car lst) dict) (replace (cdr lst) dict))])) +(replace '(1 2 3 4) '((1 a) (2 b) (3 c) (4 d))) ; -> '(a b c d) + ;;; Задача 6 (define (deep-delete lst) |
