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

[REBOL] No return Value???

From: tim:johnsons-web at: 28-Nov-2003 10:38

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 ] ] -- Tim Johnson <[tim--johnsons-web--com]>