Slight issue with the sort command

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10328
Joined: Wed May 06, 2009 2:28 pm

Slight issue with the sort command

Post by dunbarx » Sat Nov 18, 2017 6:54 am

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.

shaosean
Posts: 906
Joined: Thu Nov 04, 2010 7:53 am

Re: Slight issue with the sort command

Post by shaosean » Sat Nov 18, 2017 9:53 am

Well.. AARDWOLVES is 10 characters, the others are 2 and 3, so Ten, Two and Three, you can see that it is sorting properly ;-)

Code: Select all

Ten
Three
Two
hehe.. sorry, couldn't help it :D

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10328
Joined: Wed May 06, 2009 2:28 pm

Re: Slight issue with the sort command

Post by dunbarx » Sat Nov 18, 2017 4:45 pm

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

shaosean
Posts: 906
Joined: Thu Nov 04, 2010 7:53 am

Re: Slight issue with the sort command

Post by shaosean » Sat Nov 18, 2017 5:18 pm

Wait?!? Are you seriously telling me I was right?!!???

bogs
Posts: 5480
Joined: Sat Feb 25, 2017 10:45 pm

Re: Slight issue with the sort command

Post by bogs » Sat Nov 18, 2017 8:58 pm

<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
Image
Image

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10328
Joined: Wed May 06, 2009 2:28 pm

Re: Slight issue with the sort command

Post by dunbarx » Sat Nov 18, 2017 10:55 pm

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

bogs
Posts: 5480
Joined: Sat Feb 25, 2017 10:45 pm

Re: Slight issue with the sort command

Post by bogs » Sun Nov 19, 2017 12:13 am

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 :?
Image

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10328
Joined: Wed May 06, 2009 2:28 pm

Re: Slight issue with the sort command

Post by dunbarx » Sun Nov 19, 2017 5:20 am

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

bogs
Posts: 5480
Joined: Sat Feb 25, 2017 10:45 pm

Re: Slight issue with the sort command

Post by bogs » Sun Nov 19, 2017 12:55 pm

Oh, heh, I didn't think you had erased it my friend :D
Image

Mikey
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 755
Joined: Fri Jun 27, 2008 9:00 pm

Re: Slight issue with the sort command

Post by Mikey » Sun Nov 19, 2017 3:30 pm

Not following, please explain for we simpletons
And then add a note to the docs

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7393
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: Slight issue with the sort command

Post by jacque » Sun Nov 19, 2017 4:36 pm

bogs wrote:
Sun Nov 19, 2017 12:55 pm
Oh, heh, I didn't think you had erased it my friend :D
If the post is the one about filtering out IDE stacks, it's there.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7393
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: Slight issue with the sort command

Post by jacque » Sun Nov 19, 2017 4:53 pm

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.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Mikey
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 755
Joined: Fri Jun 27, 2008 9:00 pm

Re: Slight issue with the sort command

Post by Mikey » Sun Nov 19, 2017 5:54 pm

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.

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7393
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: Slight issue with the sort command

Post by jacque » Sun Nov 19, 2017 6:31 pm

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?
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Mikey
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 755
Joined: Fri Jun 27, 2008 9:00 pm

Re: Slight issue with the sort command

Post by Mikey » Sun Nov 19, 2017 7:21 pm

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.

Post Reply