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

Two Questions

3 views
Skip to first unread message

SRS

unread,
Dec 16, 2000, 8:24:28 AM12/16/00
to
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))

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/

Tim Bradshaw

unread,
Dec 16, 2000, 8:46:22 AM12/16/00
to
SRS <sr...@my-deja.com> writes:

> 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

Tim Bradshaw

unread,
Dec 16, 2000, 8:50:31 AM12/16/00
to
Tim Bradshaw <t...@tfeb.org> writes:

> 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

Erik Naggum

unread,
Dec 16, 2000, 10:11:01 AM12/16/00
to
* SRS <sr...@my-deja.com>

| Firstly, why is the function last not an accessor?

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!

SRS

unread,
Dec 16, 2000, 12:22:20 PM12/16/00
to
In article <nkjzohw...@tfeb.org>,

Tim Bradshaw <t...@tfeb.org> wrote:
> SRS <sr...@my-deja.com> writes:
>
> > 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.
>

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)

Arseny Slobodjuck

unread,
Dec 16, 2000, 10:38:03 PM12/16/00
to
On Sat, 16 Dec 2000 17:22:20 GMT, SRS <sr...@my-deja.com> wrote:

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


0 new messages