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 > Hi all, > > It may just be my irredeemably old-fashioned mindset, > but everywhere I turn in Rebol I see the need to 'DO strings. > I've been ticked off before on the list about it and -- these > days -- I can normally see better approaches. > > But this little example has got me stumped. So I'm interested > in how the gurus would unDo my approach. > > The code below is the proof-of-concept, back of the envelope > idea that many data entry validation rules can be written to a > database as Rebol code. I just then need to write a single > apply-the-rules function, and add a little code for special cases, > rather than write buckets of repetitive code. But its got a > DO string in it. Any comments? > > --Colin > > ---------------------------------- > ;; rules table > ;; =========== > Rules: [ > "(Length? to-string *) > 0" "No data" > "date? *" "Bad date" > "(* - 14 ) < now/date" "Too old" > "specialcheck * " "Not special" > ] > > ;; prepare data field > ;; ============== > > RawValue: "5-122-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 mold LoadedValue) [ > print [LoadedValue " fails rule: " Message] > break > ] ; if > ] ; for > ---------------------------------- > -- > To unsubscribe from this list, please send an email to > [EMAIL PROTECTED] with "unsubscribe" in the > subject, without the quotes. > > -- To unsubscribe from this list, please send an email to [EMAIL PROTECTED] with "unsubscribe" in the subject, without the quotes.