One way to approach this is to "sort out" things
into various groups and then apply a sum on each.
Use sort-out function, like I posted once here:
(setq vals '(("25x19" 1500)("50x19" 2500)("25x19" 1000)("6x19" 750)("50x19"
3000)))
(setq sorted nil)
(sort-out vals
'sorted ;; store under this variable
car ;; using car as a key
cadr ;; and cadr as value
)
(setq res
(mapcar
'(lambda(g)
(cons (car g)(apply '+ (cdr g))))
sorted))
so you can retrieve total size with (cdr(assoc "50x19" res)) ==> 5500
where
(defun sort-out (things container-sym keyfun valfun)
(foreach thing things
(store (valfun thing) (keyfun thing) container-sym))
container-sym)
(defun store (x k c / cv a)
(setq cv (vl-symbol-value c)) ; A2K and above
(if (setq a (assoc k cv))
(set c (subst (cons k (cons x (cdr a)))
a cv))
(set c (cons (list k x) cv))))
Cheers,
--
Have fun, 🙂
Vlad http://vnestr.tripod.com/
(define (average . ns)
(if ns (/ (apply '+ ns) (length ns))))
rcunningham wrote in message
news:f09572c.-1@WebX.maYIadrTaRb...
> Hello everyone, I need a little help getting un-stuck..... I have a list
such as this, where each item is a label and distance: (("25x19"
"1500'")("50x19" "2500'")("25x19" "1000'")("6x19" "750'")("50x19"
"3000'"))..... Without creating alot of (cond)'s for each possible label,
how would I create a new list that combines duplicate labels and adds the
distance?..... The result would look like this: (("25x19" "2500'")("50x19"
"5500'")("6x19" "750'"))..... If it would make it easier, I can create the
original list so that the distance is an integer..... Thanks for any help,
Robert.....(using A2K)
>