Author Topic: [HELP]Deal the list with one condition!  (Read 1206 times)

0 Members and 1 Guest are viewing this topic.

cjw

  • Newt
  • Posts: 162
[HELP]Deal the list with one condition!
« on: April 29, 2009, 04:09:51 AM »
Code: [Select]
(setq LST1 '(((1371.24 720.75 0.0) . 100.408)
     ((1030.31 740.794 0.0) . 80.7133)
     ((1030.31 740.794 0.0) . 40.6777)
     ((655.957 393.364 0.0) . 92.1824)
     ((655.957 393.364 0.0) . 53.9207)
     ((527.273 794.245 0.0) . 116.764)
    )
)

Code: [Select]
(setq LST2 '(((1371.24 720.75 0.0) . (100.408))
     ((1030.31 740.794 0.0) . (80.7133 40.6777))
     ((655.957 393.364 0.0) . (92.1824 53.9207))
     ((527.273 794.245 0.0) . (116.764))
    )
)

How to realize LST1->LST2?

Thanks,it's too hard for me,I think there are good boys can help me here.
The slow need to start early!

mkweaver

  • Bull Frog
  • Posts: 346
Re: [HELP]Deal the list with one condition!
« Reply #1 on: April 29, 2009, 06:31:11 AM »
cjw, are you sure you want the dot in there on the output?  Notice that the output from your setq lst2 strips the dots:
Code: [Select]
(((1371.24 720.75 0.0) 100.408)
  ((1030.31 740.794 0.0) 80.7133 40.6777)
  ((655.957 393.364 0.0) 92.1824 53.9207)
  ((527.273 794.245 0.0) 116.764)
)

That said, the following code will return the same thing as your setq lst2:
Code: [Select]
(defun CondenseList(lst1 / lstsbypoint rtlist)
  (setq
    lstsbypoint (mapcar
  (function
    (lambda(ptinfo1)
      (vl-remove-if-not
(function
  (lambda(pt)
    (equal (car pt) (car ptinfo1))
    )
  )
lst1
)
      )
    )
  lst1
  )
    rtlist (mapcar
     (function
       (lambda(x)
(CombineCDRs x)
)
       )
     lstsbypoint
     )
    rtlist (removeduplicates rtlist)
    )
  )

(defun CombineCDRs(lst / rtlist)
  (setq rtlist
  (cons (caar lst)
(mapcar
  (function
    (lambda(pts /)
      (setq rtlist (cons (cdr pts) rtlist))
      )
    )
  lst
  )
)
rtlist (vl-list*
(car rtlist)
(if (= 1 (length (cdr rtlist)))
   (cadr rtlist)
   (reverse (last rtlist))
   )
)
)
  )


;;This removeduplicates code came from a post by MP

(defun RemoveDuplicatesAux ( x )
    (cond
        ((vl-position x index))
        ((null (setq index (cons x index))))
    )
)

(defun RemoveDuplicates ( lst / index )
    (vl-remove-if
       'RemoveDuplicatesAux
        lst
    )
)

And running this with your lst1 returns:
Code: [Select]
(setq temp (condenselist lst1))

(((1371.24 720.75 0.0) 100.408)
  ((1030.31 740.794 0.0) 80.7133 40.6777)
  ((655.957 393.364 0.0) 92.1824 53.9207)
  ((527.273 794.245 0.0) 116.764)
)

cjw

  • Newt
  • Posts: 162
Re: [HELP]Deal the list with one condition!
« Reply #2 on: April 29, 2009, 07:27:13 AM »
mkweaver,
Good job!
Thank you vvvvvvery much!!!!
The slow need to start early!

mkweaver

  • Bull Frog
  • Posts: 346
Re: [HELP]Deal the list with one condition!
« Reply #3 on: April 29, 2009, 11:19:02 AM »
You are welcome.