In another programming language, I always liked using Boolean values in calculations to avoid if-statements. An example:

a = 2
b = 5 + (a==2)*5

Instead of

a = 2
if a==2 then
b = 10
else
b = 5
end

Unfortunately, arithmetic on Boolean values is not possible in Codea. I think I can solve this using a meta table, changing the _lt and _le (less than and less or equal then, respectively) functions. But I was wondering if any of you might know an easier way, making true equal 1 and false equal 0?

PS: Thank you @Ignatz, since your ebook taught me about meta tables.

@Ignatz How does that method work exactly? It doesn’t change the outcome (error) of (a==2)*4, since the == operator wouldn’t return my fake True.

@stevon8ter That sounds like an easy solution, odd I didn’t come up with that myself, doh! And choosing a short name for such a function, makes that it doesn’t get in the way too much.