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

[REBOL] Small admin/report benchmark Re:

From: jeff:rebol at: 18-Sep-2000 9:18

Howdy, Joel:
> REBOL solution: > > My effort at producing a comparable REBOL script is > given next. I tried to use appropriate REBOLish > idioms to accomplish equivalent results. > > ============ begin REBOL script > #!/usr/local/bin/rebol -sq > > REBOL [] > > shells: copy make block! 5 > countshell: func [sh [string!] /local shr] [ > either none? shr: find shells sh [ > append shells reduce [sh 1] > ][ > change shr: next shr 1 + shr/1 > ] > ] > > foreach line read/lines %passwords.txt [ > countshell any [pick parse/all line ":" 7 "(none)"] > ] > > foreach [sh n] sort/skip shells 2 [ > n: to-string n > while [3 > length? n] [insert n " "] > print [n sh] > ] > ============= end REBOL script =============
Here's an alternate approach: (I skipped the sort for now..) REBOL [] shells: make block! 5 ;- no need for xtra copy do func [/sh/blk][ foreach line read/lines %passwords.txt [ sh: pick parse/all line ":" 7 append any [ select shells sh all [ append shells reduce [sh blk: copy []] blk ] ] sh ] blk: copy [backdrop 20.40.200 title "Shells" across] foreach [name sh] shells [ append blk compose [text (form length? sh) tab text (form name) return] ] view layout blk ] ;-- Note, we used rebol's NONE datatype to represent those ; whose shells are NONE. The approach taken is to use blocks to accumulate data and use length? and index? and what not to do the bean counting. I did cheat, though, and didn't bother sorting. Sorry! Reason why is the REBOL sort function is getting some much needed work done to it right now and the new sort function will make this kind of thing a lot easier. Might even use it to sort the actual layout produced! :-) Perl is likely faster for various tasks to REBOL, but REBOL makes many tasks much easier to do. It's all how you slice it. :) -jeff