From ed541c0d83caff9e417a89bc4e6ae83ea22eb214 Mon Sep 17 00:00:00 2001 From: Teddy Date: Fri, 9 Aug 2013 20:28:37 +0800 Subject: bugfix on `lt` `gt` `eq`, added `number?` --- builtin.cpp | 8 ++++++++ builtin.h | 1 + eval.cpp | 1 + 3 files changed, 10 insertions(+) diff --git a/builtin.cpp b/builtin.cpp index 94fcd9b..a8091ba 100644 --- a/builtin.cpp +++ b/builtin.cpp @@ -1028,6 +1028,7 @@ BUILTIN_PROC_DEF(num_lt) { throw TokenError("a number", RUN_ERR_WRONG_TYPE); NumObj *last = static_cast(args->car), *opr; + args = TO_PAIR(args->cdr); for (; args != empty_list; args = TO_PAIR(args->cdr), last = opr) { if (!args->car->is_num_obj()) // not a number @@ -1052,6 +1053,7 @@ BUILTIN_PROC_DEF(num_gt) { throw TokenError("a number", RUN_ERR_WRONG_TYPE); NumObj *last = static_cast(args->car), *opr; + args = TO_PAIR(args->cdr); for (; args != empty_list; args = TO_PAIR(args->cdr), last = opr) { if (!args->car->is_num_obj()) // not a number @@ -1076,6 +1078,7 @@ BUILTIN_PROC_DEF(num_eq) { throw TokenError("a number", RUN_ERR_WRONG_TYPE); NumObj *last = static_cast(args->car), *opr; + args = TO_PAIR(args->cdr); for (; args != empty_list; args = TO_PAIR(args->cdr), last = opr) { if (!args->car->is_num_obj()) // not a number @@ -1417,6 +1420,11 @@ do { \ return new BoolObj(true); } +BUILTIN_PROC_DEF(is_number) { + ARGS_EXACTLY_ONE; + return new BoolObj(args->car->is_num_obj()); +} + BUILTIN_PROC_DEF(display) { ARGS_EXACTLY_ONE; printf("%s\n", args->car->ext_repr().c_str()); diff --git a/builtin.h b/builtin.h index b3aef77..7b2c6d1 100644 --- a/builtin.h +++ b/builtin.h @@ -262,6 +262,7 @@ BUILTIN_PROC_DEF(num_eq); BUILTIN_PROC_DEF(num_is_exact); BUILTIN_PROC_DEF(num_is_inexact); +BUILTIN_PROC_DEF(is_number); BUILTIN_PROC_DEF(bool_not); BUILTIN_PROC_DEF(is_boolean); diff --git a/eval.cpp b/eval.cpp index 1e78a8e..323c4c9 100644 --- a/eval.cpp +++ b/eval.cpp @@ -34,6 +34,7 @@ void Evaluator::add_builtin_routines() { ADD_BUILTIN_PROC("exact?", num_is_exact); ADD_BUILTIN_PROC("inexact?", num_is_inexact); + ADD_BUILTIN_PROC("number?", is_number); ADD_BUILTIN_PROC("not", bool_not); ADD_BUILTIN_PROC("boolean?", is_boolean); -- cgit v1.2.3-70-g09d2