Slight issue with the sort command
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
-
- 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
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.
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
HyperActive Software | http://www.hyperactivesw.com
Re: Slight issue with the sort command
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
Re: Slight issue with the sort command
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
-
- 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
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
HyperActive Software | http://www.hyperactivesw.com
Re: Slight issue with the sort command
Code: Select all
sort thatList by the length of item 1 of each
That we are continuing to have this discussion is exactly why the docs need a note.
Re: Slight issue with the sort command
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.
-
- 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
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
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
-
- 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
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.Mikey wrote: ↑Sun Nov 19, 2017 10:34 pmI need to add “numeric” why?Code: Select all
sort thatList by the length of item 1 of each
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
Re: Slight issue with the sort command
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.
-
- 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
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
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
-
- 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
We all use the term "text" somewhat loosely. The default is ASCII.
Try sorting this, plain vanilla:
Craig
EDIT:
Note that the caseSensitive will come into play if one wants to sort:
Try sorting this, plain vanilla:
Code: Select all
678
abc
@#$
EDIT:
Note that the caseSensitive will come into play if one wants to sort:
and have the ASCII 65 come before the ASCII 97.aaa
AAA
aaa
AAA
Re: Slight issue with the sort command
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.
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
Script Tracker https://github.com/bwmilby/scriptTracker
Re: Slight issue with the sort command
Imagine all those deals on Russian goods he is missing out on..
-
- 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
Huh? My inbox is only half full.Heh, little did I know Craig needs to empty his inbox
Craig