TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: abe123456789 on May 19, 2023, 09:58:33 PM

Title: list help
Post by: abe123456789 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
Title: Re: list help
Post by: JohnK 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.  
Title: Re: list help
Post by: abe123456789 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
Title: Re: list help
Post by: Lee Mac on May 20, 2023, 10:06:25 AM
Here (http://lee-mac.com/groupbynum.html) 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)).
Title: Re: list help
Post by: abe123456789 on May 20, 2023, 11:45:19 AM
That is what i am looking for.

Thank you
Title: Re: list help
Post by: JohnK 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?
Title: Re: list help
Post by: abe123456789 on May 20, 2023, 02:47:21 PM
Didnt mean to be rude, sorry about that. I appreciate the help. :straight:
Title: Re: list help
Post by: abe123456789 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,
Title: Re: list help
Post by: BIGAL 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.
Title: Re: list help
Post by: kdub_nz on May 21, 2023, 04:41:13 PM
Also:
https://help.autodesk.com/view/OARX/2023/ENU/


Title: Re: list help
Post by: kdub_nz 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.

Title: Re: list help
Post by: JohnK 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.