From: Elijah Cohen Date: Wed, 13 Nov 2024 18:20:48 +0000 (-0600) Subject: more combinators in demo, deprecated 'if' statement X-Git-Url: https://git.eli173.com/?a=commitdiff_plain;h=652211ba8979c7b40bf4b9b428b22e07f5b6260f;p=klapaucius more combinators in demo, deprecated 'if' statement --- diff --git a/demos.kl b/demos.kl index 6514650..941e2a7 100644 --- a/demos.kl +++ b/demos.kl @@ -1,6 +1,18 @@ (def CC (B (C B (C B cdr)) (B (Phi cons) (C B car)))) (def D (B B)) +(def T (C I)) +(def V (B C T)) +(def O (S I)) +(def M (S I I)) +(def Q (C B)) +(def L (C B M)) +(def G (B B C)) +(def E (B (B B B))) +(def R (B B T)) +(def H (B W (B C))) +(def U (L O)) +(def F (E T T E T)) (def and (B W (B C) I)) (def or (S I I)) diff --git a/src/builtins.c b/src/builtins.c index c38a0c9..e79fd1c 100644 --- a/src/builtins.c +++ b/src/builtins.c @@ -136,8 +136,6 @@ char* lookup_builtin(Sexpr* b) { return CORE_CAR_STR; case CORE_CDR: return CORE_CDR_STR; - case CORE_IF: - return CORE_IF_STR; case CORE_EQ: return CORE_EQ_STR; case CORE_NOT: diff --git a/src/builtins/core.c b/src/builtins/core.c index 71ae600..1774fe3 100644 --- a/src/builtins/core.c +++ b/src/builtins/core.c @@ -75,25 +75,6 @@ Sexpr* c_cdr(Sexpr* b, Sexpr* rest, Sexpr* env) { sexpr_free(b); return ret; } -Sexpr* c_if(Sexpr* b, Sexpr* rest, Sexpr* env) { - if(CORE_IF_ARGS != u64_get_num_args(b)) - return cons(b, rest); - Sexpr* args = b->value.b.args; - - Sexpr* cond = eval(clone(car(cdr(cdr(args)))), env); - if(unquote(cond)->type != NIL) { - Sexpr* truthy = clone(car(cdr(args))); - sexpr_free(cond); - sexpr_free(b); - return cons(truthy, rest); - } - else { - Sexpr* falsy = clone(car(args)); - sexpr_free(cond); - sexpr_free(b); - return cons(falsy, rest); - } -} Sexpr* c_eq(Sexpr* b, Sexpr* rest, Sexpr* env) { if(CORE_EQ_ARGS != u64_get_num_args(b)) return cons(b, rest); @@ -268,8 +249,6 @@ Sexpr* x_core_dispatch(Sexpr* b, Sexpr* rest, Sexpr* env) { return c_car(b, rest, env); case CORE_CDR: return c_cdr(b, rest, env); - case CORE_IF: - return c_if(b, rest, env); case CORE_EQ: return c_eq(b, rest, env); case CORE_NOT: @@ -300,7 +279,6 @@ Sexpr* load_core_env(Sexpr* env) { load_builtin(CORE_CONS_STR, (CORE_PREFIX << 8) | CORE_CONS, env); load_builtin(CORE_CAR_STR, (CORE_PREFIX << 8) | CORE_CAR, env); load_builtin(CORE_CDR_STR, (CORE_PREFIX << 8) | CORE_CDR, env); - load_builtin(CORE_IF_STR, (CORE_PREFIX << 8) | CORE_IF, env); load_builtin(CORE_EQ_STR, (CORE_PREFIX << 8) | CORE_EQ, env); load_builtin(CORE_NOT_STR, (CORE_PREFIX << 8) | CORE_NOT, env); load_builtin(CORE_ATOM_STR, (CORE_PREFIX << 8) | CORE_ATOM, env); diff --git a/src/builtins/core.h b/src/builtins/core.h index 7ccc08e..760afb6 100644 --- a/src/builtins/core.h +++ b/src/builtins/core.h @@ -20,25 +20,22 @@ #define CORE_CDR 0x03 #define CORE_CDR_ARGS 1 #define CORE_CDR_STR "cdr" -#define CORE_IF 0x04 -#define CORE_IF_ARGS 3 -#define CORE_IF_STR "if" -#define CORE_EQ 0x05 +#define CORE_EQ 0x04 #define CORE_EQ_ARGS 2 #define CORE_EQ_STR "eq" -#define CORE_NOT 0x06 +#define CORE_NOT 0x05 #define CORE_NOT_ARGS 1 #define CORE_NOT_STR "not" -#define CORE_ATOM 0x07 +#define CORE_ATOM 0x06 #define CORE_ATOM_ARGS 1 #define CORE_ATOM_STR "atom" -#define CORE_REST 0x08 +#define CORE_REST 0x07 #define CORE_REST_ARGS 2 #define CORE_REST_STR "rest" -#define CORE_UNQUOTE 0x09 +#define CORE_UNQUOTE 0x08 #define CORE_UNQUOTE_ARGS 1 #define CORE_UNQUOTE_STR "unquote" -#define CORE_APPLYN 0x0a +#define CORE_APPLYN 0x09 #define CORE_APPLYN_ARGS 3 #define CORE_APPLYN_STR "applyn"