From d791077e2583c94ebc0c9a3a8ac55e9f656217b3 Mon Sep 17 00:00:00 2001 From: Calvin Rose Date: Fri, 23 Nov 2018 15:33:49 -0500 Subject: [PATCH] Fix abstract? function. --- src/core/core.janet | 1 - src/core/corelib.c | 9 +++++++++ test/suite2.janet | 9 +++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/core/core.janet b/src/core/core.janet index 78ad1d5b..fc25d2dc 100644 --- a/src/core/core.janet +++ b/src/core/core.janet @@ -102,7 +102,6 @@ (defn function? "Check if x is a function (not a cfunction)." [x] (= (type x) :function)) (defn cfunction? "Check if x a cfunction." [x] (= (type x) :cfunction)) -(defn abstract? "Check if x an abstract type." [x] (= (type x) :abstract)) (defn table? [x] "Check if x a table." (= (type x) :table )) (defn struct? [x] "Check if x a struct." (= (type x) :struct)) (defn array? [x] "Check if x is an array." (= (type x) :array)) diff --git a/src/core/corelib.c b/src/core/corelib.c index e23c151e..ba01ad8d 100644 --- a/src/core/corelib.c +++ b/src/core/corelib.c @@ -148,6 +148,11 @@ static int janet_core_buffer(JanetArgs args) { JANET_RETURN_BUFFER(args, b); } +static int janet_core_is_abstract(JanetArgs args) { + JANET_FIXARITY(args, 1); + JANET_RETURN_BOOLEAN(args, janet_checktype(args.v[0], JANET_ABSTRACT)); +} + static int janet_core_scannumber(JanetArgs args) { const uint8_t *data; Janet x; @@ -320,6 +325,10 @@ static const JanetReg cfuns[] = { "converted to bytes via describe if they are not byte sequences. Returns " "the new symbol." }, + {"abstract?", janet_core_is_abstract, + "(abstract? x)\n\n" + "Check if x is an abstract type." + }, {"table", janet_core_table, "(table & kvs)\n\n" "Creates a new table from a variadic number of keys and values. " diff --git a/test/suite2.janet b/test/suite2.janet index 42477cb9..f2aa8090 100644 --- a/test/suite2.janet +++ b/test/suite2.janet @@ -82,5 +82,14 @@ (assert (deep= (string.find-all "e" "onetwothree") @[2 9 10]) "string.find-all 1") (assert (deep= (string.find-all "," "onetwothree") @[]) "string.find-all 2") +# Check if abstract test works +(assert (abstract? stdout) "abstract? stdout") +(assert (abstract? stdin) "abstract? stdin") +(assert (abstract? stderr) "abstract? stderr") +(assert (not (abstract? nil)) "not abstract? nil") +(assert (not (abstract? 1)) "not abstract? 1") +(assert (not (abstract? 3)) "not abstract? 3") +(assert (not (abstract? 5)) "not abstract? 5") + (end-suite)