Rebol [ Title: "Pif" Purpose: {Polymorphic If} Author: "Ladislav Mecir" Date: 2/2/2000 File: %pif.r Category: [General] ] pif: func [[throw catch] { Polymorphic If lazy evaluation no default (use True guard instead) If/Either compatibility: guard checking (unset not allowed) non-logic guards allowed block checking (after a guard only a block allowed) computed blocks allowed Return working Exit working Break working } args [block!] /local res ] [ either unset? first res: do/next args [ if not empty? args [ ; invalid guard throw make error! [script no-arg pif condition] ] ] [ either first res [ either block? first res: do/next second res [ do first res ] [ ; not a block throw make error! [ script expect-arg pif block [block!] ] ] ] [ pif second do/next second res ] ] ] { Examples: sign: func [x] [ pif [ negative? x [-1] zero? x [0] true [1] ] ] for i 1 10 1 [ print i pif [ i = 6 [break] ] ] 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"] x = 2 [print "Second"] x = 3 [print "Third"] x = 4 [print "Fourth"] true [print "Default"] ] ] }