[REBOL] Re: To do or not to do?
From: sterling:rebol at: 28-Nov-2001 14:06
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? first 
Answer: because REBOL understands REBOL.
Now what's the difference between these two statements?
a: "print 10"
b: [print 10]
Great. So why do we want to use the second one?
Well, check this out.
type? second a
type? second b
How about this?
find a integer!
find b integer!
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
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.
[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
if error? try [loadedValue: first load/all Rawvalue]
;; apply rules
foreach [rule message] Rules [
if not (do replace/all copy rule 'item LoadedValue) [
print [LoadedValue " fails rule: " Message]
] ; 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?