# Pure functional code for the sublists of a list

The code below gives me the list of sublists of a list. Code can still be improved to avoid the use of append, right?

(defun sublists (alist)
(labels ((aux (list p r)
(if (null list)
(append r (maplist #'identity p))
(aux (cdr list)
(append p (list (car list)))
(append r (maplist #'identity p))))))
(aux alist nil nil)))

CL-USER> (sublists (list 1 2 3 4))
((1) (1 2) (1 2 3) (1 2 3 4) (2) (2 3) (2 3 4) (3) (3 4) (4))


ideas? This question was posted in https://stackoverflow.com/questions/49019045/pure-functional-code-for-the-sublists-of-a-list originally.

• It's OK for the output to appear in any order, right? – 200_success Mar 1 '18 at 1:18
• yes, it is fine. – Alexandre Rademaker Apr 6 '18 at 3:35