Firstly, why is the function last not an accessor? I would, for
example, like to change the end of a list by doing
(setf (rest (last some-list)) new-ending)
but this is not possible, I must use
(setf some-list (nconc some-list new-ending))
Secondly, why are the functions notany and notevery _not_ deprecated?
In the 'deprecation spree' of X3J13 vote TEST-NOT-IF-NOT:FLUSH-ALL many
functions such as
(remove-if-not ...) were deprecated because they could be written as
(remove-if (complement ...) ...)
This is also the case with notany and notevery, so why were they not
deprecated? I think they should be, the are superfluous, and removing
them will reduce the size of CLtS.
Thanks in advance.
-- SRS
Sent via Deja.com
http://www.deja.com/
> I have two (unrelated) questions, but I thout I would submit them in
> one post.
>
> Firstly, why is the function last not an accessor? I would, for
> example, like to change the end of a list by doing
> (setf (rest (last some-list)) new-ending)
> but this is not possible, I must use
> (setf some-list (nconc some-list new-ending))
>
I think this works. It's not an issue of whether LAST has a SETF
method, actually, it's an issue of whether REST has, and it does.
> Secondly, why are the functions notany and notevery _not_ deprecated?
> In the 'deprecation spree' of X3J13 vote TEST-NOT-IF-NOT:FLUSH-ALL many
> functions such as
> (remove-if-not ...) were deprecated because they could be written as
> (remove-if (complement ...) ...)
> This is also the case with notany and notevery, so why were they not
> deprecated? I think they should be, the are superfluous, and removing
> them will reduce the size of CLtS.
>
I think this is academic because no one seems to want remove-if-not
and so on to go away any more.
--tim
> I think this works. It's not an issue of whether LAST has a SETF
> method, actually, it's an issue of whether REST has, and it does.
>
Incidentally, here's why it isn't about LAST:
(defun my-rest (l)
(cdr l))
(defun (setf my-rest) (new l)
(rplacd l new)
new)
--tim
Because (setf (last x n)) == (setf (cdr (last x (1+ n)))) in the specific
case where you can modify the cdr of the cons pointing to the last cons
because (last x n) is different from (last x (1+ n)). When they return
the same value, you have a problem.
Besides, you aren't asking for last, but rest or cdr and both of those
are certainly accessors in the language. Maybe they aren't in your
implementation, but if so, that's a reportable non-conformance bug.
#:Erik
--
The United States of America, soon a Bush league world power. Yeee-haw!
Sorry, you are right. What I meant to say is that something similar to
the following code does not work. Why doesn't it?
(setf (last some-list) new-ending)
>> > Firstly, why is the function last not an accessor? I would, for
>> > example, like to change the end of a list by doing
>> > (setf (rest (last some-list)) new-ending)
>> > but this is not possible, I must use
>> > (setf some-list (nconc some-list new-ending))
>> >
>>
>> I think this works. It's not an issue of whether LAST has a SETF
>> method, actually, it's an issue of whether REST has, and it does.
Some time ago I asked similar question and considered
using some pretty cool expression for pushing of 1 element
to the end of list
(defun push-end(list last)
(rplacd (last list) (list last)))
Unfortunately, it doesn't work on an empty list.
>
>Sorry, you are right. What I meant to say is that something similar to
>the following code does not work. Why doesn't it?
> (setf (last some-list) new-ending)
Really don't know. But you may use last but one element since
cdr of cons is accessor. Next expression works
only when (list-length some-list) > 1
(rplacd (last 2 some-list) new-ending)