Because sort is destructive, only the return value is guaranteed to be
sorted. So, as you mentioned you should use setq with the return value.
What is descructive?? :)
- From CLHS(Common Lisp Hyper Spec)
destructive adj. (of an operator) capable of modifying some
program-visible aspect of one or more objects that are either explicit
arguments to the operator or that can be obtained directly or
indirectly from the global environment by the operator.
Hope this helps,
- jwchoi
<hp827.cs.Uni-Magdeburg.DE at hoefling> ( Bjoern Hoefling ) writes:
> Hello everybody,
>
> I have traced down a problem in a big part of code to the following
> strange behaviour of sort:
>
> Allegro CL 4.3 [SPARC; R1] (4/5/96 19:24)
> Copyright (C) 1985-1996, Franz Inc., Berkeley, CA, USA. All Rights Reserved.
> ; Loading /usr/local/acl4.3/home/code/ipc.cl
> ;; Optimization settings: safety 1, space 1, speed 1, debug 2.
> ;; For a complete description of all compiler switches given the
> ;; current optimization settings evaluate (EXPLAIN-COMPILER-SETTINGS).
> USER(1): (setf ll '("a" "f" "d" "c"))
> ("a" "f" "d" "c")
> USER(2): (sort ll #'string<)
> ("a" "c" "d" "f")
> USER(3): ll
> ("a" "c" "d" "f")
> USER(4): (setf ll (cons "b" ll))
> ("b" "a" "c" "d" "f")
> USER(5): (sort ll #'string<)
> ("a" "b" "c" "d" "f")
> USER(6): ll
> ("b" "c" "d" "f")
>
> Certainly this might be encompassed by always doing an explicit setf after
> sorting. But with this strange effect I would like to know whether the
> return value of sort is guaranteed to be correct.
>
> Greetings
> 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
> *******************************************************************************
>