Actually, the syntax is correct. It uses a custom sort function. The function call includes the "each" which means it passes the correct parameter to the custom function, which then acts on it and sends the result back to the calling handler for sorting. It's a nice way to customize the built-in sort. You can do some pretty extravagant things with it.

On 8/31/23 10:25 AM, Bob Sneidar via use-livecode wrote:
To be more clear, the argument to “by” needs to be a chunk statement, not a 
value, followed by “of each”. Your function *might* work if you returned the 
chunk expression instead of the actual value the chunk resolves to.

But why? I am not sure what the myVal() function accomplishes. Does the chunk 
expression change on the fly? Even so, pStr needs to be a list of numbers 
because you are adding them together, so it won’t return a chunk expression.

Your method as it stands would resolve to “sort lines tVariable by 3” when it 
needs to resolve to something like “sort lines of tVariable by item 3 of each”.

Further it looks like you are sorting by multiple items. You cannot do that in 
one statement. Instead run multiple sorts, by the last element first, down to 
the first element.

Bob S


On Aug 31, 2023, at 8:06 AM, Bob Sneidar via use-livecode 
<use-livecode@lists.runrev.com> wrote:

I think you have to append “of each”. Sort lines of tVar by item 3 of each

Bob S


On Aug 30, 2023, at 9:11 PM, Neville Smythe via use-livecode 
<use-livecode@lists.runrev.com> wrote:

There is a bug in sorting a container using a function, as in

sort lines tVariable by myVal(each)

where the function is for example

function myVal pStr
   return item 1 of pStr + item 2 of pStr
end myval

If the function myVal encounters a run-time error (in the example if one of the 
items is not a number) the sort command fails silently: the script exits at 
that code line and the user is unaware that the sort (and the rest of the 
handler) were not executed.

If you sort directly with

sort lines tVariable by (item 1 of pStr + item 2 of pStr)

the handler will throw an error dialog, as expected.

QC has confirmed this is a bug ( bug 24321 
<https://quality.livecode.com/show_bug.cgi?id=24321> ) that evidently has been 
around for a long time.

Neville Smythe



_______________________________________________
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode

_______________________________________________
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode

_______________________________________________
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode

--
Jacqueline Landman Gay         |     jac...@hyperactivesw.com
HyperActive Software           |     http://www.hyperactivesw.com

_______________________________________________
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode

Reply via email to