Created
July 14, 2017 22:45
-
-
Save FernandoBasso/8e7f058c0624fcd6f9dd9fbb57da0dda to your computer and use it in GitHub Desktop.
Produce lists in increasing number of items from input list.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(define (defsep los) | |
(if (empty? (rest los)) | |
"" | |
", ")) | |
(define (concat los) | |
(cond [(empty? los) ""] | |
[else | |
(string-append (first los) | |
(defsep los) | |
(concat (rest los)))])) | |
(define (breadcrumb lol) | |
(cond [(empty? lol) '()] | |
[else | |
(cons (concat lol) | |
(breadcrumb (reverse (rest (reverse lol)))))])) | |
(breadcrumb '()) | |
(breadcrumb '("one")) | |
(breadcrumb '("one" "two")) | |
(breadcrumb '("one" "two" "three")) | |
(reverse (breadcrumb '("one" "two" "three" "four"))) | |
;; '() | |
;; (list "one") | |
;; (list "one, two" "one") | |
;; (list "one, two, three" "one, two" "one") | |
;; (list "one" "one, two" "one, two, three" "one, two, three, four") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment