Re: sort bug

2023-09-06 Thread Geoff Canyon via use-livecode
From the original email:

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.


To be clear: the above is NOT what I'm seeing. Mark W says in the bug
report:

The 'sort ... by ...' command has always allowed the by expression to be
fault tolerant - if evaluating it generates a runtime error then the sort
key for that element is just taken to be the original element.

And that is what I'm seeing. For example, this code does not exit -- it
displays the answer dialog as if nothing out of the ordinary has happened:

on mouseUp
   sort lines of fld 1 numeric by sortVal(each)
   answer "done"
end mouseUp

function sortVal S
   return item 2 of S + item 3 of S
end sortVal

It seems to be sorting as Mark described: when the function fails, the
whole line is used for the sort. And that "fallback to the whole value
needs better documentation, and could lead to some truly dismal debugging
situations, but it doesn't seem like a bug to me.

The original report, if I were able to replicate it, would clearly be a bug.

On Sat, Sep 2, 2023 at 8:19 PM neville smythe via use-livecode <
use-livecode@lists.runrev.com> wrote:

> Geoff Canyon wrote (after a bravura  display of how many different
> ways there are to do things in LC!) :
>
> And the function sort also sorts based on a negative infinity value
> for
>
> errors. I'm not sure I'd consider that a bug.
>
> Hmm. I would. The sortKey function should tolerate any sort of
> run-time error? But anyway that's not the issue. The bug I see is that
> the sort command exits its containing handler - actually I presume the
> sortKey function exits to top - without throwing an error, so nothing
>  beyond that line is executed. This creates a very difficult problem
> to track down, since the code appears to be executing correctly, until
> something falls over or a file gets corrupted much later because some
> stuff never happened.
>
> Of course one should always validate data, particularly if it's not
> your own data. In this case it was my own data! Moreover I had thought
> I had checked for invalid cases, just hadn't checked all possible
> kinds of invalid data (the sortKey was rather more complicated than
> the one I used for illustration).
>
> Neville
>
> -
> Email sent using Optus Webmail
> ___
> 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


Re: Sort bug and also multilevel sorting

2023-09-06 Thread Neville Smythe via use-livecode
Ralph: Interesting. Your code works as you present it, sorting the given items 
by the sortkey function f1 which adds 1 to each item. I do get the “sorting 
failed” dialog.

But if I try the same thing using myVal modified as you suggest, which adds the 
first and second items of each line of data and then adds 1 to the global s1, I 
get the bug I reported: the handler simply exits without showing either the 
“sorting failed” or the “Done” answer dialog.

I would have thought the two methods would generate the same error code, an 
incorrect operand in a sum, so this is strange! The function definitely returns 
on the error line, the value of s1 is not changed in the next line in either 
your f1 or my myVal. So perhaps the bug occurs when the processing returns to 
the sort code. Not something we can solve here, one for the engineers to sort 
out (!)

Mark Waddingham says the sortKey function is intended to be tolerant of errors, 
simply returning the original value of ‘each’ - in your case each item, in my 
case each line. So it should either 

1. Continue with the (undocumented) sort order  OR 

2a. exit to top AND 2b. drop into the debugger/errorDialog. In my example it is 
doing  2a but not 2b.

Craig: The missing bit is that your method won’t work if the integers you are 
sorting by having different string lengths

The lines
2,7
1,99

should, when sorted by numeric ascending (item 1 of each, item 2 of each) - 
which would be the appropriate syntax for a multilevel sort tho not in LC - 
result in
1.99
2,7

But if sorted by (item 1 of each & item 2 of each) - which concatenates as 
strings - gives sort keys 199 and 27 to result in
2,7
1,99
This can be fixed by formatting the numbers  so they have the same length by 
padding with 0s, as MW noted. Once they have the same length you could actually 
sort lexically which may be a lot faster than sorting numerically (although my 
guess is using 2 separate sorts may be faster still at least for short lists).

The concatenation method also won’t work if sorting real numbers:
1.0,0.2
1.0,0.1
since after concatenation the second decimal place would be ignored in a 
numeric sort.


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


Re: LC server, on-rev and time zones

2023-09-06 Thread jbv via use-livecode

Just tested on On-Rev and it works.
Thank you, that's very helpful.

Le 2023-09-06 09:39, matthias rebbe via use-livecode a écrit :
You could try to set the $TZ variable. I did not try on 
On-Rev/LivecodeHosting, but on a HostM Server which also has Livecode 
Server installed.


This script here for example would set the timezone first to Germany  
and outputs the current time and then for New York.



<€?€l€c€
€put "Europe/Berlin" into $TZ
€set the twelvehourtime to false
put the time
€put ""
€put "America/New_York" into $TZ
€set the twelvehourtime to true
€put the time
?>

Am 06.09.2023 um 15:22 schrieb jbv via use-livecode 
:


Hi list,

How do you handle different time zones in server scripts ?
For example, I and my clients are in Europe, so dates and
times need to be consistent with the local time zone.
But on-rev servers are located in the US East coast, so
there is presently a 6 hours difference.
Furthermore, switching from summer time to winter time
(and back) occur at different dates in Europe and North
America...
How do you guys manage to keep everything consistent
all year round ?

Thanks you in advance.
jbv

___
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


Re: LC server, on-rev and time zones

2023-09-06 Thread matthias rebbe via use-livecode
You could try to set the $TZ variable. I did not try on On-Rev/LivecodeHosting, 
but on a HostM Server which also has Livecode Server installed.

This script here for example would set the timezone first to Germany  and 
outputs the current time and then for New York.


<?lc
put "Europe/Berlin" into $TZ
set the twelvehourtime to false
put the time
put ""
put "America/New_York" into $TZ
set the twelvehourtime to true
put the time
?>

> Am 06.09.2023 um 15:22 schrieb jbv via use-livecode 
> :
> 
> Hi list,
> 
> How do you handle different time zones in server scripts ?
> For example, I and my clients are in Europe, so dates and
> times need to be consistent with the local time zone.
> But on-rev servers are located in the US East coast, so
> there is presently a 6 hours difference.
> Furthermore, switching from summer time to winter time
> (and back) occur at different dates in Europe and North
> America...
> How do you guys manage to keep everything consistent
> all year round ?
> 
> Thanks you in advance.
> jbv
> 
> ___
> 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


LC server, on-rev and time zones

2023-09-06 Thread jbv via use-livecode

Hi list,

How do you handle different time zones in server scripts ?
For example, I and my clients are in Europe, so dates and
times need to be consistent with the local time zone.
But on-rev servers are located in the US East coast, so
there is presently a 6 hours difference.
Furthermore, switching from summer time to winter time
(and back) occur at different dates in Europe and North
America...
How do you guys manage to keep everything consistent
all year round ?

Thanks you in advance.
jbv

___
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


Re: Sorting by item ... of each and item ... of each

2023-09-06 Thread Craig Newman via use-livecode
Matthias.

I do not have your original data. But try using “&” instead of “and”.

Craig

> On Sep 5, 2023, at 5:05 PM, Ralph DiMola via use-livecode 
>  wrote:
> 
> You can at least detect if the sorting function has failed using a global
> variable.
> 
> global s1
> 
> command test1
>   local t1
> 
>   --put "10,9,8,7,6,5,4,3,2,1" into t1 -- This line will not show an error
>   put "10,9,8,7a,6,5,4,3,2,1" into t1 -- This line will show an error
> 
>   put 0 into s1
>   sort items of t1 numeric by f1(each)
> 
>   if s1 <> the number of items in t1 then answer "Sort Function failed"
>   put t1 & cr & s1
> 
> end test1
> 
> 
> function f1 pEach
>   local tEach
>   put pEach into tEach
>   add 1 to tEach
>   add 1 to s1
>   return tEach
> end f1
> 
> Ralph DiMola
> IT Director
> Evergreen Information Services
> rdim...@evergreeninfo.net
> 
> -Original Message-
> From: use-livecode [mailto:use-livecode-boun...@lists.runrev.com] On Behalf
> Of matthias rebbe via use-livecode
> Sent: Saturday, September 02, 2023 9:03 PM
> To: How to use LiveCode
> Cc: matthias_livecode_150...@m-r-d.de
> Subject: Re: Sorting by item ... of each and item ... of each
> 
> Of course my "not working" sort code look like this
> 
> set the itemdelimiter to  ";"
> sort lines of tList numeric by item 3 of each and item 2 of each.
> 
> 
> 
> 
>> Am 03.09.2023 um 02:59 schrieb matthias_livecode_150...@m-r-d.de:
>> 
>> Maybe i do not see the forest for the trees
>> 
>> I have a tab delimited list which i want to sort. I am using this code to
> sort it by item 3 and  item 2
>> 
>> set the itemdelimiter to tab
>> sort lines of tList numeric by item 3 of each and item 2 of each.
>> 
>> But that code does not sort as i expected it. Column 2 is not sorted
> correctly.
>> The following list is the result. 
>> 
>> 113254;8420;3016365
>> 113254;8423;3016365
>> 113254;8422;3016365
>> 113254;8420;3016365
>> 113254;8420;3016365
>> 113254;8420;3016365
>> 113254;8421;3016365
>> 203212;8420;3016366
>> 203212;8423;3016366
>> 203212;8422;3016366
>> 203212;8420;3016366
>> 
>> 
>> My expectation for example  was that for value 3016365 in column 3 the
> values in Col 2 would be sorted like this
>> 
>> 113254;8423;3016365
>> 113254;8422;3016365
>> 113254;8421;3016365
>> 113254;8420;3016365
>> 113254;8420;3016365
>> 113254;8420;3016365
>> 113254;8420;3016365
>> 
>> Tried also'by item 2 of each and item 3 of each', but the sort result
> is the same?
>> 
>> Am i missing something?
>> 
>> Regards,
>> Matthias
>> 
> 
> 
> ___
> 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