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

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7228
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Slight issue with the sort command

Post by jacque » Sun Nov 19, 2017 7:50 pm

I see the confusion now. The sort does not use the word representation, if it did it could only sort up to ten. Shao Sean was joking about that. It only happened to work in this case because the first three lengths were incidentally correctly sorted by their alpha representations. It would fail in almost every other example.

Length() returns integers, and sorting numerically on those integers produces the correct result. The error was due to the English like nature of the language where our brain naturally fills in the missing pieces. As programmers we need to be careful about that.
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 8:38 pm

I don’t understand why sort by length would also require a “numeric” specifier. That’s what I think needs to be explained in the docs

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

Re: Slight issue with the sort command

Post by bogs » Sun Nov 19, 2017 9:34 pm

jacque wrote:
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.
No, the post was a jokey post based on the tangents post after that post. I pm'd it to Craig instead, the only reason I was looking for a pm from the eraser was because for the life of me, I couldn't see what was in it that was bad enough to delete it. I can't learn from it if it just up and disappears like a fart in the wind, if you see (or don't) what I mean :D
Image

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7228
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Slight issue with the sort command

Post by jacque » Sun Nov 19, 2017 10:05 pm

Mikey wrote:
Sun Nov 19, 2017 8:38 pm
I don’t understand why sort by length would also require a “numeric” specifier. That’s what I think needs to be explained in the docs
I don't undertand what you don't understand, I guess. :) Length() is a function, which could just as easily be a custom sort function that returns any data type. LC has no way of knowing how you want the order arranged unless you tell it. The default is an alpha sort, so without adding "numeric" to the sort command you will get an alpha sort:

1
10
111
...etc.

Which is what Craig got initially. I'm not sure how this would be different from any other sort command.

Edit: Imagine a list of times:

12:03
1:15
2:30
1:45

Sorting by default would sort these in alpha order. To get what you'd expect, you'd need to add "dateTime" to the sort command. "Sort lines of tList" returns alpha sorting, where "sort lines of tList dateTime" gives what you expect. Same thing, right?
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 10:34 pm

Code: Select all

sort thatList by the length of item 1 of each
I need to add “numeric” why?

That we are continuing to have this discussion is exactly why the docs need a note.

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

Re: Slight issue with the sort command

Post by bogs » Sun Nov 19, 2017 10:40 pm

I used to think I knew this stuff, but at this point I think I am leaning towards what Mikey is saying. Clarification in the docs can't hurt, but it could probably help.
Image

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9648
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Slight issue with the sort command

Post by dunbarx » Sun Nov 19, 2017 10:51 pm

Mike.

Constants are powerful and useful native elements. We could live without "comma", for example, but could not live without "quote".

So there are degrees of constant usefulness, and of their concomitant caveats in their use.

There is a counterintuitive glitch in using the constant "two, for example. This, to LC, is not a string of three chars. I have always found those particular ones to be dangerous and superfluous, and have never used any of them.

I do think it would be useful to supply an example in the dictionary showing the sorting, as I wrote above, "9,10,11" as ASCII and numeric, and what you get with either, and why.

Are the user notes still in existence? I do not see them anymore in v.8.They might be the best place to start.

Craig

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7228
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Slight issue with the sort command

Post by jacque » Sun Nov 19, 2017 11:32 pm

Mikey wrote:
Sun Nov 19, 2017 10:34 pm

Code: Select all

sort thatList by the length of item 1 of each
I need to add “numeric” why?
Because you might in fact want all the 1s together. My list of times might be Bible verses or hospital rooms. The length of a string might not actually represent a measurement but rather something else. All sorting requires a qualifier, even if it is the default.
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 » Mon Nov 20, 2017 12:35 am

I must have had a stroke. I am completely baffled by this conversation. The docs do not say you have to specify the sort type.

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9823
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Slight issue with the sort command

Post by FourthWorld » Mon Nov 20, 2017 1:57 am

Mikey wrote:
Mon Nov 20, 2017 12:35 am
The docs do not say you have to specify the sort type.
True, and you don't. The docs say:
If you don't specify a sortType, the sortType is text.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9648
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Slight issue with the sort command

Post by dunbarx » Mon Nov 20, 2017 2:46 am

We all use the term "text" somewhat loosely. The default is ASCII.

Try sorting this, plain vanilla:

Code: Select all

678
abc
@#$
Craig

EDIT:

Note that the caseSensitive will come into play if one wants to sort:
aaa
AAA
aaa
AAA
and have the ASCII 65 come before the ASCII 97.

bwmilby
Posts: 438
Joined: Wed Jun 07, 2017 5:37 am
Location: Henrico, VA
Contact:

Re: Slight issue with the sort command

Post by bwmilby » Mon Nov 20, 2017 10:50 pm

I’m not sure how/where a note would add to what is already there. Examples 2 and 3 are both numeric.

I do see a stray word after “text” as the default sortType in my copy. If in the repo I will submit a PR to correct.
Brian Milby

Script Tracker https://github.com/bwmilby/scriptTracker

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

Re: Slight issue with the sort command

Post by bogs » Mon Nov 27, 2017 6:12 am

bogs wrote:
Sun Nov 19, 2017 12:13 am
Wow, Craig, I'll send you a pm...
Heh, little did I know Craig needs to empty his inbox :mrgreen:
Image

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

Re: Slight issue with the sort command

Post by shaosean » Mon Nov 27, 2017 7:32 am

Imagine all those deals on Russian goods he is missing out on..

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9648
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Slight issue with the sort command

Post by dunbarx » Mon Nov 27, 2017 2:55 pm

Heh, little did I know Craig needs to empty his inbox
Huh? My inbox is only half full.

Craig

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”