|
Pages: [1]
|
 |
|
Author
|
Topic: IF or EITHER as a function (Read 399 times)
|
RebolBert
Guest
|
How could I write in REBOL this piece of Scheme code : (define x 1) ((if (< x 5) + *) 3 4) => 7 ((if (< x 5) + *) 3 4) is more concise than (if (< x 5) (+ 3 4) (* 3 4)) or either x < 5 [3 + 4] [3 * 4] (but maybe less readable ?)
|
|
|
|
|
Logged
|
|
|
|
|
Graham
|
this factors out the operator, but introduces a variable instead
op: either x < 5 [:add][:multiply] op 3 4
|
|
|
|
|
Logged
|
|
|
|
|
Gabriele
|
do either x < 5 [:add] [:multiply] 3 4
|
|
|
|
|
Logged
|
|
|
|
|
Graham
|
Ahh... I thought I tried that first and got an error, but I see it works 
|
|
|
|
|
Logged
|
|
|
|
RebolBert
Guest
|
>> x: 1 == 1 >> do either x < 5 ['add]['multiply] 3 4 == 7 Thanks for the solution, as readable as the Schem(atic) one -_- Great power of Rebol !
|
|
|
|
« Last Edit: June 22, 2006, 12:29:58 PM by Bert »
|
Logged
|
|
|
|
|
|
Pages: [1]
|
|
|
 |