Why is the bool 'asNum' method not 'toNum'? #12
-
Asked by @danialgoodwin (#11):
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Its a great question, there are several differences between the two. Firstly, it should be understood that the only false values in senegal are:
Anything else is considered to be true. That goes to say, any non-zero number is "true" while zero is "false". Why does that matter? All numbers are valid within a boolean context, take an if clause for example: if (1)
println("foo"); Is perfectly acceptable, you should expect foo to be printed. Thus, a numerical value can be used in place of a bool. This does not hold true for strings, a string cannot guarantee to be a numerical value, ie: To sum it up, a strings characters need to be converted to their expected numerical counterparts. Whereas senegal will interpret a number as a bool just fine. |
Beta Was this translation helpful? Give feedback.
Its a great question, there are several differences between the two.
Firstly, it should be understood that the only false values in senegal are:
Anything else is considered to be true. That goes to say, any non-zero number is "true" while zero is "false".
Why does that matter? All numbers are valid within a boolean context, take an if clause for example:
Is perfectly acceptable, you should expect foo to be printed. Thus, a numerical value can be used in place of a bool.
This does not hold true for strings, a string cannot guarantee to be a numerical value, ie:
"foo123"
. Even if a string was to assert that it contains nothing but numerical values, a c…