From: Elijah Cohen Date: Tue, 15 Oct 2024 18:27:56 +0000 (-0500) Subject: changed z combintaor semantics, added range example X-Git-Url: https://git.eli173.com/?a=commitdiff_plain;h=d1914540d59166e3f55d4f1e533f7bac25aefbe4;p=klapaucius changed z combintaor semantics, added range example --- diff --git a/demos.kl b/demos.kl index 5ac7f56..2f1e5ec 100644 --- a/demos.kl +++ b/demos.kl @@ -1,5 +1,12 @@ (def D (B B)) -(def g (D S (C (eq 0) 1) (D S * (C B (C - 1))))) +(def fachelp (D S (C (eq 0) 1) (D S * (C B (C - 1))))) + +(def fac (Z fachelp)) + +(def rh (B B S (S (B (eq 0) car) cdr) (C B (Phi cons (B (C - 1) car) (Phi cons car cdr))))) + +(def range (S (C (eq 0) nil) (B (Z rh) (C cons nil)))) + +(def fph (B (S (Phi (eq nil) cdr car)) (C B (Phi cons (Phi + car (B car cdr)) (B cdr cdr))))) -(def fac (Z g)) \ No newline at end of file diff --git a/src/builtins/combinators.c b/src/builtins/combinators.c index cefc6dc..9b3f4d1 100644 --- a/src/builtins/combinators.c +++ b/src/builtins/combinators.c @@ -129,7 +129,9 @@ Sexpr* c_z(Sexpr* b, Sexpr* rest, Sexpr* env) { } Sexpr* args = b->value.b.args; Sexpr* g = clone(car(cdr(args))); - Sexpr* v = clone(car(args)); + Sexpr* v = eval(clone(car(args)), env); + // man that eval does a /lot/ for computation, + // need to think about what this implies sexpr_free(b); Sexpr* g2 = clone(g); Sexpr* z = from_opcode((COMB_PREFIX << 8) | COMB_Z);