S-99-09 Pack consecutive duplicates of list elements into sublists.

If a list contains repeated elements they should be placed in separate sublists.


 (pack '(a a a a b c c a a d e e e e)) 
 ; => ((a a a a) (b) (c c) (a a) (d) (e e e e)) 


 (define pack 
   (lambda (xs) 
     (if (null? xs) '() 
       (let loop ((rest (cdr xs)) 
                  (pkg (list (car xs)))) 
         (cond ((null? rest) 
                (list pkg)) 
               ((eq? (car pkg) (car rest)) 
                (loop (cdr rest) (cons (car rest) pkg))) 
                 (cons pkg (loop (cdr rest) (list (car rest))))))))))