-
Notifications
You must be signed in to change notification settings - Fork 8
Falseyness
JavaScript, it is well known, has a strange notion of falseyness. So when I was designing PogoScript I wondered if there would be an appetite for it being less strange.
In particular, I thought Ruby had the nicest semantics for falseyness, that is, only nil and false itself were false and nothing else.
In fact every language has a different notion of falseyness, which surprised me because having written plenty of code in plenty of languages, I thought I would have noticed this.
So I looked into a number of other languages and found some
surprising results. What I was looking for were values that would not pass as a true condition to an if statement/expression.
Lisp: nil and the empty list (), which are actually the same thing in Lisp. Lisp doesn't have a "false".
Scheme: #f. Unlike Lisp, the empty list is not false, interestingly Scheme doesn't have a nil.
JavaScript: empty string "", 0, null, undefined and false.
Ruby: false and nil.
Python: empty string "", 0, None and empty string [].
C/C++: NULL and FALSE which are really just macros for 0.
Objective C: same as C/C++, but also defines NO as false.
C# and Java: false. Not even null is allowed in an if statement.
Go: false. Same as C# and Java.
Smalltalk: false.
Personally I like Ruby's, it offers a nice cross between Smalltalk and Lisp. But given that some very popular languages are also weird, and that PogoScript is running on JavaScript I think I'll stick to JavaScript semantics.
According to the documentation, you can have Closure Compiler add the sourceMappingURL to the bottom of the script with something like this:
--output_wrapper "%output%
//# sourceMappingURL=output.js.map"being added to your call. Not that you cannot use "\n" here, and you need a newline literal. On a Linux shell this works just fine (if you're inside of quotes when you press enter, the command doesn't get executed).