make all numbers truthy

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

View File

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

View File

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