Hi Tim.

1. You can use unset? to check for words that do not return values .
 >> unset? print ""

== true
 >> if unset? print "" [result: "<<unset>>"]

2. If you need to assign the return value of the tested function to some 
local word, you can use set/any to avoid an error.

3. Why doesn't print return a value? Wel;l, I suspect that is because 
the purpose of print is to display its argument. If print were to return 
a value, it would not only be displaying its argument, it would force 
the REBOL interpreter to display print's return value as well. I.e. you 
would see a combination of the printed argument and print's return value 
on the screen. Instead of
 >> print ""

 >>

which is the expected result, for instance, you would get

 >> print_with_return: func [arg] [ print arg return true ]
 >> print_with_return ""

== true
 >>

BUT the argument to print was NOT "==true" it was "".

Hope this helps.

Elan


Tim Johnson wrote:

>Hello Rebols: 
>I've got a question:
>I've written a function called 'fetch, which has print
>stubs to help follow the flow control.
>
>If you evaluate 'print with 'fetch, no value is
>returned. 
>
>Can someone tell me why this is so?
>TIA
>tim
>
>(example and code follows)
>Example:
>  
>
>>>do %test-fetch.r
>>>      
>>>
>Script: "Untitled" (none)
>  
>
>>>fetch 'abc
>>>      
>>>
>type = 'word
>val is unset
>returning unset words as default value
>== none
>  
>
>>>fetch 'print
>>>      
>>>
>type = 'word
>val is set
>
>The code for 'fetch and helper function 'safe-reduce
>follows:
>REBOL[]
>; -------------------------------------------------------------------------------
>make object! [
>    default-value: none
>    set 'fetch func[ {safe data retrieval. Handles any value} 
>               val [any-type!] 
>               /seed {set default value} /deep {If block, reduce} 
>               /same {If unset return 'val}
>               /local tmp][
>               either word? val[
>                       print "type = 'word"
>                       either value? val[
>                               print "val is set"
>                               get val
>                               ][
>                               print "val is unset"
>                               either same[
>                                       print "returning unset word as the word"
>                                       val
>                                       ][
>                                       print "returning unset words as default value"
>                                       default-value
>                                       ]
>                               ]
>                       ][ ; any other type but 'word
>                       print ["type = " (type? val)]
>                       either block? val[
>                               either deep[
>                                       safe-reduce/deep val
>                                       ][
>                                       safe-reduce val
>                                       ] 
>                               ][
>                               val
>                               ]
>                       ] 
>               ]
>       ]
>; -------------------------------------------------------------------------------
>safe-reduce: function[blk[block!] {reduce block, leaving unset values}
>       /deep {reduce nested blocks} ][rblk _reduce][
>       dummy: func[val /deep][val]   ; pass    
>       ; below a function assignment using the prefix colon
>       _reduce: either deep[:safe-reduce][:dummy]      
>       ; since 'reduce is a native value (compiled into binary)
>       ;   try it first
>       either all[(not deep) (rblk: attempt[reduce blk])][
>               print "Used native 'reduce"
>               rblk
>               ][
>               print "Block with unset values, using 'safe-reduce"
>               rblk: make block! length? blk
>               foreach element blk[
>                       either word? element[
>                               either value? element[
>                                       append rblk (get element)
>                                       ][
>                                       append rblk element
>                                       ]
>                               ][
>                               either block? element[
>                                       append/only rblk _reduce/deep element
>                                       ][
>                                       append rblk element
>                                       ]
>                               ]
>                       ]
>               rblk
>               ]
>       ]
>  
>



-- 
To unsubscribe from this list, just send an email to
[EMAIL PROTECTED] with unsubscribe as the subject.

Reply via email to