Which is the best way to delete some element, whose number is known
from a list ? Is it the following ?
(delete-if (lambda (x) t) some-list :start i :count 1)
thanks
Clever solution, but I tend to think that plain old ordinary list
hacking is simpler:
(defun delete-nth (n list)
(if (zerop n)
(cdr list)
(let ((cons (nthcdr (1- n) list)))
(if cons
(setf (cdr cons) (cddr cons))
cons))))
#:Erik
--
If this is not what you expected, please alter your expectations.
>* Arseny Slobodjuck
>| Which is the best way to delete some element, whose number is known
>| from a list? Is it the following?
>
> Clever solution, but I tend to think that plain old ordinary list
> hacking is simpler:
>
>(defun delete-nth (n list)
> (if (zerop n)
> (cdr list)
> (let ((cons (nthcdr (1- n) list)))
> (if cons
> (setf (cdr cons) (cddr cons))
> cons))))
Would prefer this :
(defun delete-position (n list)
(if (zerop n)
(cdr list)
(let ((cons (nthcdr (1- n) list)))
(when cons
(setf (cdr cons) (cddr cons)))
list)))
>#:Erik
--
Francis Leboutte
f...@algo.be www.algo.be +32-(0)4.388.39.19
> * Arseny Slobodjuck
> | Which is the best way to delete some element, whose number is known
> | from a list? Is it the following?
>
> Clever solution, but I tend to think that plain old ordinary list
> hacking is simpler:
However, the delete-if solution would work for any sequence, not just
lists.
--
'------------------- Markus Bjartveit Krüger ---------------------`
' `
` E-mail: mar...@pvv.org WWW: http://www.pvv.org/~markusk/ '
)-------------------------------------------------------------------(