On Wed, Nov 5, 2008 at 7:21 PM, dan brooks <alloh...@gmail.com> wrote:
If you just have some lists and its not in a table...
this does everything... i think
(defun samep (lst)
(null
(remove-if-not #'null (mapcar #'(lambda (x) (if (numberp x) (= x (car
lst)) (string= (symbol-name x) (symbol-name (car lst))))) lst))))
there are much more elegant ways of doing it but again... this is a hack job
Dan
;; i am in awe of dan's coding skills!
;; my version is MUCH longer than dan's
; first, i wrote something that returns "t" if everything in a list has the same value
(defun singletonp (list) ; top-level driver. initializes the goal variable for the worker
(or (null list)
(singletonp1 (first list) (rest list))))
(defun singletonp1 (goal list) ; the worker
(or (null list)
(and (eql goal (first list))
(singletonp1 goal (rest list)))))
; second, i wrote those that turned the columns into rows so i can use my "singletonp" column
(defun transpose (x)
(apply #'mapcar (cons #'list x)))
; third, i write something that glues it all together. note that there are two calls to transpose:
; once to turn columns to rows then once to turn it all backwards
(defun prune-singleton-columns (lists)
(transpose
(prune-singleton-columns1
(transpose lists))))
; this one just runs over the lists and only adds to "out" if it is not a singletonp
(defun prune-singleton-columns1 (lists)
(let (out)
(dolist (list lists (reverse out))
(unless (singletonp list)
(push list out)))))
; fourth, i wrote a test case to see if i can reprorduce justin's goal
(defun testdata ()
'((1 2 3 5) (2 3 5 5) (9 8 6 5)))
(defun test-prune-singleton-columns ()
(prune-singleton-columns (testdata)))
; that's all. for an example on how to call this, see test-prune-singleton-columns
t
--
timm, a/prof, csee, wvu, usa
Chris Rock - "You don't pay taxes - they take taxes."