Skip to content

Why is the bool 'asNum' method not 'toNum'? #12

Answered by Calamity210
Calamity210 asked this question in Help
Discussion options

You must be logged in to vote

Its a great question, there are several differences between the two.

Firstly, it should be understood that the only false values in senegal are:

  • null
  • false
  • 0

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: "foo123". Even if a string was to assert that it contains nothing but numerical values, a c…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@danialgoodwin
Comment options

Answer selected by Calamity210
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
2 participants