| Hello all! Here's a basic function to filter out duplicates in a list (and sort it in the mean time) (def unique_list (ls)
"Removes all duplicated values in LS. Returns a new list"
(= ls (sort < ls))
((afn (ls uniq_ls x) ;; uniq_ls -> the list we are building, x-> last inserted value
(let y (car ls) ;; y -> actual value
(if (no y)
uniq_ls ;; we're done, return list
(is x y)
(self (cdr ls) uniq_ls y) ;; current val is same than last one, we don't insert it
(self (cdr ls) (join uniq_ls (list y)) y)))) ;; else we insert it and continue recursion
ls () nil)) ;; function call
But I feel I'm missing Arc lisp's power. So I think it's a good function to post out here, since there must be some more elegant manner of solving the mentionned problem. No particular need for the algorithm to sort... Maybe that could be an improvement also made?Thanks alot, Enjoy! Mike. |