# Unexpected behaviour from (sort) with transient-sym-with-leading-numeral-in-cdr

```I have a perplexing situation with the (sort) function sorting
alphanumeric elements, and can't find any explanation in the
documentation after searching for a while. Unless I am
misunderstanding some painfully fundamental point, this appears to be
a bug.```
```
When I try to sort alphanumeric transient-syms it seems that the
(sort) function bails out early as soon as it hits an element from the
CDR with leading numeral (I guess it is internally attempting to
transform each transient-sym to an internal-sym as it iterates through
the CDR, which won't work for e.g. "3a"), and then it seems to quietly
return one of the halved partitions being internally constructed by
the mergesort algorithm rather than erroring out loudly. I would
expect that:

* sorting alphanumerically would be possible (leading numbers before
letters), as e.g. (< "3a" "a") and (< "a" "3a") in isolation both work
as expected
* if it is going to fail it should make it clear that it is failing
rather than "successfully" presenting an incorrect (and initially
baffling) result

The same happens whether assigning A inside (let) or assigning A
beforehand with (set). I am using 64bit (assembler) picolisp v16.7.17
(Debian package). Please let me know if you need more information (or
if I'm an idiot and just didn't understand something). Example
fail-scenarios are below:

> # -- "sort"
> : (let (A '("t" "z" "q" "a" "3a" "x3" "3")) (println A) (sort A) (println A))
> ("t" "z" "q" "a" "3a" "x3" "3")
> ("t" "x3" "z")
> -> ("t" "x3" "z")

> # -- "sort <" [same as above, with implicit < sort-function]
> : (let (A '("t" "z" "q" "a" "3a" "x3" "3")) (println A) (sort A <) (println
> A))
> ("t" "z" "q" "a" "3a" "x3" "3")
> ("t" "x3" "z")
> -> ("t" "x3" "z")

> # -- "sort >"
> : (let (A '("t" "z" "q" "a" "3a" "x3" "3")) (println A) (sort A >) (println
> A))
> ("t" "z" "q" "a" "3a" "x3" "3")
> ("t" "q" "a" "3a" "3")
> -> ("t" "q" "a" "3a" "3")

> # -- "sort with CAR-with-leading-numeral"
> : (let (A '("4b" "t" "z" "q" "a" "3a" "x3" "3")) (println A) (sort A)
> (println A))
> ("4b" "t" "z" "q" "a" "3a" "x3" "3")
> ("4b" "a" "q" "t" "x3" "z")
> -> ("4b" "a" "q" "t" "x3" "z")

> # -- "sort > with CAR-with-leading-numeral"
> : (let (A '("4b" "t" "z" "q" "a" "3a" "x3" "3")) (println A) (sort A >)
> (println A))
> ("4b" "t" "z" "q" "a" "3a" "x3" "3")
> ("4b" "3a" "3")
> -> ("4b" "3a" "3")

> # -- "sort quoted list" [doesn't do anything at all]
> : (let (A '("t" "z" "q" "a" "3a" "x3" "3")) (println A) (sort 'A) (println A))
> ("t" "z" "q" "a" "3a" "x3" "3")
> ("t" "z" "q" "a" "3a" "x3" "3")
> -> ("t" "z" "q" "a" "3a" "x3" "3")

--
Rowan Thorpe
PGP fingerprint:
BB0A 0787 C0EE BDD8 7F97  3D30 49F2 13A5 265D CCBD
----
"A riot is the language of the unheard." - Dr. Martin Luther King
"There is a great difference between worry and concern. A
worried person sees a problem, and a concerned person solves a
problem." - Harold Stephens
"Ignorance requires no apologies when it presents questions
rather than assertions." - Michael Sierchio (OpenSSL mailing list)
"What we need more than an end to wars is an end to the
beginning of all wars." - Franklin Roosevelt
--
UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe
```