Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

[REBOL] Re: Loop with negative count

From: tim-johnsons:web at: 27-Dec-2006 19:20

* Peter Wood <pwawood-gmail.com> [061227 18:08]:
> Tim > > Why don't you protect your code against changes in undocumented > behaviour by either using:
Thanks. Of course. Also it could be redefined probably with some performance penalty. loop: func[count[integer!] code[block!]][ if positive? count[ system/words/loop count code ] ] ;; untested and "unbenchmarked", but not ;; "unfooledaroundwith" :-)
> Loop max 0 possible-negative-count > or > if positive? count [loop count [code]] > > I thought that there would be a time penalty in doing so but my tests > show it is hardly noticeable. (Providing my tests are correct). > > Regards > > Peter > > Test Source: > REBOl [] > > count: to integer! ask "Enter an integer - positive of negative: " > times: 100000 > > start: now/time/precise > loop times > [ > test: copy [] > loop count [append test "hello"] > ] > end: now/time/precise > print "test 1" > print [times "loops with count of " count " took: " subtract end start] > > start: now/time/precise > loop times > [ > test: copy [] > loop max 0 count [append test "hello"] > ] > end: now/time/precise > print "test 2" > print [times "loops with count of " count " took: " subtract end start] > > start: now/time/precise > loop times > [ > test: copy [] > if positive? count [loop count [append test "hello"]] > ] > end: now/time/precise > print "test 3" > print [times "loops with count of " count " took: " subtract end start] > > >> do %tt.r > Script: "Untitled" (none) > Enter an integer - positive of negative: 2 > test 1 > 100000 loops with count of 2 took: 0:00:02.404771 > test 2 > 100000 loops with count of 2 took: 0:00:02.365083 > test 3 > 100000 loops with count of 2 took: 0:00:02.41553 > >> do %tt.r > Script: "Untitled" (none) > Enter an integer - positive of negative: 8 > test 1 > 100000 loops with count of 8 took: 0:00:08.297555 > test 2 > 100000 loops with count of 8 took: 0:00:07.476637 > test 3 > 100000 loops with count of 8 took: 0:00:07.236025 > >> do %tt.r > Script: "Untitled" (none) > Enter an integer - positive of negative: -4 > test 1 > 100000 loops with count of -4 took: 0:00:00.843843 > test 2 > 100000 loops with count of -4 took: 0:00:00.683992 > test 3 > 100000 loops with count of -4 took: 0:00:00.466519 > >> do %tt.r > Script: "Untitled" (none) > Enter an integer - positive of negative: -55 > test 1 > 100000 loops with count of -55 took: 0:00:00.902979 > test 2 > 100000 loops with count of -55 took: 0:00:00.600534 > test 3 > 100000 loops with count of -55 took: 0:00:00.513414 > >> do %tt.r > Script: "Untitled" (none) > Enter an integer - positive of negative: 30 > test 1 > 100000 loops with count of 30 took: 0:00:37.077424 > test 2 > 100000 loops with count of 30 took: 0:00:33.583799 > test 3 > 100000 loops with count of 30 took: 0:00:38.293701 > > > Hello: > > on Core 2.6.2.4.2 > > > >>> help loop > > makes no reference to negative values for the 'count argument. > > > > consider the following console session > >>> test: [] > > == [] > >>> loop -4 [append test "hello"] > >>> test > > == [] > > > > Can we reliably expect that a negative argument will be ignored? > > thanks > > tim > > -- > > Tim Johnson <tim-johnsons-web.com> > > http://www.alaska-internet-solutions.com > > -- > > To unsubscribe from the list, just send an email to > > lists at rebol.com with unsubscribe as the subject. > > > > -- > To unsubscribe from the list, just send an email to > lists at rebol.com with unsubscribe as the subject.
-- Tim Johnson <tim-johnsons-web.com> http://www.alaska-internet-solutions.com