Types¶
Comefrom0x10 has two types of variables, strings and numbers. The space operator coerces its operands to strings, where undefined
becomes the empty string:
2 2 # prints 22
'foo' undefined # prints "foo"
And mathematical operators coerce undefined
to zero:
2 + undefined # prints 2
Note
As in early JavaScript, undefined
is not reserved, it’s a perfectly fine variable name.
Being strongishly typed, however, Cf0x10 doesn’t try to make sense of nonsensical operations like adding strings to numbers:
2 + 2 # prints 4
2 + '2' # prints nothing
In the second line, the result of adding a string to a number is undefined
, so, as seen in Variables, it prints nothing at all.
Lists¶
As any Lisper knows, all data structures are just fancy forms of lists. In recent decades, however, a new movement, stringly-typed programming, has discovered that all lists are just fancy forms of strings. Cf0x10 embraces this movement, though there is a proposal to add list support, CUM 2: Lists.
Truthiness¶
As in C, Cf0x10 has no boolean type. Numbers are good enough:
0 # zero is falsy
1 # all other numbers are truthy
'' # empty strings are falsy
'false' # non-empty strings are truthy
1 / 0 # undefined is falsy
Next, we’ll exercise Cf0x10’s full complement of boolean operators to unlock this power.