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

[REBOL] Re: To do or not to do?

From: sterling:rebol at: 28-Nov-2001 14:06

NOOOOOOOOOO!!!! There is always a way not to do strings. :) Think about it this way... what are you building in your string that can be done? Answer: REBOL code. Why does this work? type? 5-Nov-2001 or this? type? first [10] Answer: because REBOL understands REBOL. Now what's the difference between these two statements? a: "print 10" b: [print 10] Not much. do a 10 do b 10 Great. So why do we want to use the second one? Well, check this out. type? second a char! type? second b integer! How about this? find a integer! == none find b integer! [10] This is useful stuff! You can change your code far easier this way than with strings. REBOL knows what you're dealing with and can help you out! Now, the super-quick translation of your code below. I re-arranged the blocks so that the replacement would be simple but you could just as easily do it using COMPOSE or BIND to get it done. I use the word 'item in the block to be the replacement instead of "*" since words are meant to be symbols and that's exactly what we need. Rules: [ [0 < length? to-string item] "No data" [date? item] "Bad date" [greater? now/date item - 14] "Too old" [specialcheck item] "Not special" ] ;; prepare data field ;; ============== RawValue: "5-12-2001" ;; bad date in this example Loadedvalue: "" if error? try [loadedValue: first load/all Rawvalue] [LoadedValue: RawValue] ;; apply rules ;; =========== foreach [rule message] Rules [ if not (do replace/all copy rule 'item LoadedValue) [ print [LoadedValue " fails rule: " Message] break ] ; if ] ; for I'm using a valid date here so it gets through more of the checks eventually failing because specialcheck is not defined. I hope this has helped you out. If you have any more questions about it, please ask... we all cringe here at REBOL HQ when we see the unnecessary use of DO with strings... you're always DOing REBOL code so why not start that way? Sterling