[REBOL] Re: [none idiom found?] The best shortcut word for "not none?"
From: lmecir::mbox::vol::cz at: 4-Sep-2006 15:28
Ladislav Mecir napsal(a):
> Gregg wrote:
> If you use ANY and ALL, the result may be none. The mezzanine that
> converts a NONE result to a logic! value is FOUND?. I was going to
> suggest that we add an alternative, for cases like this, to improve
> the readability.
> found? all [a = b zero? a - b]
> That is, I've always read FOUND? as "was the value found?", as you
> would when using FIND.
> Now, whenever I think I've caught something that Carl missed, I try to
> think about it a bit before requesting a change, because it usually
> turns out that he's thought ahead of me and did the right thing; it
> just takes me a little time to see it sometimes. :)
> So, I was going to say a new word would be nice but, when I stopped to
> think about it a little more, I realized that all I need to do is read
> it in context. In the above example, it would mean "If it is found
> that all the following are true...", which couldn't be clearer (I
> tried to come up with better words, and couldn't).
> So, thanks Carl, and thanks to Ladislav for making me think about
> What else in REBOL have you found that makes you think, or read code,
> -- Gregg
> Thank you for highlighting this issue. You made me think about it once
> again and find out, that all problems may not be solved yet.
> My original need was to obtain a LOGIC! value, so the question is, if I
> shouldn't have used the TO function. Advantages:
> a) TO LOGIC! is twice as fast as the FOUND? mezzanine and faster than
> the NOT NONE? idiom
> b) TO LOGIC! clearly shows what my intention is
> c) TO LOGIC! does not behave exactly like FOUND? sometimes. See TO
> LOGIC! FALSE and the question is, which result is appropriate for the
> specific usage. For the above use this question is unimportant, but it
> may occur elsewhere.
there is one *important* difference I overlooked, though:
to logic! 0 ; == false
Speaking of which, I would prefer a different behaviour, what do you think?
> Even when we really need to know whether something has been found, the
> situation is complicated. See e.g.:
> found? select 1 reduce [1 none]
it should have been:
found? select [1 #[none]] 1
> , which is related to the question, what you expect when writing:
> switch/default 1 reduce [1 none] 
switch/default 1 [1 #[none]] 
, if you prefer