Skip to content

Instantly share code, notes, and snippets.

@FernandoBasso
Created July 14, 2017 22:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FernandoBasso/8e7f058c0624fcd6f9dd9fbb57da0dda to your computer and use it in GitHub Desktop.
Save FernandoBasso/8e7f058c0624fcd6f9dd9fbb57da0dda to your computer and use it in GitHub Desktop.
Produce lists in increasing number of items from input list.
(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