From: hoeflin ( Bjoern Hoefling )

Subject: destructive nature of sort

Date: 1997-7-7 9:00

Some remarks to the reply of Erik Naggum concerning the destructive nature
of sort:

> this is indeed a strange way to think. just because the side effect is > different from your expectations, doesn't mean you can doubt the return > value. Lisp functions are usually defined in terms of their return values, > and not in terms of their side effects. (other languages have other ways.)
There are many Lisp-Functions which are only used because of their side-effects and for which sometimes even the return-value is left open to the Lisp-implementation (many I/O functions, but also destructive operations). Apparently there are two kinds of destructive operations: 1) those, where the destructive side-effects are well defined and reliable for the user (example: nconc) 2) those, where the destructive modification is only allowed (for example for efficiency reasons) but left open to the Lisp-Implementation and in this case the user cannot be sure about what is really happening My 'strange way to think' might be that I thought that sort is of type 1 and not 2. The description of sort in CLTL2 is not very clear for me with respect to this question but apparently sort is considered to be of type 2.
> note that `sort' is unable to know where to store the return value, and > that if `sort' is called on a list, there is no way to store a pointer to > the first element. if `sort' is called on a vector, it will obviously be > able to return its value by side effect to the vector, but that is an > accident.
Then why do other Lisp-Dialects (unfortunately I was only able to test it with CLISP) don't have problems with my small example? Perhaps there are other members of the mailing-list who are able to test it on other Lisp-dialects. Bjoern ******************************************************************************* Dipl.-Inform. Bj"orn H"ofling * Otto-von-Guericke Universit"at Magdeburg Phone: +49 391 67 18055 * FIN/IIK Fax: +49 391 67 12018 * Universit"atsplatz 2 * D - 39106 Magdeburg (Germany) ******************************************************************************* E-mail: <iik.cs.uni-magdeburg.de at hoefling> WWW: http://www-ai.cs.uni-magdeburg.de/~hoefling *******************************************************************************