From ed4163cfdebe64962b532951bb21b96882c347a8 Mon Sep 17 00:00:00 2001 From: Calvin Rose Date: Sun, 5 Jul 2020 23:24:07 -0500 Subject: [PATCH 1/4] Replace copyright on boot with system information. --- src/boot/boot.janet | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/boot/boot.janet b/src/boot/boot.janet index bb3f5138..0e82cd4f 100644 --- a/src/boot/boot.janet +++ b/src/boot/boot.janet @@ -2825,7 +2825,7 @@ (when (and (not *compile-only*) (or *should-repl* *no-file*)) (if-not *quiet* - (print "Janet " janet/version "-" janet/build " Copyright (C) 2017-2020 Calvin Rose")) + (print "Janet " janet/version "-" janet/build " " (os/which) "/" (os/arch))) (flush) (defn getprompt [p] (def [line] (parser/where p)) From 9d8e338a115dbd5a4a2157322f4e0274835df8d5 Mon Sep 17 00:00:00 2001 From: Calvin Rose Date: Sun, 5 Jul 2020 23:32:59 -0500 Subject: [PATCH 2/4] Update default repl prompt to match errors. --- src/boot/boot.janet | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/boot/boot.janet b/src/boot/boot.janet index 0e82cd4f..27d8e5ab 100644 --- a/src/boot/boot.janet +++ b/src/boot/boot.janet @@ -2829,7 +2829,7 @@ (flush) (defn getprompt [p] (def [line] (parser/where p)) - (string "janet:" line ":" (parser/state p :delimiters) "> ")) + (string "repl:" line ":" (parser/state p :delimiters) "> ")) (defn getstdin [prompt buf _] (file/write stdout prompt) (file/flush stdout) From 7478ad115fde587f9ad13cd12f9a0d9f005d15e9 Mon Sep 17 00:00:00 2001 From: Calvin Rose Date: Mon, 6 Jul 2020 09:19:10 -0500 Subject: [PATCH 3/4] Add `any?` predicate to core. This is the contrapositive to `every?`, and is analagous to `or` as `every?` is to `and`. --- src/boot/boot.janet | 9 +++++++++ test/suite0.janet | 20 +++++++++++--------- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/src/boot/boot.janet b/src/boot/boot.janet index 27d8e5ab..3fc8bcd0 100644 --- a/src/boot/boot.janet +++ b/src/boot/boot.janet @@ -1202,6 +1202,15 @@ (if x nil (set res x))) res) +(defn any? + "Returns the first truthy valye in ind, otherwise nil. + falsey value." + [ind] + (var res nil) + (loop [x :in ind :until res] + (if x (set res x))) + res) + (defn reverse! "Reverses the order of the elements in a given array or buffer and returns it mutated." diff --git a/test/suite0.janet b/test/suite0.janet index fa8352cf..c5ecc226 100644 --- a/test/suite0.janet +++ b/test/suite0.janet @@ -386,17 +386,14 @@ (assert (compare= 3 n3 (table/setproto @{:v 3} mynum)) "compare= poly") (assert (deep= (sorted @[4 5 n3 2] compare<) @[2 n3 4 5]) "polymorphic sort")) -(let [ - MAX_INT_64_STRING "9223372036854775807" +(let [MAX_INT_64_STRING "9223372036854775807" MAX_UINT_64_STRING "18446744073709551615" MAX_INT_IN_DBL_STRING "9007199254740991" NAN (math/log -1) INF (/ 1 0) MINUS_INF (/ -1 0) - compare-poly-tests - [ - [(int/s64 3) (int/u64 3) 0] + [[(int/s64 3) (int/u64 3) 0] [(int/s64 -3) (int/u64 3) -1] [(int/s64 3) (int/u64 2) 1] [(int/s64 3) 3 0] [(int/s64 3) 4 -1] [(int/s64 3) -9 1] @@ -409,11 +406,16 @@ [(+ 1 (int/u64 MAX_INT_IN_DBL_STRING)) (scan-number MAX_INT_IN_DBL_STRING) 1] [(int/s64 0) INF -1] [(int/u64 0) INF -1] [MINUS_INF (int/u64 0) -1] [MINUS_INF (int/s64 0) -1] - [(int/s64 1) NAN 0] [NAN (int/u64 1) 0] - ]] + [(int/s64 1) NAN 0] [NAN (int/u64 1) 0]]] (each [x y c] compare-poly-tests - (assert (= c (compare x y)) (string/format "compare polymorphic %q %q %d" x y c))) - ) + (assert (= c (compare x y)) (string/format "compare polymorphic %q %q %d" x y c)))) + +(assert (= nil (any? [])) "any? 1") +(assert (= nil (any? [false nil])) "any? 2") +(assert (= nil (any? [nil false])) "any? 3") +(assert (= 1 (any? [1])) "any? 4") +(assert (nan? (any? [nil math/nan nil])) "any? 5") +(assert (= true (any? [nil nil false nil nil true nil nil nil nil false :a nil])) "any? 6") (end-suite) From a1feb32a2f7f905daf635a8714e0bf089209a795 Mon Sep 17 00:00:00 2001 From: Calvin Rose Date: Mon, 6 Jul 2020 17:21:55 -0500 Subject: [PATCH 4/4] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 639de2cf..aeb32da7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ All notable changes to this project will be documented in this file. ## Unreleased - ??? +- Add `any?` predicate to core. - Add `jpm list-pkgs` subcommand to see which package aliases are in the listing. - Add `jpm list-installed` subcommand to see which packages are installed. - Add `math/int-min`, `math/int-max`, `math/int32-min`, and `math/int32-max` for getting integer limits.