[LISP] Simplify the code

[LISP] Simplify the code

iBlachu
Advocate Advocate
1,272 Views
21 Replies
Message 1 of 22

[LISP] Simplify the code

iBlachu
Advocate
Advocate

Hi,

 

Who can help me simplify the code below, the one that is between the START and END tags.

 

(setq L
	(list
		(list 0 1 2)
		(list 0 1 2)
		(list 0 1 2)
		(list 0 1 2)
	)
)

(setq e 2)
(setq L1 nil)
(foreach
	x
	L
	; START
	(setq t nil)
	(setq i 0)
	(while (< i (length x))
		(if (not (equal i e))
			(setq t (reverse (cons (nth i x) (reverse t))))
		)
		(setq i (1+ i))
	)
	(setq L1 (reverse (cons t (reverse L1))))
	; END
)

(princ L1)
(princ)

 

0 Likes
1,273 Views
21 Replies
Replies (21)
Message 21 of 22

ronjonp
Mentor
Mentor

Well since Linda is out of the picture lets keep Donna around 😁

(defun _removenth (l n / i)
  (setq i -1)
  (vl-remove 'nil
	     (mapcar '(lambda (x)
			(if (/= n (setq i (1+ i)))
			  x
			)
		      )
		     l
	     )
  )
)
(_removenth '(0 1 2 "Linda" "Donna"  3 4 5 6 7 8 9 10 10 10 11) 3)
;; (0 1 2 "Donna" 3 4 5 6 7 8 9 10 10 10 11) 
0 Likes
Message 22 of 22

john.uhden
Mentor
Mentor
@ronjonp
THAT's what I wanted to see. Very nice!
Poor Linda. She married a guy named Bob whom I never did like.

John F. Uhden

0 Likes