Rebol Talk Forum  |  Getting Started  |  Newbie Help  |  Topic: IF or EITHER as a function
Pages: [1] Print
Author Topic: IF or EITHER as a function  (Read 399 times)
RebolBert
Guest


Email
IF or EITHER as a function
« on: June 20, 2006, 10:05:16 AM »

How could I write in REBOL this piece of Scheme code :
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
Full Member
***
Offline Offline

Posts: 113


View Profile
Re: IF or EITHER as a function
« Reply #1 on: June 20, 2006, 03:13:10 PM »

this factors out the operator, but introduces a variable instead

op: either x < 5 [:add][:multiply] op 3 4
Logged

Gabriele
Full Member
***
Offline Offline

Posts: 182


View Profile WWW
Re: IF or EITHER as a function
« Reply #2 on: June 21, 2006, 03:47:24 AM »

Code:
do either x < 5 [:add] [:multiply] 3 4
Logged
Graham
Full Member
***
Offline Offline

Posts: 113


View Profile
Re: IF or EITHER as a function
« Reply #3 on: June 21, 2006, 11:44:58 PM »

Ahh... I thought I tried that first and got an error, but I see it works Smiley
Logged

RebolBert
Guest


Email
Re: IF or EITHER as a function
« Reply #4 on: June 22, 2006, 12:24:35 PM »

Code:
>> 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] Print 
Rebol Talk Forum  |  Getting Started  |  Newbie Help  |  Topic: IF or EITHER as a function
Jump to:  

  
Quick Search...

Advanced search
  
Welcome, Guest. Please login or register.
Did you miss your activation email?
November 21, 2008, 01:50:29 PM
Username: Password: Session Length:
  

News: 01-09-08

Alpha version of REBOL 3 has been released!


  
2293 Posts in 593 Topics by 3749 Members
Latest Member: irotlydor

  Rebol Talk Forum | Powered by SMF 1.0.9.
© 2001-2005, Lewis Media. All Rights Reserved.

RT design by Defiant Pc