Hi Joel,

How about this variation of Ladislav's function?

pif: func [
        [throw]
    {polymorphic if with lazy evaluation and minimal checking}
    args [block!]
] [
    result: false
    while [not empty? args] [
        args: do/next args
                either all [
                        not unset? first args
                        first args
                ][
                        args: first second args
            break
                ][
                        args: skip second args 1
                ]
        ]
        if args [do args]
]

testcase: func [a b] [
    pif [
        a < b [print [a "<" b]]
        a = b [print [a "=" b]]
        a > b [print [a ">" b]]
    ]
]

paranoid: func [a b] [
    pif [
        a <= 0 [return 0]
        b <= 0 [return 0]
    ]
    print "Computing now!"
]


>> testcase 2 3
2 < 3
>> testcase 2 1
2 > 1
>> testcase 5 5
5 = 5
>> paranoid 4 6
Computing now!
>> paranoid 4 -6
== 0
>> paranoid -4 6
== 0

Cheers,
Eric

Reply via email to