(def D (B B))
-(def fachelp (D S (C (eq 0) 1) (D S * (C B (C - 1)))))
-(def fac (Z fachelp))
+(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 fph (B (S (Phi (eq nil) cdr car)) (C B (Phi cons (Phi + car (B car cdr)) (B cdr cdr)))))
+(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 CC (B (C B (C B cdr)) (B (Phi cons) (C B car))))
return cons(from_nil(), rest);
}
+Sexpr* c_rest(Sexpr* b, Sexpr* rest, Sexpr* env) {
+ // what kind of name is rest? need to reconsider
+ // but am making this a bit broader than it might need to be
+ // but this is the variadic thing, takes the first argument,
+ // and applies it to the rest
+ // e.g. (rest (nth 5) 1 2 3 4 5 6) -> 5
+ // !! also! this is weird and takes two args so as to not trigger when trying to define things(?)
+ // i.e. (def list (rest I)) works this way rather than the more straightforward implementation
+ if(CORE_REST_ARGS != u64_get_num_args(b))
+ return cons(b, rest);
+ Sexpr* args = b->value.b.args;
+ Sexpr* first_arg = eval(clone(car(cdr(args))), env);
+ Sexpr* second_arg = clone(car(args)); // uhh no eval? nah don't think so
+ Sexpr* newrest = cons(second_arg, rest);
+ sexpr_free(b);
+ return cons(first_arg, cons(from_quote(newrest), from_nil()));
+}
+
Sexpr* c_applyn(Sexpr* b, Sexpr* rest, Sexpr* env) {
// possible commentary for the future:
return c_not(b, rest, env);
case CORE_ATOM:
return c_atom(b, rest, env);
+ case CORE_REST:
+ return c_rest(b, rest, env);
case CORE_APPLYN:
return c_applyn(b, rest, env);
case CORE_DEF:
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);
+ load_builtin(CORE_REST_STR, (CORE_PREFIX << 8) | CORE_REST, env);
load_builtin(CORE_DEF_STR, (CORE_PREFIX << 8) | CORE_DEF, env);
load_builtin(CORE_EXIT_STR, (CORE_PREFIX << 8) | CORE_EXIT, env);
#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
//#include <unistd.h>
#include <editline/readline.h>
#include "builtins.h"
#include "sexpr.h"
#include "util.h"
-
+#include "config.h"
int main(int argc, char** argv) {
load_env(env);
while(argc > 1) {
- printf("ac/av: %d, %s\n", argc, argv[argc-1]);
// lol am i loading files back to front?
env = load_file(env, argv[argc-1]);
argc--;
}
+
+ // now i load the history?
+ char* histfile = getenv("HOME");
+ strcat(histfile, "/.config/klhist");
+ FILE* f = fopen(histfile, "r");
+ if(f) {
+ size_t s;
+ char* line = NULL;
+ while (getline(&line, &s, f) != -1) {
+ add_history(line);
+ free(line);
+ line = NULL;
+ }
+ fclose(f);
+ }
+ else {
+ printf("no histfile!?!?!?\n");
+ }
char* input = NULL;
while(1) {
if(input == NULL)
return 0;
add_history(input);
+ // add to histfile here
+ f = fopen(histfile, "a");
+ if(f) {
+ fprintf(f, "%s", input);
+ fclose(f);
+ }
+ //
Sexpr* in = parse(input);
if(in == NULL) {
ERR("bad input\n", "");
}
free(input);
}
+ free(histfile);
return 0;
}