Take the 2-minute tour ×  How can I construct the function segs
that returns a list of all contiguous segments in a list? For
example, (segs '(l i s t)) should produce the following answer:
(() (t) (s) (s t) (i) (i s) (i s t) (l) (l i) (l i s) (l i s t))
I'm especially interested in how to solve this problem in
accordance with the design principles described in HtDP (no,
this is not the problem from the book, so please feel free to
discuss it!) How to solve it? Which principles to use in program
derivation?  share|improve this question To ask for
clarification, post a comment on the answer and/or amend your
question, don't try edit the answer itself. –  Ryan Culpepper
Jan 10 '12 at 19:21 add comment  2 Answers  up vote 5 down vote
accepted  Start by building up a set of related examples, most
trivial first:  (equal? (segs '())         (list '())) (equal?
(segs '(z))         (list '() (equal? (segs '(y z))
(list '() '(z)               '(y) '(y z))) (equal? (segs '(x y
z))         (list '() '(z) '(y)