* Maxim Olivier-Adlhoch <[EMAIL PROTECTED]> [031128 11:41]: > > print does not return any value,
Yeah, I know, I will probable have to use a tmp word, test it and use a default return value. > I had to work around that in encompass... (hence the /silent refinement) > > you can build up a function which returns no value: > > a: func [data][ > ; do what you want with data > return unset 'data > ] > > the above is not really usefull but if you want to free the memory used up by data > (cause each word in a function keeps its value in between each function call), then > this is one way of ensuring it does not hang around. > > ladislav and gabrielle might correct me if I'm wrong. > > > -MAx > --- > "You can either be part of the problem or part of the solution, but in the end, > being part of the problem is much more fun." > > > > -----Original Message----- > > From: Tim Johnson [mailto:[EMAIL PROTECTED] > > Sent: Friday, November 28, 2003 2:38 PM > > To: [EMAIL PROTECTED] > > Cc: [EMAIL PROTECTED] > > Subject: [REBOL] No return Value??? > > > > > > > > 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 <[EMAIL PROTECTED]> > > http://www.alaska-internet-solutions.com > > -- > > To unsubscribe from this list, just send an email to > > [EMAIL PROTECTED] with unsubscribe as the subject. > > > > > > -- > To unsubscribe from this list, just send an email to > [EMAIL PROTECTED] with unsubscribe as the subject. -- Tim Johnson <[EMAIL PROTECTED]> http://www.alaska-internet-solutions.com -- To unsubscribe from this list, just send an email to [EMAIL PROTECTED] with unsubscribe as the subject.