help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: replacing a certain element in a list with another


From: Barry Margolin
Subject: Re: replacing a certain element in a list with another
Date: Thu, 23 Oct 2003 22:20:34 GMT

In article <m33cdj8vdf.fsf@tfkp07.physik.uni-erlangen.de>,
Roland Winkler  <Roland.Winkler@physik.uni-erlangen.de> wrote:
>The info page for nreverse gives an example for the results obtained
>by the present implementation of nreverse where the argument is
>converted into a 1-element list containing the last element of the
>reversed list. I find this example rather confusing because it is
>given wihtout further explanation which rules nreverse is obeying
>when it modifies its argument destructively. However, if I
>understand you correctly it does not even make sense to ask which
>rules nreverse is using here because they depend on the
>implementation of nreverse. It is nothing one could rely upon.
>
>If indeed we are talking here about something that is
>implementation-dependent, it would be better to replace this example
>with a sentence saying that nreverse "destroys" its argument in an
>implementation-dependent way such that only the return value is a
>well-defined object. Then I would know that it doesn't make sense to
>ask the question whether the argument of nreverse may be used for
>anything else after it was passed to nreverse.
>
>Or am I missing something here?

The idea of Emacs documentation describing something as
"implementation-dependent" is kind of weird.  Emacs Lisp is not a general
purpose language with multiple implementations, it's a part of Emacs.  So
the documentation is describing just this one implementation.

I don't have the Emacs Lisp info pages online, but the built-in
documentation says:

   Reverse LIST by modifying cdr pointers.
   Returns the beginning of the reversed list.

This is terse, but it pretty much describes what I explained in detail a
few messages back.

The fact that any references to the old list will now refer specifically to
the last cons in the new list is a natural result of this; you just need to
understand how lists are built out of cons cells.  But this specific result
is not considered important -- no one ever writes a program that depends
specifically on what the old references point to.

The verbose documentation of all the destructive list operations should
mention that you must use the value to get the expected results all the
time, rather than depending on everything to work due to the lists being
modified in place.

-- 
Barry Margolin, barry.margolin@level3.com
Level(3), Woburn, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]