Page 1 of 3
Slight issue with the sort command
Posted: Sat Nov 18, 2017 6:54 am
by dunbarx
By "slight", I mean I am going to start crying shortly.
Consider the following list:
AAH,AAH
AAL,AAL
AAS,AAS
AA,AA
AARDWOLVES,AADELORSVW
AB,AB
AA,AA
AB,AB
If I:
sort thatList by the length of item 1 of each
The string "AARDWOLVES,AADELORSVW" comes out on top.
Oh, and if i sort descending, that string comes out on the bottom.
Oh and if I lose that string, everything else in the list sorts just fine. I cannot wait to hear what I am missing.
Sob.
Craig Newman
EDIT:
Just to make sure I am not missing some strange aspect of what I thought was the definition of "length", I tried the following list:
aaaa
aaaaaa
aaaaaaaa
aaaaaaaaaa
aaaaaaaaaaaaa
aaaaaaaaaaaaaaaa
Go on, sort that by the length of each.
Sob.
Re: Slight issue with the sort command
Posted: Sat Nov 18, 2017 9:53 am
by shaosean
Well.. AARDWOLVES is 10 characters, the others are 2 and 3, so Ten, Two and Three, you can see that it is sorting properly
hehe.. sorry, couldn't help it

Re: Slight issue with the sort command
Posted: Sat Nov 18, 2017 4:45 pm
by dunbarx
I feel like an idiot. Of course if the sortKey is not numeric...
I have actually helped others with this very issue over the years.
It was late. I was in a hurry. I was....
Sob.
Craig
Re: Slight issue with the sort command
Posted: Sat Nov 18, 2017 5:18 pm
by shaosean
Wait?!? Are you seriously telling me I was right?!!???
Re: Slight issue with the sort command
Posted: Sat Nov 18, 2017 8:58 pm
by bogs
<Passes Craig a hanky...>
Buck up, little camper, we've all been there.
This morning, I was working on a mockup of the old Hypercard IDE, I was working on the field that lists the stacks. I wanted it to list only the stacks made by the person using it.
Simple enough, thinks I, I'll just use [if / then] to determine if it is a mainStack or subStack, filter out IDE stacks, use a repeat loop, etc.
Well, I was at it for about 6 hours today, when I finally arrived at this...
Code: Select all
put the openStacks into field "stksInMem"
filter field "stksInMem" without regex pattern "rev*"
There are a few assorted bits left to filter, like home and message box and the like. I was looking through the code of the
project browser at one point, I got so desperate.
So give yourself a clap on the back, you persevered and triumphed in the end, and that is nothing to cry about

Re: Slight issue with the sort command
Posted: Sat Nov 18, 2017 10:55 pm
by dunbarx
Yes, of course your were right (at least I think so).
I should have, knew I should have, forgot I should have (take your pick):
sort myList numeric by the length of item 1 of each
I have known this forever. I just don't know it all the time
But isn't that what you meant? The length of a string, used as a sortKey as I did (as LC resolves it) falls into the same newbie question why "9,10,11" seems to sort incorrectly if you sort it as text.
If one is thinking clearly, one must sort numeric.
Bogs does go off on tangents, doesn't he?
Craig
Re: Slight issue with the sort command
Posted: Sun Nov 19, 2017 12:13 am
by bogs
Wow, Craig, I'll send you a pm, as apparently my last post offended someone who erased it. If the eraser could send me a pm explaining why, I'd sure appreciate it

Re: Slight issue with the sort command
Posted: Sun Nov 19, 2017 5:20 am
by dunbarx
Huh?
Bogs, the only ones who would, or could delete a post are all quite aware of both who you are and your style. Are you sure it was actually deleted? That is actually posted?
Craig
Re: Slight issue with the sort command
Posted: Sun Nov 19, 2017 12:55 pm
by bogs
Oh, heh, I didn't think you had erased it my friend

Re: Slight issue with the sort command
Posted: Sun Nov 19, 2017 3:30 pm
by Mikey
Not following, please explain for we simpletons
And then add a note to the docs
Re: Slight issue with the sort command
Posted: Sun Nov 19, 2017 4:36 pm
by jacque
bogs wrote: ↑Sun Nov 19, 2017 12:55 pm
Oh, heh, I didn't think you had erased it my friend
If the post is the one about filtering out IDE stacks, it's there.
Re: Slight issue with the sort command
Posted: Sun Nov 19, 2017 4:53 pm
by jacque
Mikey wrote: ↑Sun Nov 19, 2017 3:30 pm
Not following, please explain for we simpletons
And then add a note to the docs
It was just a thinko. Sorting a text list by the length of an item requires a numeric sort rather than a text sort because length is an integer. I don't think it needs a dictionary note, but we could require Craig to write "I will get more sleep" 100 times on the blackboard.
Re: Slight issue with the sort command
Posted: Sun Nov 19, 2017 5:54 pm
by Mikey
I think it definitely needs a dictionary note. I never would have thought that behavior would be normal. That seems completely counterintuitive, and would burn me. That is one of those things I would immediately change if I ever got a controlling interest in LC.
Re: Slight issue with the sort command
Posted: Sun Nov 19, 2017 6:31 pm
by jacque
If you had a list of numbers instead of alpha characters, would you need a dictionary note that you may want to sort numeric sometimes?
Re: Slight issue with the sort command
Posted: Sun Nov 19, 2017 7:21 pm
by Mikey
Yes, that's a good reminder, because the datatype of a container and of a chunk of a container in LC is implicit to the operation, not to the contents. In the case of sorting a list by some property, in this case the length of each line, I think the intent is clear. If the sort is indeed using the word representation of a numeral ("one", "two", "three"), then that is so counterintuitive as to require bold and underline and italics in the note, and a bug report and deprecation.