make all numbers truthy

This commit is contained in:
2021-01-24 11:53:58 -07:00
parent 9cf520bd3a
commit d54297c373
2 changed files with 3 additions and 4 deletions

View File

@@ -225,7 +225,6 @@ class Prelude {
public static dynamic function truthy(v:Any) {
return switch (Type.typeof(v)) {
case TNull: false;
case TInt | TFloat: (v : Float) > 0;
case TBool: (v : Bool);
default:
// Empty strings are falsy

View File

@@ -81,8 +81,8 @@
(defun _testIf []
(Assert.equals true (if 1 true false))
(Assert.equals false (if 0 true false))
(Assert.equals false (if -1 true false))
(Assert.equals true (if 0 true false))
(Assert.equals true (if -1 true false))
(Assert.equals false (if null true false))
(Assert.equals true (if true true false))
(Assert.equals false (if false true false))
@@ -288,7 +288,7 @@
(for val [1 2 3 4 5 6 7 8]
(if (> val 6)
(break)
(if (% val 2)
(if !(= 0 (% val 2))
(continue)
val)))]
(Assert.equals 2 a)