1
0
Fork 0

Compare commits

..

No commits in common. "ad7a80752acce1c125d08b919793c183916203cc" and "b2acf41393a41a2a1e7f2b661e5d35818a3ccd7a" have entirely different histories.

5 changed files with 20 additions and 4 deletions

View File

@ -20,7 +20,6 @@ OBJS = \
LIBS = \
-r lib/lists.scm \
-r lib/logic.scm \
-r lib/io.scm \
-r lib/type_predicates.scm

View File

@ -1 +0,0 @@
(define (not x) (if x #false #true))

View File

@ -31,6 +31,8 @@ static struct Object *func_equal_QN(size_t args_count, struct Object **args_arra
static struct Object *func_number_TO_string(size_t args_count, struct Object **args_array);
static struct Object *func_string_TO_symbol(size_t args_count, struct Object **args_array);
static struct Object *func_symbol_TO_string(size_t args_count, struct Object **args_array);
// Logical operators
static struct Object *func_not(size_t args_count, struct Object **args_array);
// Arithmetic operators
static struct Object *func_EQ(size_t args_count, struct Object **args_array);
static struct Object *func_PLUS(size_t args_count, struct Object **args_array);
@ -60,6 +62,8 @@ static struct Object builtins[] = {
{ .type = TYPE_PROCEDURE, .procedure = { "number->string", func_number_TO_string } },
{ .type = TYPE_PROCEDURE, .procedure = { "string->symbol", func_string_TO_symbol } },
{ .type = TYPE_PROCEDURE, .procedure = { "symbol->string", func_symbol_TO_string } },
// Logical operators
{ .type = TYPE_PROCEDURE, .procedure = { "not", func_not } },
// Arithmetic operators
{ .type = TYPE_PROCEDURE, .procedure = { "=", func_EQ } },
{ .type = TYPE_PROCEDURE, .procedure = { "+", func_PLUS } },
@ -451,6 +455,18 @@ struct Object *func_symbol_TO_string(
return Object_new_string(symbol->s);
}
/*********************
* Logical operators *
*********************/
struct Object *func_not(
const size_t args_count,
struct Object **const args_array
) {
assert(args_count == 1);
return Object_new_boolean(Object_is_false(args_array[0]));
}
/************************
* Arithmetic operators *
************************/

View File

@ -89,7 +89,7 @@ struct Object *syntax_if(
struct Object *const environment
) {
assert(Object_is_pair(args));
struct Object *const cond_expr = args->pair.car;
struct Object *const cond = args->pair.car;
struct Object *const then_else_list = args->pair.cdr;
assert(then_else_list);
assert(Object_is_pair(then_else_list));
@ -100,7 +100,7 @@ struct Object *syntax_if(
struct Object *const else_branch = else_list->pair.car;
assert(OBJECT_IS_NULL(else_list->pair.cdr));
if (Object_is_false(eval(cond_expr, environment))) {
if (Object_is_false(cond)) {
return eval(else_branch, environment);
} else {
return eval(then_branch, environment);

View File

@ -26,6 +26,8 @@
(assert-true (procedure? (arcana/builtin 'number->string)))
(assert-true (procedure? (arcana/builtin 'string->symbol)))
(assert-true (procedure? (arcana/builtin 'symbol->string)))
; Logical operators
(assert-true (procedure? (arcana/builtin 'not)))
; Arithmetic operators
(assert-true (procedure? (arcana/builtin '=)))
(assert-true (procedure? (arcana/builtin '+)))