Re: function for greatest object in list less than or equal to a value

2015-10-16 Thread Geoff Canyon
On Fri, Oct 16, 2015 at 2:02 PM,  wrote:

> Geoff.
>
>
> My original post:
>
>
>
> on mouseUp
>   answer findItemLessThanIndex(fld 1,"5")
> end mouseUp
>
> function findItemLessThanIndex tData,tIndex
>put comma & tIndex after tData
>sort items of tData numeric
>return  item itemOffset("5",tData) -1 of tData
> end findItemLessThanIndex
>
>
> Craig
>

Okay, that's what I implemented to test, so great. I have this weird
problem that gmail thinks posts to this list are spam. I've implemented a
rule to never let mail to this list be spam, but gmail makes a pain of
itself by labeling items as "This item wasn't put in spam because you said
so, but you should still consider letting us get rid of it for you." There
is apparently no way to tell gmail that it's being stupid and to just stop
doing that. And I think it messes with search results. :-/

gc
___
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: function for greatest object in list less than or equal to a value

2015-10-16 Thread dunbarx
Geoff.


My original post:


on mouseUp 
  answer findItemLessThanIndex(fld 1,"5") 
end mouseUp 

function findItemLessThanIndex tData,tIndex 
   put comma & tIndex after tData 
   sort items of tData numeric 
   return  item itemOffset("5",tData) -1 of tData 
end findItemLessThanIndex 


Craig



-Original Message-
From: Geoff Canyon 
To: How to use LiveCode 
Sent: Fri, Oct 16, 2015 12:04 pm
Subject: Re: function for greatest object in list less than or equal to a value


I couldn't find the original code for the offset version, but I took a shot
at
it and got the following results, with the repeat solution still faster
(in
6.7.3):

Run Count: 10

Test ID: 1 Looking for greatest value <
5
sort 0.920932 48402
repeat 0.33892 48402
PMB 0.337938
48402
ByOffset 0.448632 48402

Test ID: 2 Looking for greatest value
< 5
sort 0.914448
repeat 0.223951
PMB 0.213347
ByOffset 0.426248

Test ID:
3 Looking for greatest value < 5
sort 0.913603 99959
repeat
0.439324 99959
PMB 0.51457 99959
ByOffset 0.46632 99959


The
code:

on mouseUp
   repeat 100
  put random(10),"" after
L
   end repeat

   put 5 into testcase[1]
   put 5 into
testcase[2]
   put 5 into testcase[3]

   put 10 into runCount

  
repeat with i = 1 to runCount
  repeat with testID = 1 to 3

repeat for each item testType in "sort,repeat,PMB,ByOffset"
put i
&& testID && testType into fld 3
put the long seconds into S
 
do format("put greatestLessThan%s(L,testcase[%s])
into
R[%s][%s]",testType,testID,testType,testID)
add (the long
seconds - S) to T[testType][testID]
 end repeat
  end repeat
  
end repeat

   put "Run Count:" && runCount & cr & cr into fld 3
   repeat
with testID = 1 to 3
  put "Test ID:" && testID && "Looking for greatest
value <" &&
testcase[testID] & cr after fld 3
  repeat for each item
testType in "sort,repeat,PMB,ByOffset"
 put testType &&
T[testType][testID]/runCount &&
R[testType][testID] & cr after fld 3
  end
repeat
  put cr after fld 3
   end repeat

end mouseUp

function
greatestLessThanSort pList,V
   sort items of pList descending numeric
   sort
items of pList by each >= V
   return item 1 of pList
end
greatestLessThanSort

function greatestLessThanRepeat pList,V
   put empty
into R
   repeat for each item i in pList
  if i < V and i > R then put i
into R
   end repeat
   return R
end greatestLessThanRepeat

function
greatestLessThanPMB tList,maxVal
   repeat for each item i in tList
  if i
< maxVal then put i & comma after outList
   end repeat
   if outList is empty
then return empty else return max(outList)
end greatestLessThanPMB

function
greatestLessThanByOffset pList,V
   put "",V after pList
   sort items of
pList numeric
   return item (itemOffset(V,pList) - 1) of pList
end
greatestLessThanByOffset



On Wed, Oct 14, 2015 at 6:27 PM, Craig Newman
 wrote:

> Hi.
>
> The param "3" would be added to the
list. The sorted list would be:
> "2,3,4". When the itemOffset finds the "3",
the item just before it would
> be "2". That is how it works. To find the item
just before itemOffset does.
>
> This is faster than any of the "repeat for
each..." variants I have seen
> here. The reason, as I stated earlier as an
uninformed opinion, is that the
> low-level "sort" routine beats the high-level
"repeat" routine.
>
> Craig
>
> Sent from my iPhone
>
> > On Oct 14, 2015,
at 2:25 PM, Dr. Hawkins  wrote:
> >
> >> On Mon, Oct 12,
2015 at 6:35 AM,  wrote:
> >>
> >> My gadget adds the index
in a parameter to the function. if it already
> >> exists in the list, the
addition is superfluous, but harmless.
> >
> > But if the search list is "2,
4", and the search value is 3, doesn't this
> > return "3" rather than 2?
>
>
> >
> > --
> > Dr. Richard E. Hawkins, Esq.
> > (702) 508-8462
> >
___
> > 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

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

Re: function for greatest object in list less than or equal to a value

2015-10-16 Thread Geoff Canyon
I couldn't find the original code for the offset version, but I took a shot
at it and got the following results, with the repeat solution still faster
(in 6.7.3):

Run Count: 10

Test ID: 1 Looking for greatest value < 5
sort 0.920932 48402
repeat 0.33892 48402
PMB 0.337938 48402
ByOffset 0.448632 48402

Test ID: 2 Looking for greatest value < 5
sort 0.914448
repeat 0.223951
PMB 0.213347
ByOffset 0.426248

Test ID: 3 Looking for greatest value < 5
sort 0.913603 99959
repeat 0.439324 99959
PMB 0.51457 99959
ByOffset 0.46632 99959


The code:

on mouseUp
   repeat 100
  put random(10),"" after L
   end repeat

   put 5 into testcase[1]
   put 5 into testcase[2]
   put 5 into testcase[3]

   put 10 into runCount

   repeat with i = 1 to runCount
  repeat with testID = 1 to 3
 repeat for each item testType in "sort,repeat,PMB,ByOffset"
put i && testID && testType into fld 3
put the long seconds into S
do format("put greatestLessThan%s(L,testcase[%s]) into
R[%s][%s]",testType,testID,testType,testID)
add (the long seconds - S) to T[testType][testID]
 end repeat
  end repeat
   end repeat

   put "Run Count:" && runCount & cr & cr into fld 3
   repeat with testID = 1 to 3
  put "Test ID:" && testID && "Looking for greatest value <" &&
testcase[testID] & cr after fld 3
  repeat for each item testType in "sort,repeat,PMB,ByOffset"
 put testType && T[testType][testID]/runCount &&
R[testType][testID] & cr after fld 3
  end repeat
  put cr after fld 3
   end repeat

end mouseUp

function greatestLessThanSort pList,V
   sort items of pList descending numeric
   sort items of pList by each >= V
   return item 1 of pList
end greatestLessThanSort

function greatestLessThanRepeat pList,V
   put empty into R
   repeat for each item i in pList
  if i < V and i > R then put i into R
   end repeat
   return R
end greatestLessThanRepeat

function greatestLessThanPMB tList,maxVal
   repeat for each item i in tList
  if i < maxVal then put i & comma after outList
   end repeat
   if outList is empty then return empty else return max(outList)
end greatestLessThanPMB

function greatestLessThanByOffset pList,V
   put "",V after pList
   sort items of pList numeric
   return item (itemOffset(V,pList) - 1) of pList
end greatestLessThanByOffset



On Wed, Oct 14, 2015 at 6:27 PM, Craig Newman  wrote:

> Hi.
>
> The param "3" would be added to the list. The sorted list would be:
> "2,3,4". When the itemOffset finds the "3", the item just before it would
> be "2". That is how it works. To find the item just before itemOffset does.
>
> This is faster than any of the "repeat for each..." variants I have seen
> here. The reason, as I stated earlier as an uninformed opinion, is that the
> low-level "sort" routine beats the high-level "repeat" routine.
>
> Craig
>
> Sent from my iPhone
>
> > On Oct 14, 2015, at 2:25 PM, Dr. Hawkins  wrote:
> >
> >> On Mon, Oct 12, 2015 at 6:35 AM,  wrote:
> >>
> >> My gadget adds the index in a parameter to the function. if it already
> >> exists in the list, the addition is superfluous, but harmless.
> >
> > But if the search list is "2, 4", and the search value is 3, doesn't this
> > return "3" rather than 2?
> >
> >
> > --
> > Dr. Richard E. Hawkins, Esq.
> > (702) 508-8462
> > ___
> > 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: function for greatest object in list less than or equal to a value

2015-10-14 Thread Dr. Hawkins
On Mon, Oct 12, 2015 at 6:35 AM,  wrote:

> My gadget adds the index in a parameter to the function. if it already
> exists in the list, the addition is superfluous, but harmless.
>

But if the search list is "2, 4", and the search value is 3, doesn't this
return "3" rather than 2?


-- 
Dr. Richard E. Hawkins, Esq.
(702) 508-8462
___
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: function for greatest object in list less than or equal to a value

2015-10-14 Thread Dr. Hawkins
On Mon, Oct 12, 2015 at 4:24 PM, Geoff Canyon  wrote:

> function greatestLessThan pList,V
>sort items of pList descending numeric
>sort items of pList by each >= V
>return item 1 of pList
> end greatestLessThan


Something along these lines was what I'm trying to wrap my head around,
when it twisted my mind into a pretzel.

I came up with

*on* mouseUp

   *put* getNxtSmlst("2, 5, 8, 15, 22", 8)

*end* mouseUp


*function* getNxtSmlst list,floorVal



   *sort* items of list by cmpr(each,floorVal)




*end* getNxtSmlst


*function* cmpr val,flr



   *if* val < flr *then*

  *return* val -flr

   *else*

  *return* -1

   *end* *if*



*end* cmpr


But staying with pure intrinsics should be a wind, I'd think.

That one came from *wanting * to write,


sort items of theList descending by (each <= floor) * (floor-each)


--but aside from liveCode not coercing the logical to a 1/0 value (as I
thought it did--too many languages over the years!), I think it misses the
case where the value is in the list.

This is always going to have a relatively small number of entries in the
list; it would be more than unusual to have more than a couple of dozen
transitions between the "canned" paragraph text and the values merged in.
The function will be called on mouseMove, though, to pop up an field over
the merge values as the mouse passes over them.

I know that the elements of an array aren't in any particular order, but
does keys return them in numeric order if they are all numeric?  (Some
distant memory says that this is an exception.  The keys also would have
been added in numeric order.  For that matter, they could be stored on
render.  In any event, I think the algorithm can presume that the numbers
are ordered.

And I'm amazed at how much more I'm learning about other pieces of liveCode.


-- 
Dr. Richard E. Hawkins, Esq.
(702) 508-8462
___
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: function for greatest object in list less than or equal to a value

2015-10-14 Thread Craig Newman
Hi.

The param "3" would be added to the list. The sorted list would be:
"2,3,4". When the itemOffset finds the "3", the item just before it would be 
"2". That is how it works. To find the item just before itemOffset does.

This is faster than any of the "repeat for each..." variants I have seen here. 
The reason, as I stated earlier as an uninformed opinion, is that the low-level 
"sort" routine beats the high-level "repeat" routine. 

Craig

Sent from my iPhone

> On Oct 14, 2015, at 2:25 PM, Dr. Hawkins  wrote:
> 
>> On Mon, Oct 12, 2015 at 6:35 AM,  wrote:
>> 
>> My gadget adds the index in a parameter to the function. if it already
>> exists in the list, the addition is superfluous, but harmless.
> 
> But if the search list is "2, 4", and the search value is 3, doesn't this
> return "3" rather than 2?
> 
> 
> -- 
> Dr. Richard E. Hawkins, Esq.
> (702) 508-8462
> ___
> 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: function for greatest object in list less than or equal to a value

2015-10-13 Thread Alex Tweedly

On 13/10/2015 02:20, Mike Doub wrote:

Pass by reference and you can eliminate a memcopy on the initial function call.

-= Mike


That *used* to be true - but (unless my memory is playing tricks again 
:-), Mark Waddingham said on the list recently that recent (*) versions 
of LC use a pointer, and only "copy-on-write" - so there would be no 
saving in this case.


Kind of verified by a very simple benchmark:

using a value of 500,000 I got times of
LC version  normalpass by ref
6.6  4023 683
7.0.5   1655   1486
8.0  1768   1465

The code used (with apologies - a bit rushed)

constant K = 100
constant KK = 10
on mouseUp
   ask "how often"
   put it into KKK
   repeat K times
  put "a" after tmp
   end repeat
   repeat KK times
  put tmp after tmp
   end repeat
   put the number of chars in tmp
   put the millisecs into t1
   repeat KKK times
  aa tmp
   end repeat
   put " took " & the millisecs - t1 after msg
   put the millisecs into t1
   repeat KKK times
  bb tmp
   end repeat
   put " took " & the millisecs - t1 after msg
end mouseUp

on aa p
  put  char 1 of p into t
end aa

on bb @p
  put  char 1 of p into t
end bb

-- Alex.

On 13/10/2015 02:20, Mike Doub wrote:

Pass by reference and you can eliminate a memcopy on the initial function call.

-= Mike



On Oct 12, 2015, 9:11 PM, at 9:11 PM, Geoff Canyon  wrote:

Not quite as concise, but this function is about 3x faster:

function greatestLessThan pList,V
   put empty into R
   repeat for each item i in pList
  if i < V and i > R then put i into R
   end repeat
   return R
end greatestLessThan
___
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: function for greatest object in list less than or equal to a value

2015-10-13 Thread hh
@Craig
I also found the "sort" method faster than the "repeat" method on
a PPC. On intel, under several OSes, here always won the [1] below.

@Bernd
I didn't include your solution because pre-sorting wastes too
much time. Perhaps sorting could be included in your binary loop?

@Geoff
You could also try with a critical value near the "edges":
greatestLessThanRepeat(L,1) and
greatestLessThanRepeat(L,10-1)
and then average your three runs?

>From my tests
(referencing the list gives moreover a smallincrease in speed.
Empty list members are not handled, LC handles empty as zero):

** The simplest is the fastest **

[1] (contributed by P.M.B.)
function getMaxLessThan tList,maxVal
   repeat for each item i in tList
  if i < maxVal then put i & comma after outList
   end repeat
   return max(outList)
end getMaxLessThan

Even the clever idea of max-finding in the same loop

[2] (contributed by G.C.)
function greatestLessThanRepeat pList,V
   put empty into R
   repeat for each item i in pList
  if i < V and i > R then put i into R
   end repeat
   return R
end greatestLessThanRepeat

is *slightly* slower.

[3] (contributed by me)
function greatestMemberSmallerThan L,V
   put -10^15 into z[true]
   repeat for each item x in L
   put comma & x after z[xv) is also asked for, with the same v.

Hermann
___
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: function for greatest object in list less than or equal to a value

2015-10-13 Thread hh
Similar things are useful for a very specialized statistical
evaluation I have to do soon, so I tested again with LC 7:

There is an interesting difference between LC versions 6 and 7.

The 'direct way' of GC reveals now as clearly fastest.

Tested with one of GC's 12 MB strings on a Mac mini(i5 2.5 GHz),
testString() as below, and a critical value of v=5.
The (correct) result is 49246, used time is in seconds.

[a] LC 6.7.7
repeat-PMB  0.326  <- fastest
repeat-GC   0.350
repeat-hh   0.445
sort-GC 0.985

[b] LC 7.1.0
repeat-PMB  3.562
repeat-GC   1.483  <- fastest, the only one with a factor < 9
repeat-hh  1163.0 <- an ARRAY BUG? :-(
sort-GC 8.156

---

function testString 
   set randomseed to 1444826515
   -- so you'll get exactly my test string
   repeat 100
  put comma & random(10) after L
   end repeat
   delete byte 1 of L
   return L
end testString

function repeatPMB L,v  --[1]
  repeat for each item i in L
  if i < v then put comma & i after outL
   end repeat
   return max(outL)
end repeatPMB

function repeatGC L,v  --[2]
   put empty into R
   repeat for each item i in L
  if i < v and i > R then put i into R
   end repeat
   return R
end repeatGC

function repeathh L,v  --[3]
  repeat for each item i in L
  put comma & i after z[i < v]
   end repeat
   return max(z[true])
end repeathh

function sortGC L,v  --[4]
   sort items of L descending numeric
   sort items of L by (each >= v)
   return item 1 of L
end sortGC


___
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: function for greatest object in list less than or equal to a value

2015-10-13 Thread Peter TB Brett

Hi Hermann,

There's no array bug -- it's an aspect of its intentional behaviour. 
Appending to an element of an array always causes a copy, so you get 
O(N^2) complexity.


Please re-test in LiveCode 8.0.0-dp-7, because there are some large 
performance optimisations in that release that may affect these results. 
 In particular, I expect anything that uses "put after" outside an 
array to be much faster, and anything that uses sort to be faster (if I 
remember correctly).  This Week in LiveCode has links to the pull 
requests, which explain exactly what's been made faster.


 Peter

On 13/10/2015 14:42, hh wrote:

Similar things are useful for a very specialized statistical
evaluation I have to do soon, so I tested again with LC 7:

There is an interesting difference between LC versions 6 and 7.

The 'direct way' of GC reveals now as clearly fastest.

Tested with one of GC's 12 MB strings on a Mac mini(i5 2.5 GHz),
testString() as below, and a critical value of v=5.
The (correct) result is 49246, used time is in seconds.

[a] LC 6.7.7
repeat-PMB  0.326  <- fastest
repeat-GC   0.350
repeat-hh   0.445
sort-GC 0.985

[b] LC 7.1.0
repeat-PMB  3.562
repeat-GC   1.483  <- fastest, the only one with a factor < 9
repeat-hh  1163.0 <- an ARRAY BUG? :-(
sort-GC 8.156

---

function testString
set randomseed to 1444826515
-- so you'll get exactly my test string
repeat 100
   put comma & random(10) after L
end repeat
delete byte 1 of L
return L
end testString

function repeatPMB L,v  --[1]
   repeat for each item i in L
   if i < v then put comma & i after outL
end repeat
return max(outL)
end repeatPMB

function repeatGC L,v  --[2]
put empty into R
repeat for each item i in L
   if i < v and i > R then put i into R
end repeat
return R
end repeatGC

function repeathh L,v  --[3]
   repeat for each item i in L
   put comma & i after z[i < v]
end repeat
return max(z[true])
end repeathh

function sortGC L,v  --[4]
sort items of L descending numeric
sort items of L by (each >= v)
return item 1 of L
end sortGC


___
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



--
Dr Peter Brett 
LiveCode Open Source Team

LiveCode on reddit: https://reddit.com/r/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: function for greatest object in list less than or equal to a value

2015-10-13 Thread Geoff Canyon
On Tue, Oct 13, 2015 at 4:35 AM, hh  wrote:

> function getMaxLessThan tList,maxVal
>repeat for each item i in tList
>   if i < maxVal then put i & comma after outList
>end repeat
>return max(outList)
> end getMaxLessThan
>

This returns 0 if there is no valid result, rather than empty. I modified
it like this to get the correct result in that case:

function getMaxLessThan tList,maxVal
   repeat for each item i in tList
  if i < maxVal then put i & comma after outList
   end repeat
   if outList is empty then return empty else return max(outList)
end getMaxLessThan

I then created three test cases, searching for a small upper limit, a mid
upper limit, and a high upper limit, as shown in the code. I saw
variability in the results, so I wrote the test to run 10 times and take
the average. Here are the results, running on a MB Pro in LC 6.7.3:

Run Count: 10

Test ID: 1 Looking for greatest value < 5
sort 0.948062 49481
repeat 0.347538 49481
PMB 0.354209 49481

Test ID: 2 Looking for greatest value < 5
sort 0.950574
repeat 0.225004
PMB 0.212485

Test ID: 3 Looking for greatest value < 5
sort 0.920444 99683
repeat 0.442339 99683
PMB 0.527431 99683

In single runs I've seen PMB beat repeat on test 1. PMB is consistently
slightly faster on test 2, and consistently slower (more than the
difference on test 2) on test 3. Unless there is a difference based on
hardware or LC version, I think it comes down to taste for which to use
between the two. I never expected the sort version to be even as close as
it was, but for most purposes even it would seem to be an okay choice.

Code used:

on mouseUp
   repeat 100
  put random(10),"" after L
   end repeat

   put 5 into testcase[1]
   put 5 into testcase[2]
   put 5 into testcase[3]

   put 10 into runCount

   repeat with i = 1 to runCount
  repeat with testID = 1 to 3
 repeat for each item testType in "sort,repeat,PMB"
put i && testID && testType into fld 3
put the long seconds into S
do format("put greatestLessThan%s(L,testcase[%s]) into
R[%s][%s]",testType,testID,testType,testID)
add (the long seconds - S) to T[testType][testID]
 end repeat
  end repeat
   end repeat

   put "Run Count:" && runCount & cr & cr into fld 3
   repeat with testID = 1 to 3
  put "Test ID:" && testID && "Looking for greatest value <" &&
testcase[testID] & cr after fld 3
  repeat for each item testType in "sort,repeat,PMB"
 put testType && T[testType][testID]/runCount &&
R[testType][testID] & cr after fld 3
  end repeat
  put cr after fld 3
   end repeat

end mouseUp

function greatestLessThanSort pList,V
   sort items of pList descending numeric
   sort items of pList by each >= V
   return item 1 of pList
end greatestLessThanSort

function greatestLessThanRepeat pList,V
   put empty into R
   repeat for each item i in pList
  if i < V and i > R then put i into R
   end repeat
   return R
end greatestLessThanRepeat

function greatestLessThanPMB tList,maxVal
   repeat for each item i in tList
  if i < maxVal then put i & comma after outList
   end repeat
   if outList is empty then return empty else return max(outList)
end greatestLessThanPMB
___
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: function for greatest object in list less than or equal to a value

2015-10-13 Thread Peter M. Brigham
Here are a couple of functions that might be useful re timing processes.

-- Peter

Peter M. Brigham
pmb...@gmail.com
http://home.comcast.net/~pmbrig

--

function microsecs
   put the long seconds into s
   set the numberformat to "#.00"
   add 0 to s
   replace "." with empty in s
   return s
end microsecs

function exactTime
   -- -MM-DD HH:MM:SS.##
   --   ie, down to microseconds
   -- times in this format can be arranged chronologically
   --   with an ordinary (non-numeric) sort command
   -- based on verboseTime() by Mark Talluto, Use-LC list
   -- revised by Peter M. Brigham, pmb...@gmail.com
   
   put the long seconds into s
   put char 1 to offset(".",s)-1 of s into dd
   convert dd to internet english date
   put word 5 of dd into tTime
   set the numberformat to "#.00"
   add 0 to s
   put char -7 to -1 of s after tTime
   convert dd to dateitems
   put item 1 of dd into tYear
   put item 2 of dd into tMo
   put item 3 of dd into tDay
   set the numberformat to "00"
   add 0 to tMo
   add 0 to tDay
   return tYear & "-" & tMo & "-" & tDay && tTime
end exactTime


On Oct 12, 2015, at 1:41 PM, Richard Gaskin wrote:

> BNig wrote:
> 
>> BTW, what is a tick? Is that the imperial gallon of time? Or more a pint, a
>> fluid ounce?
>> I do kow that ticks bite and :)
> 
> In other programming languages a tick is often a counter within some larger 
> timer framework.
> 
> In HyperTalk it was derived similarly, the default update rate for the early 
> Mac OS vertical retrace subsystem.
> 
> Throughout HyperTalk's life it was the most granular expression of time the 
> language supported, since millisecond support was introduced to the xTalk 
> world by MetaCard in 1992.
> 
> The choice of tying the ticks to retrace was perhaps a necessity in early Mac 
> OS systems, relying as they did on preemptive multitasking. But that reliance 
> also made it an inexact quantity:  by default the vertical retrace would 
> happen 60 times a second, but it was possible to have some processes run long 
> enough to stall it a bit now and then.
> 
> But imprecise as it was it was all we had, so we used it.
> 
> Today both ticks and milliseconds are independent of the display subsystem on 
> all platforms, and generally more reliable.
> 
> I migrated to milliseconds for benchmarking as soon as I became aware of them 
> in MetaCard, since most routines are fast enough that the finer granularity 
> is often useful.
> 
> If you need even finer granularity you can use "the long seconds", but with 
> any of them it's helpful to keep in mind the consideration Mark Wieder 
> reminds us of: modern multi-tasking systems can have throughput affected by a 
> great many considerations beyond our control.
> 
> For this reason all benchmarks should be run multiple times with as few other 
> processes running as practical, and even then their results should be taken 
> with a grain of salt.
> 
> -- 
> Richard Gaskin
> Fourth World Systems
> Software Design and Development for the Desktop, Mobile, and the Web
> 
> ambassa...@fourthworld.comhttp://www.FourthWorld.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


___
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: function for greatest object in list less than or equal to a value

2015-10-13 Thread Peter TB Brett

On 13/10/2015 15:33, Richard Gaskin wrote:

Peter TB Brett wrote:

 > On 13/10/2015 14:42, hh wrote:
 >> There is an interesting difference between LC versions 6 and 7.
 >>...
 >> [a] LC 6.7.7
 >> repeat-PMB 0.326 <- fastest
 >> repeat-GC 0.350
 >> repeat-hh 0.445
 >> sort-GC 0.985
 >>
 >> [b] LC 7.1.0
 >> repeat-PMB 3.562
 >> repeat-GC 1.483 <- fastest, the only one with a factor < 9
 >> repeat-hh 1163.0 <- an ARRAY BUG? :-(
 >> sort-GC 8.156
 >
 > There's no array bug -- it's an aspect of its intentional behaviour.
 > Appending to an element of an array always causes a copy, so you get
 > O(N^2) complexity.

Thanks for the background, Peter, but what accounts for the difference
between version (v6 @ 0.445ms vs v7 @ 1163.0ms)?


I don't know anything about the way arrays are implemented in LiveCode 
6.x, so I can't tell you how they've changed.



 > Please re-test in LiveCode 8.0.0-dp-7, because there are some large
 > performance optimisations in that release that may affect these
 > results.

Being part of LiveCode Script and not specific to Builder, will these
changes also be in v7.x?


The changes will be in 7.1.1-rc-1.

  Peter

--
Dr Peter Brett 
LiveCode Open Source Team

LiveCode on reddit: https://reddit.com/r/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: function for greatest object in list less than or equal to a value

2015-10-13 Thread Geoff Canyon
I ran the same code in 7.0.3 and got this:

Run Count: 10

Test ID: 1 Looking for greatest value < 5
sort 9.366217 49338
repeat 1.764816 49338
PMB 4.268512 49338

Test ID: 2 Looking for greatest value < 5
sort 8.5548
repeat 1.534175
PMB 1.494919

Test ID: 3 Looking for greatest value < 5
sort 9.406507 98573
repeat 1.842926 98573
PMB 6.723159 98573

Disappointing how much slower it is.
___
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: function for greatest object in list less than or equal to a value

2015-10-13 Thread Richard Gaskin

Peter TB Brett wrote:

> On 13/10/2015 14:42, hh wrote:
>> There is an interesting difference between LC versions 6 and 7.
>>...
>> [a] LC 6.7.7
>> repeat-PMB 0.326 <- fastest
>> repeat-GC 0.350
>> repeat-hh 0.445
>> sort-GC 0.985
>>
>> [b] LC 7.1.0
>> repeat-PMB 3.562
>> repeat-GC 1.483 <- fastest, the only one with a factor < 9
>> repeat-hh 1163.0 <- an ARRAY BUG? :-(
>> sort-GC 8.156
>
> There's no array bug -- it's an aspect of its intentional behaviour.
> Appending to an element of an array always causes a copy, so you get
> O(N^2) complexity.

Thanks for the background, Peter, but what accounts for the difference 
between version (v6 @ 0.445ms vs v7 @ 1163.0ms)?



> Please re-test in LiveCode 8.0.0-dp-7, because there are some large
> performance optimisations in that release that may affect these
> results.

Being part of LiveCode Script and not specific to Builder, will these 
changes also be in v7.x?


--
 Richard Gaskin
 Fourth World Systems
 Software Design and Development for the Desktop, Mobile, and the Web
 
 ambassa...@fourthworld.comhttp://www.FourthWorld.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


Re: function for greatest object in list less than or equal to a value

2015-10-13 Thread hh
@P.T.B

The average time needed is (testing gave me a break ...)

[c] LC 8.0.0-dp7
repeat-PMB  3.794
repeat-GC   1.475  <- fastest
repeat-hh  1165.0 <- :-(  No difference to LC 7.1.0!
sort-GC 7.240

I have indeed data strings of the tested size (10-15 MByte).
Advanced statistical analysis without arrays is close to useless.
And LC > 6 has the useful option to split and combine by
delimiters of length > 1.

Is the library 'com.livecode.foreign' a target of hope?

p.s. Your HTML5-link from 'This Week in Livecode' forces me to
improve that test. What a trick!  ;-)

@G.C.
Of course is a large smaller-than-set the worst case for the PMBrepeat.

But meanwhile I think, fully convinced by the tests with LC 7 and 8
(see above) that your 'direct' function greatestLessThanRepeat is the
way to go.

It works also great for smallestGreaterThan (without equality) or both:

-- Here v is the critical value and v1,v2 are starting values
-- for min and max, coming from a pre-knowledge about the data
-- or for example v1=-10^16, v2=10^16
function miniMaxGC L,v,v1,v2
   put v1 into vMax; put v2 into vMin
   repeat for each item i in pList
  if i < v and i > vMax then put i into vMax
  else if i > v and i < vMin then put i into vMin
   end repeat
   return ( vMax, v, vMin )
end miniMaxGC

[Perhaps a switch will be better? Or eliminate at first v by "replace"?]

  

___
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: function for greatest object in list less than or equal to a value

2015-10-13 Thread Richard Gaskin

Peter TB Brett wrote:

On 13/10/2015 15:33, Richard Gaskin wrote:

Peter TB Brett wrote:

 > On 13/10/2015 14:42, hh wrote:
 >> There is an interesting difference between LC versions 6 and 7.
 >>...
 >> [a] LC 6.7.7
 >> repeat-PMB 0.326 <- fastest
 >> repeat-GC 0.350
 >> repeat-hh 0.445
 >> sort-GC 0.985
 >>
 >> [b] LC 7.1.0
 >> repeat-PMB 3.562
 >> repeat-GC 1.483 <- fastest, the only one with a factor < 9
 >> repeat-hh 1163.0 <- an ARRAY BUG? :-(
 >> sort-GC 8.156
 >
 > There's no array bug -- it's an aspect of its intentional behaviour.
 > Appending to an element of an array always causes a copy, so you get
 > O(N^2) complexity.

Thanks for the background, Peter, but what accounts for the difference
between version (v6 @ 0.445ms vs v7 @ 1163.0ms)?


I don't know anything about the way arrays are implemented in LiveCode
6.x, so I can't tell you how they've changed.


I keep hoping to find some time to learn C++ well enough to figure out 
things like that on my own, but between bash and JavaScript and Python 
already filling my weekends it's been hard to get the time.  Hopefully 
one day...




 > Please re-test in LiveCode 8.0.0-dp-7, because there are some large
 > performance optimisations in that release that may affect these
 > results.

Being part of LiveCode Script and not specific to Builder, will these
changes also be in v7.x?


The changes will be in 7.1.1-rc-1.


Super-cool, Peter.  Thanks!

--
 Richard Gaskin
 Fourth World Systems
 Software Design and Development for the Desktop, Mobile, and the Web
 
 ambassa...@fourthworld.comhttp://www.FourthWorld.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


Re: function for greatest object in list less than or equal to a value

2015-10-12 Thread Peter TB Brett



On 12/10/2015 03:26, Peter M. Brigham wrote:

function getMaxLessThan tList,maxVal
repeat for each item i in tList
   if i < maxVal then put i & comma after outList
end repeat
return max(item 1 to -1 of outList)
end getMaxLessThan


This should be slightly faster, because it only loops over the items once:

function getMaxLessThan pList, pLimit
   local tMaxFound, tItem
   put empty into tMaxFound
   repeat for each item tItem in tList
  if tItem < pLimit and \
(tItem > tMaxFound or tMaxFound is empty) then
 put tItem into tMaxFound
  end if
   end repeat
   return tMaxFound
end getMaxLessThan

The "sort"-based solution will be much less efficient for long input 
lists because sorting is O(N*log(N)), whereas Peter Brigham's and my 
solutions are O(N).


 Peter

--
Dr Peter Brett 
LiveCode Open Source Team

LiveCode on reddit: https://reddit.com/r/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: function for greatest object in list less than or equal to a value

2015-10-12 Thread J. Landman Gay
Oops, I missed that. You're right. 

On October 12, 2015 8:35:04 AM CDT, dunb...@aol.com wrote:
>Jacque,
>
>
>My gadget adds the index in a parameter to the function. if it already
>exists in the list, the addition is superfluous, but harmless.
>
>
>Craig
>
>
>
>-Original Message-
>From: J. Landman Gay 
>To: How to use LiveCode 
>Sent: Mon, Oct 12, 2015 12:07 am
>Subject: Re: function for greatest object in list less than or equal to
>a value
>
>
>On 10/11/2015 9:26 PM, dunb...@aol.com wrote:
>> function findItemLessThanIndex
>tData,tIndex
>> put comma & tIndex after tData
>> sort items of tData
>numeric
>> return  item itemOffset("5",tData) -1 of tData
>> end
>findItemLessThanIndex
>
>I thought of that too, but it fails if tIndex isn't in
>the list. The 
>example list was: "1,3,4,7,9" and the target limit was 5.
>
>I
>couldn't see a way that avoids looping through all the values.
>
>--
>
>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
>
> 
>___
>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


Re: function for greatest object in list less than or equal to a value

2015-10-12 Thread Randy Hengst
I realize this isn’t written as a function, but what about doing the sort first?

on getMaxLessThan tList,maxVal
   sort items of tList descending
   repeat for each item theDigitToCheck in tList
  if theDigitToCheck < maxVal then
 answer "found it" && theDigitToCheck
 exit repeat
  end if
   end repeat
end getMaxLessThan

be well,
randy

Randy Hengst
www.classroomFocusedSoftware.com


> On Oct 12, 2015, at 10:26 AM, J. Landman Gay  wrote:
> 
> Oops, I missed that. You're right. 
> 
> On October 12, 2015 8:35:04 AM CDT, dunb...@aol.com wrote:
>> Jacque,
>> 
>> 
>> My gadget adds the index in a parameter to the function. if it already
>> exists in the list, the addition is superfluous, but harmless.
>> 
>> 
>> Craig
>> 
>> 
>> 
>> -Original Message-
>> From: J. Landman Gay 
>> To: How to use LiveCode 
>> Sent: Mon, Oct 12, 2015 12:07 am
>> Subject: Re: function for greatest object in list less than or equal to
>> a value
>> 
>> 
>> On 10/11/2015 9:26 PM, dunb...@aol.com wrote:
>>> function findItemLessThanIndex
>> tData,tIndex
>>>put comma & tIndex after tData
>>>sort items of tData
>> numeric
>>>return  item itemOffset("5",tData) -1 of tData
>>> end
>> findItemLessThanIndex
>> 
>> I thought of that too, but it fails if tIndex isn't in
>> the list. The 
>> example list was: "1,3,4,7,9" and the target limit was 5.
>> 
>> I
>> couldn't see a way that avoids looping through all the values.
>> 
>> --
>> 
>> 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
>> 
>> 
>> ___
>> 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

___
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: function for greatest object in list less than or equal to a value

2015-10-12 Thread dunbarx
Jacque,


My gadget adds the index in a parameter to the function. if it already exists 
in the list, the addition is superfluous, but harmless.


Craig



-Original Message-
From: J. Landman Gay 
To: How to use LiveCode 
Sent: Mon, Oct 12, 2015 12:07 am
Subject: Re: function for greatest object in list less than or equal to a value


On 10/11/2015 9:26 PM, dunb...@aol.com wrote:
> function findItemLessThanIndex
tData,tIndex
> put comma & tIndex after tData
> sort items of tData
numeric
> return  item itemOffset("5",tData) -1 of tData
> end
findItemLessThanIndex

I thought of that too, but it fails if tIndex isn't in
the list. The 
example list was: "1,3,4,7,9" and the target limit was 5.

I
couldn't see a way that avoids looping through all the values.

--

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

 
___
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: function for greatest object in list less than or equal to a value

2015-10-12 Thread dunbarx
I made a test between the "sort" method and the "repeat for each". For a list 
of about 100,000 items, sort finds the max value in 33 ticks, and "repeat" 
takes 50 ticks.


This seems logical to me, since lower level operations are used in "sort" as 
opposed to "repeat" even though we all know how fast "repeat for each" is.


Craig 



-Original Message-
From: Peter TB Brett 
To: How to use LiveCode 
Sent: Mon, Oct 12, 2015 4:55 am
Subject: Re: function for greatest object in list less than or equal to a value




On 12/10/2015 03:26, Peter M. Brigham wrote:
> function getMaxLessThan
tList,maxVal
> repeat for each item i in tList
>if i < maxVal then
put i & comma after outList
> end repeat
> return max(item 1 to -1 of
outList)
> end getMaxLessThan

This should be slightly faster, because it
only loops over the items once:

 function getMaxLessThan pList, pLimit
 
local tMaxFound, tItem
put empty into tMaxFound
repeat for
each item tItem in tList
   if tItem < pLimit and \

(tItem > tMaxFound or tMaxFound is empty) then
  put tItem into
tMaxFound
   end if
end repeat
return tMaxFound

end getMaxLessThan

The "sort"-based solution will be much less efficient for
long input 
lists because sorting is O(N*log(N)), whereas Peter Brigham's and
my 
solutions are O(N).

  Peter

--

Dr Peter Brett 
LiveCode Open Source
Team

LiveCode on reddit:
https://reddit.com/r/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: function for greatest object in list less than or equal to a value

2015-10-12 Thread BNig
OK, I will throw this in for a good measure


-
function closestSmallerValue @pList, pMax
   -- this assumes pList to be sorted ascending AND consisting of numbers
   -- AND no empty items
   -- here only testing for SMALLER, not <=
   
   put the number of items of pList into tNoItems
   
   -- if pMax is > then value of last item of pList
   if pMax > tNoItems and pMax > item tNoItems of pList then return item
tNoItems of pList
   
   -- if pMax is smaller then value of first item
   if pMax <= item 1 of pList then return "error, no smaller value found"
   
   -- in case the number of items < pMax but pList contains valid range
   put min(pMax, tNoItems) into tStartItem
   
   -- try sort of a binary search
   return closeIn(pList,1,tStartItem,pMax)
end closestSmallerValue

function closeIn @pList pLowerBounds, pUpperBounds, pMax
   put pUpperBounds - pLowerBounds into tSpan
   put tSpan div 2 + pLowerBounds into tNewItem
   put item tNewItem of pList into tNewValue
   if tNewValue > pMax then
  put tNewItem into pUpperBounds
   else
  put tNewItem into pLowerBounds
   end if
   if pUpperBounds - pLowerBounds < 2 then
  if item pLowerBounds of pList < pMax then
 return item  pLowerBounds  of pList
  else
 return item  pLowerBounds -1  of pList
  end if
   else
  get closeIn (pList, pLowerBounds, pUpperBounds, pMax)
   end if
end closeIn
-

BTW, what is a tick? Is that the imperial gallon of time? Or more a pint, a
fluid ounce?
I do kow that ticks bite and :)

No guarantees, did test it though with various lists up to 10 items, but
what the tick... :)
My first attempt at something like "binary search" so please be forgiving.

Kind regards
Bernd



--
View this message in context: 
http://runtime-revolution.278305.n4.nabble.com/function-for-greatest-object-in-list-less-than-or-equal-to-a-value-tp4697221p4697266.html
Sent from the Revolution - User mailing list archive at Nabble.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


Re: function for greatest object in list less than or equal to a value

2015-10-12 Thread BNig
Thank you for the explanation Richard. Good to know the historical background
of ticks.

so for a list of 10 items the worst case for my code is tMax 10 to
find 9
it takes about 12 ticks and roughly 190 milliseconds

Kind regards
Bernd



--
View this message in context: 
http://runtime-revolution.278305.n4.nabble.com/function-for-greatest-object-in-list-less-than-or-equal-to-a-value-tp4697221p4697273.html
Sent from the Revolution - User mailing list archive at Nabble.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


Re: function for greatest object in list less than or equal to a value

2015-10-12 Thread Richard Gaskin

BNig wrote:


BTW, what is a tick? Is that the imperial gallon of time? Or more a pint, a
fluid ounce?
I do kow that ticks bite and :)


In other programming languages a tick is often a counter within some 
larger timer framework.


In HyperTalk it was derived similarly, the default update rate for the 
early Mac OS vertical retrace subsystem.


Throughout HyperTalk's life it was the most granular expression of time 
the language supported, since millisecond support was introduced to the 
xTalk world by MetaCard in 1992.


The choice of tying the ticks to retrace was perhaps a necessity in 
early Mac OS systems, relying as they did on preemptive multitasking. 
But that reliance also made it an inexact quantity:  by default the 
vertical retrace would happen 60 times a second, but it was possible to 
have some processes run long enough to stall it a bit now and then.


But imprecise as it was it was all we had, so we used it.

Today both ticks and milliseconds are independent of the display 
subsystem on all platforms, and generally more reliable.


I migrated to milliseconds for benchmarking as soon as I became aware of 
them in MetaCard, since most routines are fast enough that the finer 
granularity is often useful.


If you need even finer granularity you can use "the long seconds", but 
with any of them it's helpful to keep in mind the consideration Mark 
Wieder reminds us of: modern multi-tasking systems can have throughput 
affected by a great many considerations beyond our control.


For this reason all benchmarks should be run multiple times with as few 
other processes running as practical, and even then their results should 
be taken with a grain of salt.


--
 Richard Gaskin
 Fourth World Systems
 Software Design and Development for the Desktop, Mobile, and the Web
 
 ambassa...@fourthworld.comhttp://www.FourthWorld.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


Re: function for greatest object in list less than or equal to a value

2015-10-12 Thread Richard Gaskin

Correction - earlier I wrote:

The choice of tying the ticks to retrace was perhaps a necessity in
early Mac OS systems, relying as they did on preemptive multitasking.


That should of course read:


The choice of tying the ticks to retrace was perhaps a necessity in
early Mac OS systems, relying as they did on cooperative multitasking.


The switch from cooperative multitasking to modern preemptive 
multitasking was one of the many welcome advancements NeXT's Unix kernel 
brought to the Mac world.


--
 Richard Gaskin
 Fourth World Systems
 Software Design and Development for the Desktop, Mobile, and the Web
 
 ambassa...@fourthworld.comhttp://www.FourthWorld.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


Re: function for greatest object in list less than or equal to a value

2015-10-12 Thread Mark Waddingham

On 2015-10-12 19:56, dunb...@aol.com wrote:

"Sort" is consistently faster, up to 50%. Why "up to"? Try it several
times. As per the other, newer part of this thread, timing based on
such things as "ticks" needs to be run many times to get an accurate
"average" reading. Other system processes come into play, as well as
gremlins.


The most interesting question here (from a complexity O(n) vs O(nlog n) 
point of view at least) is at what length of list does the 'sort' 
version become slower than the 'repeat' version...


Mathematically, there has to be a minimum length of list for which this 
is true.


Mark.

--
Mark Waddingham ~ m...@livecode.com ~ http://www.livecode.com/
LiveCode: Everyone can create apps

___
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: function for greatest object in list less than or equal to a value

2015-10-12 Thread John Dixon


wait for 10 ticks -- 1/6 of a second

> 
> No guarantees, did test it though with various lists up to 10 items, but
> what the tick... :)
> My first attempt at something like "binary search" so please be forgiving.
> 
> Kind regards
> Bernd

  
___
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: function for greatest object in list less than or equal to a value

2015-10-12 Thread dunbarx
Peter.


All you need is a button:



on mouseUp
   put "1,2,4,3,5,6,7,8,9,34," into temp
   repeat 16
  put temp after temp
   end repeat
   put the ticks into xx
   put  "Repeat:" && getMaxLessThan(temp,"5") into repeatResults
   put "  :Ticks:" && the ticks - xx  after repeatResults
   put the ticks into xx
   put  "Sort:" && findItemLessThanIndex(temp,"5") into sortResults
   put "  :Ticks:" && the ticks - xx  after sortResults
   answer repeatResults & return & sortResults
end mouseUp


function getMaxLessThan tList,maxVal 
   repeat for each item i in tList 
  if i < maxVal then put i & comma after outList 
   end repeat 
   return max(item 1 to -1 of outList) 
end getMaxLessThan 


function findItemLessThanIndex tData,tIndex
   put comma & tIndex after tData
   sort items of tData numeric
   return  item itemOffset("5",tData) -1 of tData
end findItemLessThanIndex



"Sort" is consistently faster, up to 50%. Why "up to"? Try it several times. As 
per the other, newer part of this thread, timing based on such things as 
"ticks" needs to be run many times to get an accurate "average" reading. Other 
system processes come into play, as well as gremlins.


Craig 





-Original Message-
From: Peter TB Brett 
To: How to use LiveCode 
Sent: Mon, Oct 12, 2015 11:23 am
Subject: Re: function for greatest object in list less than or equal to a value




On 12/10/2015 15:24, dunb...@aol.com wrote:
> I made a test between the
"sort" method and the "repeat for each". For a list of about 100,000 items, sort
finds the max value in 33 ticks, and "repeat" takes 50 ticks.
>
> This seems
logical to me, since lower level operations are used in "sort" as opposed to
"repeat" even though we all know how fast "repeat for each" is.
>

That's
really surprising!  Could you please share your test stack so I 
can have a
play?

Peter

-- 
Dr Peter Brett

LiveCode Open Source Team

LiveCode on reddit:
https://reddit.com/r/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: function for greatest object in list less than or equal to a value

2015-10-12 Thread Bob Sneidar
NVM stupid question. I was thinking about the lag older systems would introduce 
in the actual clock, and lost sight of the problem.

Bob S


On Oct 12, 2015, at 11:21 , Bob Sneidar 
> wrote:

So are you sating that if I had a monitor that refreshed at say 120/sec, that 
there would then be (roughly) 120 ticks in a second? Also, since processor load 
can influence real time statistics, but cannot influence the vertical refresh 
rate, wouldn't ticks then be the more accurate unit of measure?

___
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: function for greatest object in list less than or equal to a value

2015-10-12 Thread Richard Gaskin

Bob Sneidar wrote:

> On Oct 12, 2015, at 10:41 , Richard Gaskin wrote:
>> The choice of tying the ticks to retrace was perhaps a necessity
>> in early Mac OS systems, relying as they did on preemptive
>> multitasking. But that reliance also made it an inexact quantity:
>> by default the vertical retrace would happen 60 times a second,
>> but it was possible to have some processes run long enough to
>> stall it a bit now and then.
>
> That is interesting. I was always under the impression that a tick
> was always 1/60 of a second. It never occurred to me that this was
> the standard vertical refresh of the monitors in use at the time.
>
> So are you sating that if I had a monitor that refreshed at say
> 120/sec, that there would then be (roughly) 120 ticks in a second?

But there weren't.  Remember, this is ancient history we're talking 
about, when the only Macs you could buy had a 512x342 monochrome screen 
built into the machine.



> Also, since processor load can influence real time statistics, but
> cannot influence the vertical refresh rate, wouldn't ticks then be
> the more accurate unit of measure?

That's a question better left for systems developers.  Here I'm relying 
only on what I've read, but it seems intuitive enough given that the 
clock on most mobos has its own chip and even its own battery, and that 
refresh rates today vary broadly by GPU type, shared load between GPU 
and on-board, bus variance, etc.


--
 Richard Gaskin
 Fourth World Systems
 Software Design and Development for the Desktop, Mobile, and the Web
 
 ambassa...@fourthworld.comhttp://www.FourthWorld.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


Re: function for greatest object in list less than or equal to a value

2015-10-12 Thread Bob Sneidar
That is interesting. I was always under the impression that a tick was always 
1/60 of a second. It never occurred to me that this was the standard vertical 
refresh of the monitors in use at the time.

So are you sating that if I had a monitor that refreshed at say 120/sec, that 
there would then be (roughly) 120 ticks in a second? Also, since processor load 
can influence real time statistics, but cannot influence the vertical refresh 
rate, wouldn't ticks then be the more accurate unit of measure?

Bob S


On Oct 12, 2015, at 10:41 , Richard Gaskin 
> wrote:

The choice of tying the ticks to retrace was perhaps a necessity in early Mac 
OS systems, relying as they did on preemptive multitasking. But that reliance 
also made it an inexact quantity:  by default the vertical retrace would happen 
60 times a second, but it was possible to have some processes run long enough 
to stall it a bit now and then.

___
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: function for greatest object in list less than or equal to a value

2015-10-12 Thread BNig
hh wrote
> [@Bernd: here a PONG to your PING.]
> 
> Obviously each list member has to be inspected once for the comparison.
> And each "smaller than"-member has to be inspected once again to find
> the maximum. There is no other way, this is a math fact.
> 
> Here is my solution, that seems to be pretty fast.
> 
> -- v is a real num, L is a list of real comma-delimites nums
> -- if L has NO member < v then return MINVAL (=your setting)
> -- Empty members are treated as 0 (doesn't harm, if all x>0)
> -- Pre-sorting of L gives no advantage.
> 
> function greatestMemberSmallerThan v,L
>put -10^15 into z[true] --> because max(empty)=0
>repeat for each item x in L
>   -- if x is empty then next repeat --> here not necessary
>   put comma & x after z[xv]
>end repeat
>return max( z[true] )
> end greatestMemberSmallerThan

Hermann, you know that math is my weak spot (among others) but whatever math
says in my code I don't touch every member of the list, in my case the
sorting has "touched" ever member and I can safely do my "binary search"
type of thing. Missing values are no problem but empty items would.

did you benchmark my snippet and yours say on a list of 10 items?

Kind regards
Bernd




--
View this message in context: 
http://runtime-revolution.278305.n4.nabble.com/function-for-greatest-object-in-list-less-than-or-equal-to-a-value-tp4697221p4697311.html
Sent from the Revolution - User mailing list archive at Nabble.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


Re: function for greatest object in list less than or equal to a value

2015-10-12 Thread hh
[@Bernd: here a PONG to your PING.]

Obviously each list member has to be inspected once for the comparison.
And each "smaller than"-member has to be inspected once again to find
the maximum. There is no other way, this is a math fact.

Here is my solution, that seems to be pretty fast.

-- v is a real num, L is a list of real comma-delimites nums
-- if L has NO member < v then return MINVAL (=your setting)
-- Empty members are treated as 0 (doesn't harm, if all x>0)
-- Pre-sorting of L gives no advantage.

function greatestMemberSmallerThan v,L
   put -10^15 into z[true] --> because max(empty)=0
   repeat for each item x in L
  -- if x is empty then next repeat --> here not necessary
  put comma & x after z[x

Re: function for greatest object in list less than or equal to a value

2015-10-12 Thread Geoff Canyon
function greatestLessThan pList,V
   sort items of pList descending numeric
   sort items of pList by each >= V
   return item 1 of pList
end greatestLessThan

100,000 items, two sorts, and consistently returns in under 0.075 seconds
on my Mac:

on mouseUp
   repeat 10
  put random(1000),"" after L
   end repeat
   put the long seconds into T
   get greatestLessThan(L,500)
   put (the long seconds - T) && it into fld 3
end mouseUp

1,000,000 items generally returns in about .95 seconds
10,000,000 items came back in 10.5 seconds, so against my intuition, this
things seems to scale fairly linearly.
___
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: function for greatest object in list less than or equal to a value

2015-10-12 Thread Mike Doub
Pass by reference and you can eliminate a memcopy on the initial function call.

-= Mike 



On Oct 12, 2015, 9:11 PM, at 9:11 PM, Geoff Canyon  wrote:
>Not quite as concise, but this function is about 3x faster:
>
>function greatestLessThan pList,V
>   put empty into R
>   repeat for each item i in pList
>  if i < V and i > R then put i into R
>   end repeat
>   return R
>end greatestLessThan
>___
>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: function for greatest object in list less than or equal to a value

2015-10-12 Thread Geoff Canyon
Not quite as concise, but this function is about 3x faster:

function greatestLessThan pList,V
   put empty into R
   repeat for each item i in pList
  if i < V and i > R then put i into R
   end repeat
   return R
end greatestLessThan
___
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: function for greatest object in list less than or equal to a value

2015-10-12 Thread Geoff Canyon
Sure, that's always an option for large data calls to functions.

On Mon, Oct 12, 2015 at 9:20 PM, Mike Doub  wrote:

> Pass by reference and you can eliminate a memcopy on the initial function
> call.
>
> -= Mike
>
>
>
> On Oct 12, 2015, 9:11 PM, at 9:11 PM, Geoff Canyon 
> wrote:
> >Not quite as concise, but this function is about 3x faster:
> >
> >function greatestLessThan pList,V
> >   put empty into R
> >   repeat for each item i in pList
> >  if i < V and i > R then put i into R
> >   end repeat
> >   return R
> >end greatestLessThan
> >___
> >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: function for greatest object in list less than or equal to a value

2015-10-12 Thread dunbarx
@LCMark

I ran a test with wide variations of the number of items for the "sort" vs.
the "repeat" method. The "sort" method is always faster, at least up to
several million items.

Craig Newman



--
View this message in context: 
http://runtime-revolution.278305.n4.nabble.com/function-for-greatest-object-in-list-less-than-or-equal-to-a-value-tp4697221p4697349.html
Sent from the Revolution - User mailing list archive at Nabble.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


Re: function for greatest object in list less than or equal to a value

2015-10-12 Thread Geoff Canyon
The first sort is straightforward, and turns "1,2,4,5,6,8,9" into
"9,8,6,5,4,2,1"

The second sort splits that into two groups. The first group is the entries
that fail the test, the second is the entries that pass the test. Since the
test is ">=", 5 passes the test and goes in the second group. That makes
the result "4,2,1,9,8,6,5"

I think it could also be written as

sort items of pList by not (each < V)

But I'm guessing that would be a bit slower (maybe not)

It would probably be clearer to do this:


sort items of pList numeric
sort items of pList by each < V
return item -1 of pList

But that adds the burden of getting item -1, i.e. parsing the whole list a
final time. If the engine were optimized for negative items it wouldn't
matter much, but since it's not, I inverted the rest of the statements to
be able to get item 1 at the end.

On Mon, Oct 12, 2015 at 11:06 PM, J. Landman Gay 
wrote:

> On 10/12/2015 6:24 PM, Geoff Canyon wrote:
>
>> function greatestLessThan pList,V
>> sort items of pList descending numeric
>> sort items of pList by each >= V
>> return item 1 of pList
>> end greatestLessThan
>>
>
> Clever. How come it works when V is in the list, when you're asking for
> ">="  ? Seems like V should be toward the front of the second sort.
>
> I used this:
>
>   put greatestLessthan("1,2,4,5,6,8,9",5)
>
> The 5 was at the end of the second sorted list, even though it's equal to
> V.
>
> --
> 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
>
___
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: function for greatest object in list less than or equal to a value

2015-10-12 Thread dunbarx
Geoff.


I find this slower than the sort method. By about 30%.


Craig



-Original Message-
From: Geoff Canyon 
To: How to use LiveCode 
Sent: Mon, Oct 12, 2015 9:11 pm
Subject: Re: function for greatest object in list less than or equal to a value


Not quite as concise, but this function is about 3x faster:

function
greatestLessThan pList,V
   put empty into R
   repeat for each item i in
pList
  if i < V and i > R then put i into R
   end repeat
   return
R
end
greatestLessThan
___
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: function for greatest object in list less than or equal to a value

2015-10-12 Thread J. Landman Gay

On 10/12/2015 6:24 PM, Geoff Canyon wrote:

function greatestLessThan pList,V
sort items of pList descending numeric
sort items of pList by each >= V
return item 1 of pList
end greatestLessThan


Clever. How come it works when V is in the list, when you're asking for 
">="  ? Seems like V should be toward the front of the second sort.


I used this:

  put greatestLessthan("1,2,4,5,6,8,9",5)

The 5 was at the end of the second sorted list, even though it's equal to V.

--
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


Re: function for greatest object in list less than or equal to a value

2015-10-12 Thread Geoff Canyon
Interesting. What exact code did you use? Here's mine:

on mouseUp
   repeat 100
  put random(10),"" after L
   end repeat
   put the long seconds into T
   get greatestLessThanSort(L,5)
   put "sort" && (the long seconds - T) && it into fld 3

   put the long seconds into T
   get greatestLessThanRepeat(L,5)
   put cr & "repeat" && (the long seconds - T) && it after fld 3
end mouseUp

function greatestLessThanSort pList,V
   sort items of pList descending numeric
   sort items of pList by each >= V
   return item 1 of pList
end greatestLessThanSort

function greatestLessThanRepeat pList,V
   put empty into R
   repeat for each item i in pList
  if i < V and i > R then put i into R
   end repeat
   return R
end greatestLessThanRepeat

And the results:

sort 0.916539 49879
repeat 0.331764 49879

On Tue, Oct 13, 2015 at 12:07 AM,  wrote:

> Geoff.
>
>
> I find this slower than the sort method. By about 30%.
>
>
> Craig
>
>
>
> -Original Message-
> From: Geoff Canyon 
> To: How to use LiveCode 
> Sent: Mon, Oct 12, 2015 9:11 pm
> Subject: Re: function for greatest object in list less than or equal to a
> value
>
>
> Not quite as concise, but this function is about 3x faster:
>
> function
> greatestLessThan pList,V
>put empty into R
>repeat for each item i in
> pList
>   if i < V and i > R then put i into R
>end repeat
>return
> R
> end
> greatestLessThan
> ___
> 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


function for greatest object in list less than or equal to a value

2015-10-11 Thread Dr. Hawkins
It would be nice to have an intrinsic for this, but I just read the entire
function list . . .

I need to find the largest number in a list which is smaller than a
specified value.

e.g., for the list "1,3,4,7,9" and 5, the largest such value would be 4.

In a spreadsheet, I could use use vlookup() and specified the index as the
row to return.

In a database, could " SELECT MAX(myVar) WHERE myVar<5;", and so forth

I  had thought that FILTER could take a]b arbitrary function, but
apparently not. t It could conceivably use a rgexp, but calling a regex for
numeric comparison "ugly" would be polite

I'm not seeing anyhing better than lo better than looping through at the
moment
-- 
Dr. Richard E. Hawkins, Esq.
(702) 508-8462
___
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: function for greatest object in list less than or equal to a value

2015-10-11 Thread Peter M. Brigham
function getMaxLessThan tList,maxVal
   repeat for each item i in tList
  if i < maxVal then put i & comma after outList
   end repeat
   return max(item 1 to -1 of outList)
end getMaxLessThan

Simple and fast.

-- Peter

Peter M. Brigham
pmb...@gmail.com
http://home.comcast.net/~pmbrig

On Oct 11, 2015, at 12:15 PM, Dr. Hawkins wrote:

> It would be nice to have an intrinsic for this, but I just read the entire
> function list . . .
> 
> I need to find the largest number in a list which is smaller than a
> specified value.
> 
> e.g., for the list "1,3,4,7,9" and 5, the largest such value would be 4.
> 
> In a spreadsheet, I could use use vlookup() and specified the index as the
> row to return.
> 
> In a database, could " SELECT MAX(myVar) WHERE myVar<5;", and so forth
> 
> I  had thought that FILTER could take a]b arbitrary function, but
> apparently not. t It could conceivably use a rgexp, but calling a regex for
> numeric comparison "ugly" would be polite
> 
> I'm not seeing anyhing better than lo better than looping through at the
> moment
> -- 
> Dr. Richard E. Hawkins, Esq.
> (702) 508-8462
> ___
> 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: function for greatest object in list less than or equal to a value

2015-10-11 Thread dunbarx
Richard,


How about this, given a comma delimited list (say "1,1,2,2,3,3,4,4,5,6,7,8,9") 
in a field 1, with a "5" as your index?



on mouseUp
  answer findItemLessThanIndex(fld 1,"5")
end mouseUp


function findItemLessThanIndex tData,tIndex
   put comma & tIndex after tData
   sort items of tData numeric
   return  item itemOffset("5",tData) -1 of tData
end findItemLessThanIndex




-Original Message-
From: Dr. Hawkins 
To: How to use LiveCode 
Sent: Sun, Oct 11, 2015 12:16 pm
Subject: function for greatest object in list less than or equal to a value


It would be nice to have an intrinsic for this, but I just read the
entire
function list . . .

I need to find the largest number in a list which
is smaller than a
specified value.

e.g., for the list "1,3,4,7,9" and 5, the
largest such value would be 4.

In a spreadsheet, I could use use vlookup()
and specified the index as the
row to return.

In a database, could " SELECT
MAX(myVar) WHERE myVar<5;", and so forth

I  had thought that FILTER could
take a]b arbitrary function, but
apparently not. t It could conceivably use a
rgexp, but calling a regex for
numeric comparison "ugly" would be polite

I'm
not seeing anyhing better than lo better than looping through at the
moment
--

Dr. Richard E. Hawkins, Esq.
(702)
508-8462
___
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: function for greatest object in list less than or equal to a value

2015-10-11 Thread J. Landman Gay

On 10/11/2015 9:26 PM, dunb...@aol.com wrote:

function findItemLessThanIndex tData,tIndex
put comma & tIndex after tData
sort items of tData numeric
return  item itemOffset("5",tData) -1 of tData
end findItemLessThanIndex


I thought of that too, but it fails if tIndex isn't in the list. The 
example list was: "1,3,4,7,9" and the target limit was 5.


I couldn't see a way that avoids looping through all the values.

--
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