1 and 0 are not true and false?

I kept getting an error in my program when it would check for the state of a button. So, I tested something…

set foo to 1
if foo then
	display dialog "True!"
end if

I get an error saying it can’t turn 1 into a boolean.

Seriously? I never noticed this before, and it completely floors me. I’m pretty sure this makes AppleScript the only language in the history of computer programming where true and false do not equal 1 and 0.

Hi,

it’s right, 1 is an integer number, to test a boolean value you must coerce it


set foo to 1
if (foo as boolean) then
	display dialog "True!"
end if

Unlike other languages, where true means “not zero”, AppleScript distinguishes numeric and booelan values

Hmm. I suppose for a strongly typed language like AppleScript, it would make more sense to require implicit casting this way. I’m just so used to C and PHP, that it baffled me that it didn’t automatically consider non-zero as true.