Code: Select all
;Cool() instead of Bool() handles three cases (#True, #False and #NIL) instead of two.
;So "B" changed To "C"
;It is good for special cases or just for fun
#NIL=2 ; not in list - undefined, neither nor, both and
Macro Cool(expr, true=#True , false=#False)
(2- Bool((expr)=(true)) -Bool((expr)=(false)) * 2) - (Bool(true=false) * Bool((expr)<>(true)) *4)
EndMacro
;- thats all ---------------------------------------------------------------------------
; the following is only for Demo
a=42
b=21
c=2
Debug "--- one Parameter"
Debug ""
Debug Cool(#True) ;1 - #True is 1 : #False is 0 : The rest is #NIL
Debug Cool(#False) ;0
Debug Cool(#NIL) ;2
Debug Cool(c) ;2
Debug Cool(42) ;2
Debug ""
Debug Cool( a > b ) ;1
Debug Cool(42 < 21) ;0
Debug Cool("42" > "21") ;1
Debug Cool("42" < "21") ;0
Debug ""
Debug "--- two Parameter"
Debug ""
Debug Cool(a,42) ;1 - value = 42 - #True is 42
Debug Cool(b,42) ;2
Debug Cool(3*7,a) ;2
Debug Cool(a,6*7) ;1
Debug Cool(b*c,a) ;1
Debug ""
Debug "--- three Parameter --- the advantage over Bool()"
Debug ""
Debug Cool("42","42","21") ;true
Debug Cool("21","42","21") ;false
Debug Cool("36","42","21") ;not in list
Debug Cool("uweb" ,"young","old") ; special case ;-)
Debug ""
Debug Cool(42,42,21) ;1
Debug Cool(21,42,21) ;0 - value = 21 - #False is 21
Debug Cool(36,42,21) ;2
Debug Cool(3*7,42,21) ;0
Debug Cool(42,6*7,21) ;1
Debug Cool(6*7,42,21) ;1
Debug Cool(21,3*7,21) ;-1 - true=false=value
Debug Cool(36,3*7,21) ;-2 - true=false and value ist not in list