From ded08b6e1e13a0ef9479c4c527d6bcffabe81c45 Mon Sep 17 00:00:00 2001 From: Andrew Chambers Date: Sun, 1 Dec 2019 14:34:41 +1300 Subject: [PATCH] Add truthy? to core. --- src/boot/boot.janet | 1 + test/suite0.janet | 3 +++ 2 files changed, 4 insertions(+) diff --git a/src/boot/boot.janet b/src/boot/boot.janet index ec98a691..9418e60d 100644 --- a/src/boot/boot.janet +++ b/src/boot/boot.janet @@ -102,6 +102,7 @@ (defn indexed? "Check if x is an array or tuple." [x] (def t (type x)) (if (= t :array) true (= t :tuple))) +(defn truthy? "Check if x is truthy." [x] (if x true false)) (defn true? "Check if x is true." [x] (= x true)) (defn false? "Check if x is false." [x] (= x false)) (defn nil? "Check if x is nil." [x] (= x nil)) diff --git a/test/suite0.janet b/test/suite0.janet index 98205fb0..b13ee819 100644 --- a/test/suite0.janet +++ b/test/suite0.janet @@ -314,5 +314,8 @@ (assert (= y 1) "regression #137 (5)") (assert (= z 2) "regression #137 (6)") +(assert (= true ;(map truthy? [0 "" true @{} {} [] '()])) "truthy values") +(assert (= false ;(map truthy? [nil false])) "non-truthy values") + (end-suite)