Just wanted to share my solution to this common problem.
(defun nub (l "l")
(let ((table (makeTable "" nil)))
(foreach e l table[e] = t)
table->?))
Output:
(nub (parseString "Banana Rama" "")) => ("a" "m" "n" "R" "B" " ")
This assumes order doesn't matter. If order does matter (and efficiency doesn't...), you could use this O(n^2) version, which is a literal translation of the one in the Haskell Data.List library:
(defun nub (l "l")
(defun _nub (xs ls "ll")
(unless (null xs)
(destructuringBind (x @rest xs) xs
(if (member x ls)
(_nub xs ls)
(cons x (_nub xs (cons x ls)))))))
(_nub l nil))
Output:
(nub (parseString "Banana Rama" "")) => ("B" "a" "n" " " "R" "m")
If you want to preserve order and get O(n) performance, you could modify the last version to use a table instead of a list:
(defun nub (l "l")
(defun _nub (xs ls "lo")
(unless (null xs)
(destructuringBind (x @rest xs) xs
(if (ls[x])
(_nub xs ls)
(cons x (_nub xs (ls[x] = t && ls)))))))
(_nub l (makeTable "" nil)))
Output:
(nub (parseString "Banana Rama" "")) => ("B" "a" "n" " " "R" "m")