[REBOL] fun with 'switch Re:
[EMAIL PROTECTED] wrote: retval: curr-func switch retval [none [print "val-none"] "abort" [print "val-abort"] Did you realize that the one above is a value of type word! and value "none", while your return value is a value of type none! ? You can solve this problem using reduce: switch none [ [none [print "found none"] [] == none switch 'none [ [none [print "found none"] [] found none switch none reduce [ [none [print "found none"] [] found none HTH, Gabriele. -- Gabriele Santilli [EMAIL PROTECTED] - Amigan - REBOL programmer Amiga Group Italia sez. L'Aquila -- http://www.amyresource.it/AGI/
[REBOL] fun with 'switch Re:(2)
Hi Elan, Hi Michael, 1. The Problem 2. The Solution 1. The Problem: retval: curr-func switch retval [none [print "val-none"] "abort" [print "val-abort"]] == none Notice that the == none is the value returned from 'switch, not the execution of the none block. To further illustrate: The reason it didn't work is that the none in a block, [none], is a value of type word! the none "as we know and love it" is a value of type none!: [snip] The same is true for other values/words such as false, true, on, off. That was very informative and well illustrated. I'd always thought of none, false etc as values in themselves, probably because my editor highlights the words. I knew (in the back of my mind) about none! etc but I never took the time to dissect the differences. I'm kinda surprised now that I hadn't run into this sort of problem earlier because of my prolific use of 'none. (BTW I now define $NONE as a standard variable in Perl along with $TRUE and $FALSE) 2. The Solution: [snip] To apply it to your problem. Simply reduce the block you pass to switch: retval: none == none switch retval reduce [none [print "val-none"] "abort" [print "val-abort"]] val-none Yep, that works (of course). Hope this helps, Very much so. Thanks. - Michael Jelinek
[REBOL] fun with 'switch Re:
Hi Michael, 1. The Problem 2. The Solution 1. The Problem: retval: curr-func switch retval [none [print "val-none"] "abort" [print "val-abort"]] == none Notice that the == none is the value returned from 'switch, not the execution of the none block. To further illustrate: The reason it didn't work is that the none in a block, [none], is a value of type word! the none "as we know and love it" is a value of type none!: type? first [none] == word! type? none == none! The none in brackets is not an evaluated none. Evaluation makes the word none a value-of-type-none! none. type? do [none] == none! type? do first [none] == none! The same is true for other values/words such as false, true, on, off. 2. The Solution: You can do or reduce (you get the value, or a block containing the value:) type? first reduce [none] == none! type? do [none] == none! To apply it to your problem. Simply reduce the block you pass to switch: retval: none == none switch retval reduce [none [print "val-none"] "abort" [print "val-abort"]] val-none Hope this helps, ;- Elan [: - )]