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

[REBOL] TECHNICAL ESSAY/CHALLENGE(s) - "Expression Based"? Re:(2)

From: al:bri:xtra at: 3-Oct-2000 0:22

This is a bit shorter, but still not as nice as the Rebol way as used in System and View. [ Rebol [ File: %Tally.r ] tally: make object! [ tot: 0 zero: does [tot: 0] up: func [/by n [number!]] [print "up!" tot: tot + either by [n] [1]] down: func [/by n [number!]] [print "down!" tot: tot - either by [n] [1]] now?: does [tot] ] bunchanums: [3 1 35 8 4 5 52 42 19 13 32 43 81 2 6 34 46] ; A better name for this function would be appreciated. mpc: func [Block [block!]] [ make path! compose Block ] ; A better name for this function would be appreciated. dr: func [Block [block!]] [ do reduce Block ] use [diffs] [ diffs: make tally [] evens: make tally [] odds: make tally [] foreach num bunchanums [ dr [mpc [diffs (either even? num ['up] ['down]) by] num] dr [mpc [(either even? num ['evens] ['odds]) up by] num] ] print ["diffs/now?" diffs/now?] print ["evens/now?" evens/now?] print ["odds/now?" odds/now?] ] ]
>> do %Tally.r
down! up! down! up! down! up! up! up! up! up! down! up! up! up! up! up! down! up! down! up! up! up! down! up! down! up! up! up! up! up! up! up! up! up! diffs/now? 26 evens/now? 226 odds/now? 200 AllenK has a better grasp of the ideal Rebol way to do this. But he says it is difficult to explain. More about this later, or you could pester Allen. :-) Andrew Martin While chatting to fellow Rebolians... ICQ: 26227169 http://members.nbci.com/AndrewMartin/ http://members.xoom.com/AndrewMartin/