bobsneidar at iotecdigital.com
Thu Aug 31 11:25:14 EDT 2023
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.
> On Aug 31, 2023, at 8:06 AM, Bob Sneidar via use-livecode <use-livecode at 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 at 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 at lists.runrev.com
>> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
More information about the use-livecode