1
0
Fork 0

Compare commits

...

2 Commits

Author SHA1 Message Date
Alex Kotov ad7a80752a
Rewrite func "not" in Lisp 2023-05-07 21:08:10 +04:00
Alex Kotov baf566703e
fix syntax "if" 2023-05-07 21:06:37 +04:00
5 changed files with 4 additions and 20 deletions

View File

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

1
lib/logic.scm Normal file
View File

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

View File

@ -31,8 +31,6 @@ 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);
@ -62,8 +60,6 @@ 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 } },
@ -455,18 +451,6 @@ 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 = args->pair.car;
struct Object *const cond_expr = 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(cond)) {
if (Object_is_false(eval(cond_expr, environment))) {
return eval(else_branch, environment);
} else {
return eval(then_branch, environment);

View File

@ -26,8 +26,6 @@
(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 '+)))