Author Topic: List to be re-constucted  (Read 3094 times)

0 Members and 1 Guest are viewing this topic.

Coder

  • Swamp Rat
  • Posts: 827
List to be re-constucted
« on: April 13, 2011, 09:03:16 AM »
Hello .

How could I divide this list to be a list or coordinate points ?

Code: [Select]
([color=red]3.09441[/color] [color=blue]3.20876[/color] 5.01197 4.31587 6.17619 2.29938 4.34473 -0.0756835 3.25095 1.8188 1.47881 1.8188 0.888771 4.57027 3.09441 3.20876)

Example .
(10 3.09441 3.20876)

So on for the rest of list .

Thanks.

Lee Mac

  • Seagull
  • Posts: 12923
  • London, England
Re: List to be re-constucted
« Reply #1 on: April 13, 2011, 09:09:17 AM »

gile

  • Gator
  • Posts: 2520
  • Marseille, France
Re: List to be re-constucted
« Reply #2 on: April 13, 2011, 09:14:02 AM »
Hi,

Here's a way:

Code: [Select]
(defun flatTo2dDXF (l)
  (if (cdr l)
    (cons (list 10 (car l) (cadr l)) (flatTo2dDXF (cddr l)))
  )
)
Speaking English as a French Frog

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: List to be re-constucted
« Reply #3 on: April 13, 2011, 09:14:57 AM »
Code: [Select]
(defun foo (lst)
  (if (cddr lst)
    (cons (list 10 (car lst) (cadr lst)) (foo (cddr lst)))
  )
)
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: List to be re-constucted
« Reply #4 on: April 13, 2011, 09:15:56 AM »
Well crap. I guess I should have checked when I received the warning that someone has posted.
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

pBe

  • Bull Frog
  • Posts: 402
Re: List to be re-constucted
« Reply #5 on: April 13, 2011, 09:19:43 AM »
Code: [Select]
(defun test (lst / NewList)
(repeat (/ (length lst) 2)
   (setq NewList (cons (list 10 (car lst) (car (setq ss (cdr lst)))) NewList) )
        (setq lst (cdr lst)))
  NewList
  )

Code: [Select]
[color=blue](defun test (lst)
  (if lst (progn
  (setq New_list (cons (list 10 (car lst) (car (setq lst (cdr lst)))) New_list))
  (test (cdr lst))) New_list)
  )[/color]

Edit: modifed for what its worth  :-)
« Last Edit: April 14, 2011, 05:01:47 AM by pBe »

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: List to be re-constucted
« Reply #6 on: April 13, 2011, 09:23:22 AM »
Code: [Select]
(defun [color=red]_SubLists[/color] ( lst n / sublist result )

    [color=green];;  Group list 'lst' into sublists of length 'n'.
    ;;
    ;;  Example:
    ;;
    ;;      (_SubLists '(1 2 3 4 5) 2)
    ;;
    ;;      => ((1 2) (3 4) (5))
    ;;
    ;;  Caller's responsibility to pass valid data. Dumb data /
    ;;  args? RAKE IN FACE.[/color]

    (foreach item lst
        (if (eq n (length (setq sublist (cons item sublist))))
            (setq
                result  (cons sublist result)
                sublist nil
            )
        )
    )
   
    (reverse
        (mapcar 'reverse
            (if sublist
                (cons sublist result)
                result
            )
        )
    )
)

Sample use:

Code: [Select]
(mapcar
    (function (lambda (sublist) (cons 10 sublist)))
    ([color=red]_SubLists[/color]
       '(   3.09441   
            3.20876
            5.01197
            4.31587
            6.17619
            2.29938
            4.34473
           -0.0756835
            3.25095
            1.8188
            1.47881
            1.8188
            0.888771
            4.57027
            3.09441
            3.20876
        )
        2
    )   
)

Code: [Select]
=>  (   (10 3.09441 3.20876)
        (10 5.01197 4.31587)
        (10 6.17619 2.29938)
        (10 4.34473 -0.0756835)
        (10 3.25095 1.8188)
        (10 1.47881 1.8188)
        (10 0.888771 4.57027)
        (10 3.09441 3.20876)
    )
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

pBe

  • Bull Frog
  • Posts: 402
Re: List to be re-constucted
« Reply #7 on: April 13, 2011, 09:29:52 AM »
double crap.. mine's messed up  :realmad:

Coder

  • Swamp Rat
  • Posts: 827
Re: List to be re-constucted
« Reply #8 on: April 13, 2011, 09:34:10 AM »
Thanks a lot guys .

Great help . Appreciated a lot .

I should have mentioned that my list is issued from a list of Coordinates from a routine .


Code: [Select]
(setq ss (entsel "\n Poly :"))
(setq pts (vlax-get (vlax-ename->vla-object (car ss)) 'Coordinates))

So the outcome of the Coordinates must be re-constructed to be re-used for another routs of lining .

Thanks a gain

Lee Mac

  • Seagull
  • Posts: 12923
  • London, England
Re: List to be re-constucted
« Reply #9 on: April 13, 2011, 09:35:39 AM »
Code: [Select]
(defun f ( l n )
  (
    (lambda ( g )
      (if l
        (cons (g l n) (f l n))
      )
    )
    (lambda ( a b )
      (if (< 0 b)
        (cons (car a) (g (cdr a) (1- b)))
        (setq l a a nil)
      )
    )
  )
)

Code: [Select]
_$ (f '(1 2 3 4 5 6 7 8 9) 3)
((1 2 3) (4 5 6) (7 8 9))

chlh_jd

  • Guest
Re: List to be re-constucted
« Reply #10 on: April 13, 2011, 03:46:47 PM »
Code: [Select]
(defun list-comp (a b / mid rslt)
    (repeat (/ (length a) b)
      (setq mid nil)
      (repeat b
(setq mid (cons (car a) mid)
      a   (cdr a)
)
      )
      (setq rslt (cons (reverse mid) rslt))
    )
  (if a (reverse (cons a rslt))
    (reverse rslt))
  )