|
|
@ -289,7 +289,7 @@ lval* lval_eval_sexpr(lval* v) { |
|
|
|
} |
|
|
|
|
|
|
|
/* Call builtin with operator */ |
|
|
|
lval* result = builtin_op(v, f->sym); |
|
|
|
lval* result = builtin(v, f->sym); |
|
|
|
lval_del(f); |
|
|
|
return result; |
|
|
|
|
|
|
@ -338,6 +338,27 @@ lval* lval_take(lval* v, size_t i) { |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
lval* builtin(lval* a, char* func) { |
|
|
|
|
|
|
|
/* Check for builtin functions */ |
|
|
|
if (strcmp("list", func) == 0) {return builtin_list(a);} |
|
|
|
if (strcmp("head", func) == 0) {return builtin_head(a);} |
|
|
|
if (strcmp("tail", func) == 0) {return builtin_tail(a);} |
|
|
|
if (strcmp("join", func) == 0) {return builtin_join(a);} |
|
|
|
if (strcmp("eval", func) == 0) {return builtin_eval(a);} |
|
|
|
|
|
|
|
/* Check for operators */ |
|
|
|
if (strstr("+-*/%^", func) || |
|
|
|
strcmp("min", func) == 0 || strcmp("max", func) == 0) { |
|
|
|
return builtin_op(a, func); |
|
|
|
} |
|
|
|
|
|
|
|
lval_del(a); |
|
|
|
return lval_err("Unknown function!"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
lval* builtin_op(lval* a, char* op) { |
|
|
|
|
|
|
|
/* Ensure all arguments are numbers */ |
|
|
|