Code:(defun f ( l ) (if l (cons (list (car l) (cadr l)) (f (cddr l)))))Generic function.Code:(defun g ( l ) (if l (cons (cons (car l) (cadr l)) (g (cddr l)))))
Registered forum members do not see this ad.
My job took me away from AutoCAD for a good while but I'm back behind a desk and I'm really rusty with my AutoLISP.
How can I take a list of numbers and put them of groups of two? For example, if my list is this:
How can I get it to look like this:Code:(1 2 3 4 5 6 7 8)
or even this:Code:(1 2)(3 4)(5 6)(7 8)
As always, any help would be appreciated.Code:(1 . 2)(3 . 4)(5 . 6)(7 . 8)
Lonnie
Code:(defun f ( l ) (if l (cons (list (car l) (cadr l)) (f (cddr l)))))Generic function.Code:(defun g ( l ) (if l (cons (cons (car l) (cadr l)) (g (cddr l)))))
Lee Mac Programming
With Mathematics there is the possibility of perfect rigour, so why settle for less?
Just another Swamper
I guess I should've known you would already have a solution. Thanks!
Lonnie
Or maybe:
-DavidCode:(defun test (l / tmp) (and (zerop (rem (length l) 2) (while (< (length l) 1) (setq tmp (cons (list (car l) (cadr l)) tmp) (setq l (cddr l)) tmp))
R12 (Dos) - A2K
Registered forum members do not see this ad.
something missing David? .. perhaps
Code:(defun test (l / tmp) (and (zerop (rem (length l) 2)) (while (> (length l) 1) (setq tmp (cons (list (car l) (cadr l)) tmp) l (cddr l)) )) (reverse tmp) )(_relist '(1 2 3 4 5 6 7 8 9 10) 1)Code:(defun _relist (l n / x ln ls) (if (zerop (rem (length l) n)) (repeat (/ (setq ln (length l)) n) ((lambda (j) (repeat j (setq x (cons (nth (setq ln (1- ln)) l) x) ))) n) (setq ls (cons x ls) x nil) )) ls)
((1) (2) (3) (4) (5) (6) (7) (8 ) (9) (10))
(_relist '(1 2 3 4 5 6 7 8 9 10) 2)
((1 2) (3 4) (5 6) (7 8 ) (9 10))
(_relist '(1 2 3 4 5 6 7 8 9 10) 3)
nil
(_relist '(1 2 3 4 5 6 7 8 9 10) 4)
nil
(_relist '(1 2 3 4 5 6 7 8 9 10) 5)
((1 2 3 4 5) (6 7 8 9 10))
Bookmarks