1
0
mirror of https://github.com/janet-lang/janet synced 2024-11-24 17:27:18 +00:00

Fix abstract? function.

This commit is contained in:
Calvin Rose 2018-11-23 15:33:49 -05:00
parent 2349e1a3be
commit d791077e25
3 changed files with 18 additions and 1 deletions

View File

@ -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))

View File

@ -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. "

View File

@ -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)