diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2023-03-26 16:37:54 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2023-03-26 16:37:54 -0700 |
commit | ab59762e97c7f68f271fde7401d93c26bbbe7d6d (patch) | |
tree | ccde357039e09ec823b545aab369ae94308471f0 /arith.c | |
parent | d152f874b7096d6642a00b8237a94b6fd9991c00 (diff) | |
download | txr-ab59762e97c7f68f271fde7401d93c26bbbe7d6d.tar.gz txr-ab59762e97c7f68f271fde7401d93c26bbbe7d6d.tar.bz2 txr-ab59762e97c7f68f271fde7401d93c26bbbe7d6d.zip |
New function: arithp.
* lib.h (arithp): Declared.
(plus_s): Existing symbol declared.
* arith.c (arithp): New function.
* struct.h (special_slot): New enum member plus_m.
* struct.c (special_sym): Register plus_s together as
the [plus_m] entry of the array.
* tests/016/arith.tl
* tests/016/ud-arith.tl: Tests for arithp.
* txr.1: Documented.
* stdlib/doc-syms.tl: Updated.
Diffstat (limited to 'arith.c')
-rw-r--r-- | arith.c | 19 |
1 files changed, 18 insertions, 1 deletions
@@ -4362,6 +4362,23 @@ val numberp(val num) } } +val arithp(val obj) +{ + switch (type(obj)) { + case NUM: + case BGNUM: + case FLNUM: + case CHR: + case RNG: + return t; + default: + if (obj_struct_p(obj) && get_special_slot(obj, plus_m)) + return t; + } + + return nil; +} + val nary_op(val self, val (*bfun)(val, val), val (*ufun)(val self, val), struct args *args, val emptyval) @@ -4918,7 +4935,7 @@ void arith_init(void) reg_fun(intern(lit("floatp"), user_package), func_n1(floatp)); reg_fun(intern(lit("integerp"), user_package), func_n1(integerp)); reg_fun(intern(lit("numberp"), user_package), func_n1(numberp)); - + reg_fun(intern(lit("arithp"), user_package), func_n1(arithp)); reg_fun(signum_s, func_n1(signum)); |