Hi Douglas,
a useful function, IMHO. I would suggest a more "goal oriented" approach
with the i-alt parameter:
i-alt [unset! block!] ; the alternate code to execute
; example code to be executed as alternate case
return either value? 'i-alt [do i-alt] [none]
Regards
Ladislav
> For your consideration:
>
> We are using a function called "vword" as
> (value of word in block or object)
> a safe, easy way to get unknown values out of blocks or objects.
>
> For instance:
> We store email/report templates in blocks, but can now safely skip
> any report details by leaving the items out of the template/blocks or
> providing a default value to use as a substitute.
>
> Another great use for "vword" is when decoding CGI gets or posts.
> You never really know what is in or out of CGI object,
> so vword is a safe way to interogate the object and get all the values.
>
>
> Try it out and let me know what you think.
>
> REBOL []
>
;---------------------------------------------------------------------------
> ---------
> vword: func [
> { Test to see if a certain word is found in a block or object.
> If so, the value of the word is returned. (Hence, the name vword.)
> If not, then the alternate value will be used.
> If the word is not found and no alternate value is supplied, none is
> returned.}
> item [block! object!] "The item containing the word you wish to search
> for."
> i-word [word!] "The word / attribute you wish to search for."
> i-alt [any-type!] "The alternate value to use if the word is not
> found."
> /local ret
> ][
> either block? item [
> if none? ret: select item :i-word [
> if (value? 'i-alt) [ret: i-alt]
> ]
> ][
> either none? ret: in item :i-word [
> if (value? 'i-alt) [ret: i-alt]
> ][
> ret: get in item :i-word
> ]
> ]
> return ret
> ]
>
;---------------------------------------------------------------------------
> ---------
>
>
>
> >> do %/e/scripts/rs/vword.r
> Script: "Untitled" (none)
> >> vword [a "APPLE" b "BANANA" c "CARROT"] 'd "DICED PEACHES"
> == "DICED PEACHES"
> >> vword [a "APPLE" b "BANANA" c "CARROT"] 'a "DICED PEACHES"
> == "APPLE"
> >> vword [a "APPLE" b "BANANA" c "CARROT"] 'b "DICED PEACHES"
> == "BANANA"
> >> vword [a "APPLE" b "BANANA" c "CARROT"] 'c "DICED PEACHES"
> == "CARROT"
> >> vword [a "APPLE" b "BANANA" c "CARROT"] 'e "DICED PEACHES"
> == "DICED PEACHES"
> >> vword [a "APPLE" b "BANANA" c "CARROT"] 'e
> == none
>
>
>
>
> >> print mold xo
>
> make object! [
> a: "ABC"
> b: "BOY"
> ]
> >> vword xo 'a "alpha"
> == "ABC"
> >> vword xo 'c "alpha"
> == "alpha"
> >> vword xo 'c
> == none
> >> vword xo 'c "alpha"
> == "alpha"
> >> vword xo 'b "alpha"
> == "BOY"
> >>
>
>
>
> Douglas Vos - EDS/GM-BSU Webmaster
> e-Mail: mailto:[EMAIL PROTECTED]
>
>
>
>