Author Topic: list help  (Read 582 times)

0 Members and 1 Guest are viewing this topic.

abe123456789

  • Newt
  • Posts: 22
list help
« on: May 19, 2023, 09:58:33 PM »
Good evening,

How can i make this list ( 1 2 0 2 3 0 4 5 0 . . .) into this ((1 2 0) (2 3 0) ( 4 5 0)( . . .))

Thank you in advance
« Last Edit: May 19, 2023, 10:08:04 PM by abe123456789 »

JohnK

  • Administrator
  • Seagull
  • Posts: 10288
Re: list help
« Reply #1 on: May 19, 2023, 10:42:09 PM »
Because you have not specified if the list will always be a multiple of three I recommend a simple recursive function.

Code - Auto/Visual Lisp: [Select]
  1. (defun packthree (lst)
  2.   (if (null lst)
  3.     nil
  4.     (cons (list (car lst) (cadr lst) (caddr lst))
  5.           (packthree (cdddr lst)))) )
  6.  
  7. ;; (packthree '(1 2 0 2 3 0 4 5 0 1))
  8. ;; > ((1 2 0) (2 3 0) (4 5 0) (1 nil nil))
  9. ;; (packthree '(1 2 0 2 3 0 4 5 0))  
  10. ;; > ((1 2 0) (2 3 0) (4 5 0))
  11.  
TheSwamp.org (serving the CAD community since 2003)

Donate to TheSwamp.org

abe123456789

  • Newt
  • Posts: 22
Re: list help
« Reply #2 on: May 20, 2023, 07:25:22 AM »
Yes I would like to put all of the list into set of 3s. If there was 100 elements in a list I would like to set the list into threes

Lee Mac

  • Seagull
  • Posts: 12781
  • London, England
Re: list help
« Reply #3 on: May 20, 2023, 10:06:25 AM »
Here are a couple of generic grouping functions, depending on whether the result for a list of (0 1 2 3 4) should be ((0 1 2) (3 4 nil)) or ((0 1 2) (3 4)).

abe123456789

  • Newt
  • Posts: 22
Re: list help
« Reply #4 on: May 20, 2023, 11:45:19 AM »
That is what i am looking for.

Thank you

JohnK

  • Administrator
  • Seagull
  • Posts: 10288
Re: list help
« Reply #5 on: May 20, 2023, 12:39:01 PM »
Well, that was kind of rude. Why didnít you specify you wanted sorting/grouping, and etc and just let us guess; do you not care about other peoples time/effort?
TheSwamp.org (serving the CAD community since 2003)

Donate to TheSwamp.org

abe123456789

  • Newt
  • Posts: 22
Re: list help
« Reply #6 on: May 20, 2023, 02:47:21 PM »
Didnt mean to be rude, sorry about that. I appreciate the help. :straight:

abe123456789

  • Newt
  • Posts: 22
Re: list help
« Reply #7 on: May 20, 2023, 03:23:41 PM »
Hey Lee, I ve seen you all over the different lisp forums. Do you have any recommendations on books or other forms of knowledge to better understand autolisp?

Thank you,

BIGAL

  • Swamp Rat
  • Posts: 1230
  • 40 + years of using Autocad
Re: list help
« Reply #8 on: May 20, 2023, 08:48:33 PM »
Most people that post all the time can make suggestions about learning lisp, to many to mention.

No disrespect to Lee who is extremely good at coding.

Try Afralisp, lisp tutorials.

The Visual LISP Developers Bible.

You can get ebooks at Kindle very cheap.
A man who never made a mistake never made anything

kdub_nz

  • Mesozoic keyThumper
  • SuperMod
  • Water Moccasin
  • Posts: 1707
  • class keyThumper<T>:ILazy<T>
Re: list help
« Reply #9 on: May 21, 2023, 04:41:13 PM »
Called Kerry in my other life
Retired; but they dragged me back in !

I live at UTC + 13.00


some people complain about loading the dishwasher

Sometimes the question is more important than the answer.[/i

kdub_nz

  • Mesozoic keyThumper
  • SuperMod
  • Water Moccasin
  • Posts: 1707
  • class keyThumper<T>:ILazy<T>
Re: list help
« Reply #10 on: May 21, 2023, 07:06:29 PM »
Well, that was kind of rude. Why didnít you specify you wanted sorting/grouping, and etc and just let us guess; do you not care about other peoples time/effort?

Hi John,
Unfortunately most people don't learn the most important skill,
 . . . How to ask questions properly.

Called Kerry in my other life
Retired; but they dragged me back in !

I live at UTC + 13.00


some people complain about loading the dishwasher

Sometimes the question is more important than the answer.[/i

JohnK

  • Administrator
  • Seagull
  • Posts: 10288
Re: list help
« Reply #11 on: May 21, 2023, 10:08:53 PM »
Well, that was kind of rude. Why didnít you specify you wanted sorting/grouping, and etc and just let us guess; do you not care about other peoples time/effort?

Hi John,
Unfortunately most people don't learn the most important skill,
 . . . How to ask questions properly.

I agree. And, I completely understand when I was new to the internet I was rude too (I understand how easy it is to forget there are actual people on the other end of these screen names) but at least I owned up to the correction(s) and certainly wasn't glib when I was new.
TheSwamp.org (serving the CAD community since 2003)

Donate to TheSwamp.org