Hi, Eric, you can never satisfy everyone ;-)

Rebol [
    Author: Ladislav Mecir
    Email: [EMAIL PROTECTED]
    File: %pif.r
    Comment: {
        I decided to throw out the default case for the sake of
higher compatibility with If and Either.
        If you want a default, simply use True as a condition.
    }
]

pif: func [[throw]
    {
        polymorphic if, minimum checking, no default, compatible
with:
        computed blocks,
        Return
        Exit
        Break
        non-logic conditions
    }
    args [block!]
] [
    if not unset? first args: do/next args [
        either first args [
            either block? first args: do/next second args[do first
args] [
                first args
            ]
        ] [
            pif second do/next second args
        ]
    ]
]

; Examples:

sign: func [x] [
    pif [
        x < 0 -1
        x = 0 0
        true 1
    ]
]

for i 1 10 1 [
    pif [
        i = 6 head insert next copy [print break] i
    ]
]

paranoic: func [s [string!]] [
    pif [
        find s "x" [return "x found"]
        true [return "x not found"]
    ]
   "Never get here"
]

no-value: func [x] [
    pif [
        x = 1 [print "First"]
        true [print "Second"]
    ]
]

; BTW, when I experimented with Break, I tried the following code:

for i 1 10 1 [
    while [ print i if i = 6 [break] false] []
]

; what would you expect it to do?

Regards,
    Ladislav

Reply via email to