
EN: rebol.com -
rebol.org -
rebol.net -
FR: Rebol Documentation Project -
forum RebelBB -
rebol-france.org -
forum codeur -
Raccourci du mot OR. Evalue et retourne TRUE or NONE.
any block
block - Bloc d’expressions (type: block!)
Evalue chaque expression dans un bloc tant qu’une des expressions retourne une valeur différente de NONE ou FALSE, dans ce cas TRUE ou la valeur est retournée. Autrement NONE sera retourné.
print any [1 none] 1 print any [none 1] 1 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
Aucune autre expression n’est evaluée à partir du point où une valeur a été trouvée avec succès :
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
all - Raccourci du mot AND. Evalue et retourne TRUE ou NONE.
and - Retourne la première valeur ANDed avec la seconde.
or - Retourne la première valeur ORed avec la seconde.
-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:
port: any [port 80]
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) ]