With 9.6.9 on a mac and a field where the second and third items of each line are numbers:
sort lines of fld 1 numeric by item 2 of each + item 3 of each -- works sort lines of fld 1 numeric by value(item 2 of each + item 3 of each) -- works sort lines of fld 1 numeric by merge("[[item 2 of each + item 3 of each]]") -- works and on mouseUp sort lines of fld 1 numeric by sortVal(each) end mouseUp function sortVal S return item 2 of S + item 3 of S end sortVal works. I haven't checked, but I'd guess that performance degrades with each further method. They all work if one or both of the items are empty. If there is an entry that has a non-numeric value in item 2 or 3: sort lines of fld 1 numeric by item 2 of each + item 3 of each -- partially sorts and throws an error sort lines of fld 1 numeric by value(item 2 of each + item 3 of each) -- partially sorts and throws an error sort lines of fld 1 numeric by merge("[[item 2 of each + item 3 of each]]") -- surprisingly, works -- error lines are seemingly sorted with a value of negative infinity? And the function sort also sorts based on a negative infinity value for errors. I'm not sure I'd consider that a bug. And this works: sort lines of fld 1 numeric by merge("<?if item 2 of each is not a number or item 3 of each is not a number then return 0 else return item 2 of each + item 3 of each?>") And of course sorting by this function does the same thing: function sortVal S if item 2 of S is not a number or item 3 of S is not a number then return 0 return item 2 of S + item 3 of S end sortVal On Thu, Aug 31, 2023 at 9:30 PM Brian Milby via use-livecode < use-livecode@lists.runrev.com> wrote: > 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 > br...@milby7.com > > > On Aug 31, 2023, at 7:53 PM, Alex Tweedly via use-livecode < > use-livecode@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@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