+(def CC (B (C B (C B cdr)) (B (Phi cons) (C B car))))
+
(def D (B B))
(def fac (Z (D S (C (eq 0) 1) (D S * (C B (C - 1))))))
-(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 range (S (C (eq 0) nil) (B (Z (B B S (S (B (eq 0) car) cdr) (C B (Phi cons (B (C - 1) car) (Phi cons car cdr))))) (C cons nil))))
(def reverse (B (Z (B (S (S (B (eq nil) cdr) car)) (C B (Phi cons (Phi cons (B car cdr) car) (B cdr cdr))))) (cons nil)))
-(def maphelp (B (S (S (B (eq nil) (B cdr cdr)) (B car cdr)) (C B (S (B cons car) (S (cons (Phi cons (S car (B car (B cdr cdr))) (B car cdr))) (B cdr (B cdr cdr))))))))
-
-(def nth-bad (B B B (Z (B (S (S (B (eq 1) car) (B car cdr))) (C B (Phi cons (C (B - car) 1) (B cdr cdr))))) cons))
-
(def nth (B (B car) (B (C I cdr) (C - 1))))
(def list (rest I))
-(def maphelp (B (S (S (B (eq nil) (3 cdr)) (B car cdr))) (C B (Phi cons car (Phi cons (Phi cons (S car (B car (3 cdr))) (B car cdr)) (4 cdr))))))
+(def len (B (Z (B (S (S (B (eq nil) cdr) car)) (C B (CC (+ 1) cdr)))) (cons 0)))
+(def map (B (B reverse) (B (B (Z (B (S (S (B (eq nil) (2 cdr)) (B car cdr))) (C B (S (B cons car) (Phi cons (Phi cons (S car (B (B car cdr) cdr)) (B car cdr)) (3 cdr))))))) (C (B B cons) (cons nil)))))
-(def CC (B (C B (C B cdr)) (B (Phi cons) (C B car))))
+(def fold (B (S (C (C (eq nil) nil) (Z (B (S (S (B (eq nil) (B cdr cdr)) (B car cdr))) (C B (S (B cons car) (Phi cons (S (S car (B car cdr)) (B car (2 cdr))) (3 cdr)))))))) cons))
\ No newline at end of file
return b;
}
else if(b->type == QUOTE) {
- // what even is this?
- return b;
+ // okay I am using this to cheat my quoting problems with lists and such...
+ // temporary fix hopefully
+ // also need to return to this for the other types...
+ if((b->value.q->type == CONS) ||
+ (b->value.q->type == SYM)) {
+ return clone(b);
+ }
+ // i might need to free something here? i'll come back later for it
+ return cons(clone(b->value.q), rest);
}
else if(b->type == UINT) {
uint64_t anx = (CORE_PREFIX << 8) | CORE_APPLYN;
// add to histfile here
f = fopen(histfile, "a");
if(f) {
- fprintf(f, "%s", input);
+ fprintf(f, "\n%s", input);
fclose(f);
}
//
#include "eval.h"
#include "builtins.h"
+void assert_eq(Sexpr* env, char* a, char* b) {
+ Sexpr* ap = parse(a);
+ Sexpr* av = eval(ap, env);
+ Sexpr* bp = parse(b);
+ Sexpr* bv = eval(bp, env);
+ Sexpr* iseq = equal(av, bv);
+ char* ao = sprint_sexpr(av);
+ char* bo = sprint_sexpr(bv);
+ if(iseq->type == T) {
+ printf("\033[32mpassed\033[0m\n");
+ }
+ else {
+ printf("\033[1m\033[31mfailed\033[0m\n");
+ }
+ sexpr_free(av);
+ sexpr_free(bv);
+ sexpr_free(iseq);
+ free(ao);
+ free(bo);
+ return;
+}
+
void run_eval_test(char* str) {
printf("<- %s\n", str);
Sexpr* env = init_dict();
}
+void many_asserts() {
+ Sexpr* env = init_dict();
+ env = load_env(env);
+
+ assert_eq(env, "(+ 4 4)", "8");
+ assert_eq(env, "(* 3 4)", "8");
+
+ sexpr_free(env);
+}
void run_tests(){
eval_tests();
+ many_asserts();
//memtest_eval();
//mem_testing();
//mem_parser();