Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

deleting a nth element of a list

1,550 views
Skip to first unread message

Arseny Slobodjuck

unread,
May 25, 2000, 3:00:00 AM5/25/00
to

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

Erik Naggum

unread,
May 25, 2000, 3:00:00 AM5/25/00
to
* 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))))

#:Erik
--
If this is not what you expected, please alter your expectations.

Francis Leboutte

unread,
May 25, 2000, 3:00:00 AM5/25/00
to
Erik Naggum <er...@naggum.no> wrote:

>* 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

Markus B. Krüger

unread,
Jun 8, 2000, 3:00:00 AM6/8/00
to
Erik Naggum <er...@naggum.no> writes:

> * 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/ '
)-------------------------------------------------------------------(

0 new messages