Sort bug
Brian Milby
brian at milby7.com
Thu Aug 31 21:29:17 EDT 2023
I just tried this in 10dp5 and the sort didn’t completely bail (it put the error value first) but it did error when including inline (as in the bug report). If I add a try, then it will stop on the throw. Not sure how much this would slow down execution though.
function myVal pStr
local tResult
try
put item 1 of pStr + item 2 of pStr into tResult
catch errorVariable
throw "Bad data"
end try
return tResult
end myVal
Brian Milby
brian at milby7.com
> On Aug 31, 2023, at 7:53 PM, Alex Tweedly via use-livecode <use-livecode at lists.runrev.com> wrote:
>
>
>> On 01/09/2023 00:37, Bob Sneidar via use-livecode wrote:
>> The function is adding the value of two chunks together and returning the result. How does that even compute? Unless the + operator is doing something totally different here…
>
> The code said:
>
>> 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
> since it's sorting the lines of the container, it calls the custom function with each line in turn. The function simply adds together the first two items from the passed-in line, and returns that. The returned value is associated with the corresponding line - and then the container is sorted by those associated values.
>
> This works fine if the input variable is well formatted (i.e. first and second items of each line are numeric), but fails to give an error when something goes wrong - such as a non-numeric item.
>
> (and, yes - the dictionary description is misleading, if not simply incorrect. However, the "Tip" at the end describes the use of ustom functions).
>
> Alex.
>
>
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
More information about the use-livecode
mailing list