Rebol3 Code Examplex


Extend your language

Add a feature or syntax extension to a language.

Rebol [
    title: "Rosetta code: Extend your language"
    file:  %Extend_your_language.r3
    url:   https://rosettacode.org/wiki/Extend_your_language
]

if2: func [cond1 cond2 both one two none][
    case [
        all [cond1 cond2] both
        cond1             one 
        cond2             two 
        true              none
    ]
]

loop 5 [
    printf ["a is" -3 ", b is" -3 ";" -15 " < 50"]
    if2 (a: random 100) < 50
        (b: random 100) < 50
        [[a b "both are"      ]]
        [[a b "only first is" ]]
        [[a b "only second is"]]
        [[a b "none is"       ]]   
]

Output:

a is 25, b is  3;       both are < 50
a is 86, b is 38; only second is < 50
a is 82, b is  6; only second is < 50
a is  1, b is 90;  only first is < 50
a is 38, b is 33;       both are < 50