@Browning_Zed wrote:
Could you give a description of the "take" function? Yes, you always refer to this function, but if I don't understand how it works and what it does, then how can I use it
(defun take (amount lst / ret)(repeat amount (setq ret (cons (car lst) (take (1- amount) (cdr lst))))))
It takes some number of list elements (amount)from the start of list
Command: (take 2 '(1 2 3 4))
(1 2)
Command: (take 3 '(1 2 3 4))
(1 2 3)
You can utilize this function to create list of 2 element lists (2d poly i.e lwpoyline points) or list pf 3 elements (3d poly) .
(defun pointlist2d (lst / ret) (while lst (setq ret (cons (take 2 lst) ret) lst (cddr lst))) (reverse ret))
Loop as long list exist, take 2 entities from he list and remove first two elements from original list (cddr lst).
(defun pointlist3d (lst / ret) (while lst (setq ret (cons (take 3 lst) ret) lst (cdddr lst))) (reverse ret))
Loop as long list exist, take 3 entities from he list and remove first three elements from original list (cddr lst).
To join list of list you can use apply function and append over the list.
Command: (setq lst (pointlist2d '(1 2 3 4 5 6)))
((1 2) (3 4) (5 6))
Command: (setq lst (apply 'append lst))
(1 2 3 4 5 6)
To switch order of list elements use function reverse.
Command: (reverse lst)
(6 5 4 3 2 1)
P.S. If you need explanation about how some function work, just ask.
Same as you my first 30-50 posts to this forum were just requests. After that I started solving some simple tasks, than more complex one..... Once you learn how to use lisp then "only sky is the limit".
Today at work I was repairing a survey map that was created all wrong. For every step of repair I have created my simple function or used something from my lisp base and after some 2h result was top notch. Usually it would take two to three days when contractors surveyor would repair all the flaws and many times result was not good.
Miljenko Hatlak

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.