Any - Function Summary
Summary:
Shortcut OR. Evaluates and returns the first value that is not FALSE or NONE.
Usage:
any block
Arguments:
block - Block of expressions (must be: block)
Description:
Evaluates each expression in a block until one of the
expressions returns a value other than NONE or FALSE, in which
case the value is returned. Otherwise, NONE will be returned.
print any [none none]
none |
print any [false none]
none |
print any [true none]
true |
time: 10:30
if any [time > 10:00 time < 11:00] [print "time is now"]
time is now |
No other expressions are evaluated beyond the point where
a successful value is found:
a: 0
any [none a: 2]
print a
2 |
a: 0
any [1 a: 2]
print a
0 |
day: 10
time: 9:45
ready: any [day > 5 time < 10:00 time: 12:00]
print time
9:45 |
Related:
all - Shortcut AND. Evaluates and returns at the first FALSE or NONE. and - Returns the first value ANDed with the second. or - Returns the first value ORed with the second.
User Comments:
-From: giesse_writeme.com 7-Dec-2000/2:46:46-8:00:
A very useful use for ANY is to set default values. For example,
if you have a word 'PORT that can hold a port number to use or
NONE if the default value should be used, you can write:
which will set 'PORT to 80 if it was NONE but will leave it untouched otherwise. The above is equivalent to:
port: either port [port] [80]
|
Using ANY in this case is much more convenient if you have more than one fallback value:
port: any [port fallback-port-1 fallback-port-2 80]
|
-From: giesse_writeme.com 7-Dec-2000/2:51-8:00:
Another use for ANY is to emulate a sequence of
if...elseif...elseif...else. Instead of writing:
either cond-1 [
code-1
] [
either cond-2 [
code-2
] [
either cond-3 [
][
...
]
]
]
|
it is possible to write:
any [
if cond-1 [
code-1
true ; in case code-1 returns FALSE or NONE
]
if cond-2 [
code-2
]
...
(default-code)
]
|
|