Sysop: | Amessyroom |
---|---|
Location: | Fayetteville, NC |
Users: | 27 |
Nodes: | 6 (0 / 6) |
Uptime: | 55:23:59 |
Calls: | 481 |
Calls today: | 13 |
Files: | 1,071 |
Messages: | 95,805 |
Posted today: | 2 |
If a list contains repeated elements they should be replaced
with a single copy of the element. The order of the elements
should not be changed.
Example:
* (compress '(a a a a b c c a a d e e e e))
(A B C A D E)
If a list contains repeated elements they should be replaced
with a single copy of the element. The order of the elements
should not be changed.
Example:
* (compress '(a a a a b c c a a d e e e e))
(A B C A D E)
In newLisp, "apply" can be used for reduce or fold.
(define (compress lst)
(reverse
(apply
(fn (accum x)
(cond ((empty? accum) (list x))
((= x (first accum)) accum)
(true (cons x accum))))
(cons '() lst)
2) ;; How many things to process at a time.
))
(compress '(a a a a b c c a a d e e e e))
===>
(a b c a d e)