stevedekorte/io — pull request #236 by kgksoft (2012-11-23 15:36:11+00:00)
Title: asBoolean message for flow operators

Add message "asBoolean" to Object.

Now flow operators IF and WHILE can be writen in c-style (good for business logic):

check := method(a,
if(a,
"true",
"false"
) println
)

check(0) //true
check(1) //true
check("") //true
check("not empty") //true
check(Date clone fromNumber(0)) //true
check(Date clone now) //true

Number asBoolean := method(
self != 0
)

Sequence asBoolean := method(
self size != 0
)

Date asBoolean := method(
self asNumber != 0
)

check(0) //false
check(1) //true
check("") //false
check("not empty") //true
check(Date clone fromNumber(0)) //false
check(Date clone now) //true

a := 10
while (a,
a println
a = a - 1
)
//now print 10,9,....,1
//before 10,9,...,1,0,-1,.....