Fixed not copying the default keyword args
This commit is contained in:
+4
-2
@@ -127,11 +127,13 @@ by the key 'from' and ends with the number defined in 'to'."
|
||||
(defun range-while (:keys from :defaults-to 0 to)
|
||||
"Returns a sequence of numbers starting with the number defined
|
||||
by the key 'from' and ends with the number defined in 'to'."
|
||||
(define result (list from))
|
||||
(define result (list (copy from)))
|
||||
(define head result)
|
||||
(mutate from (incr from))
|
||||
(while (< from to)
|
||||
(prog
|
||||
(append result (copy from))
|
||||
(mutate head (pair (first head) (pair (copy from) nil)))
|
||||
(define head (rest head))
|
||||
(mutate from (incr from))))
|
||||
result)
|
||||
|
||||
|
||||
+7
-1
@@ -1,4 +1,4 @@
|
||||
(when 1 (breakpoint))
|
||||
;; (when 1 (breakpoint))
|
||||
|
||||
;; (if (eval 1)
|
||||
;; (apply prog ((breakpoint)))
|
||||
@@ -7,3 +7,9 @@
|
||||
;; (if (eval 1)
|
||||
;; (eval (pair prog ((breakpoint)))))
|
||||
;; nil))
|
||||
|
||||
|
||||
(defun ! (n)
|
||||
(if (< n 2)
|
||||
1
|
||||
(* n (! (- 1 n)))))
|
||||
|
||||
Binary file not shown.
@@ -126,6 +126,7 @@ typedef enum {
|
||||
Built_In_Addition,
|
||||
Built_In_And,
|
||||
Built_In_Breakpoint,
|
||||
Built_In_Copy,
|
||||
Built_In_Define,
|
||||
Built_In_Division,
|
||||
Built_In_Equal,
|
||||
@@ -169,6 +170,7 @@ char* Built_In_Name_to_string(Built_In_Name name) {
|
||||
case Built_In_Addition: return "+";
|
||||
case Built_In_And: return "and";
|
||||
case Built_In_Breakpoint: return "breakpoint";
|
||||
case Built_In_Copy: return "copy";
|
||||
case Built_In_Define: return "define";
|
||||
case Built_In_Division: return "/";
|
||||
case Built_In_Equal: return "=";
|
||||
@@ -294,6 +296,7 @@ Ast_Node* create_ast_node_built_in_function(char* name) {
|
||||
else if (string_equal(name, ">=")) type = Built_In_Greater_Equal;
|
||||
else if (string_equal(name, "and")) type = Built_In_And;
|
||||
else if (string_equal(name, "breakpoint")) type = Built_In_Breakpoint;
|
||||
else if (string_equal(name, "copy")) type = Built_In_Copy;
|
||||
else if (string_equal(name, "define")) type = Built_In_Define;
|
||||
else if (string_equal(name, "error")) type = Built_In_Error;
|
||||
else if (string_equal(name, "eval")) type = Built_In_Eval;
|
||||
@@ -337,3 +340,9 @@ Ast_Node* create_ast_node_pair(Ast_Node* first, Ast_Node* rest) {
|
||||
node->value.pair->rest = rest;
|
||||
return node;
|
||||
}
|
||||
|
||||
Ast_Node* copy_ast_node(Ast_Node* n) {
|
||||
Ast_Node* target = new(Ast_Node);
|
||||
*target = *n;
|
||||
return target;
|
||||
}
|
||||
|
||||
+29
-3
@@ -77,7 +77,8 @@ Ast_Node* apply_arguments_to_function(Ast_Node* arguments, Function* function, E
|
||||
// if not set it and then add it to the array list
|
||||
define_symbol(
|
||||
create_ast_node_symbol(arguments->value.pair->first->value.keyword->identifier),
|
||||
arguments->value.pair->rest->value.pair->first, new_env);
|
||||
arguments->value.pair->rest->value.pair->first,
|
||||
new_env);
|
||||
|
||||
append_to_String_array_list(read_in_keywords, arguments->value.pair->first->value.keyword->identifier);
|
||||
|
||||
@@ -115,7 +116,7 @@ Ast_Node* apply_arguments_to_function(Ast_Node* arguments, Function* function, E
|
||||
if (!was_set) {
|
||||
define_symbol(
|
||||
create_ast_node_symbol(defined_keyword),
|
||||
function->keyword_arguments->values->data[i], new_env);
|
||||
copy_ast_node(function->keyword_arguments->values->data[i]), new_env);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -151,7 +152,6 @@ Ast_Node* apply_arguments_to_function(Ast_Node* arguments, Function* function, E
|
||||
result = eval_expr(function->body, new_env);
|
||||
}
|
||||
|
||||
free(new_env);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -456,8 +456,18 @@ Ast_Node* eval_expr(Ast_Node* node, Environment* env) {
|
||||
printf("Keyword: {");
|
||||
if (fun->value.function->keyword_arguments->next_index != 0) {
|
||||
printf("%s", fun->value.function->keyword_arguments->identifiers[0]);
|
||||
if (fun->value.function->keyword_arguments->values->data[0]) {
|
||||
printf(" (");
|
||||
print(fun->value.function->keyword_arguments->values->data[0]);
|
||||
printf(")");
|
||||
}
|
||||
for (int i = 1; i < fun->value.function->keyword_arguments->next_index; ++i) {
|
||||
printf(", %s", fun->value.function->keyword_arguments->identifiers[i]);
|
||||
if (fun->value.function->keyword_arguments->values->data[i]) {
|
||||
printf(" (");
|
||||
print(fun->value.function->keyword_arguments->values->data[i]);
|
||||
printf(")");
|
||||
}
|
||||
}
|
||||
}
|
||||
printf("}\n");
|
||||
@@ -808,6 +818,22 @@ Ast_Node* eval_expr(Ast_Node* node, Environment* env) {
|
||||
*target = *source;
|
||||
return target;
|
||||
}
|
||||
case Built_In_Copy: {
|
||||
if (arguments_length != 1)
|
||||
report_error(Error_Type_Wrong_Number_Of_Arguments);
|
||||
|
||||
if (evaluated_arguments->value.pair->first->type == Ast_Node_Type_Nil ||
|
||||
evaluated_arguments->value.pair->first->type == Ast_Node_Type_Keyword)
|
||||
{
|
||||
report_error(Error_Type_Type_Missmatch);
|
||||
}
|
||||
|
||||
Ast_Node* target = new(Ast_Node);
|
||||
Ast_Node* source = evaluated_arguments->value.pair->first;
|
||||
|
||||
*target = *source;
|
||||
return target;
|
||||
}
|
||||
case Built_In_Load: {
|
||||
if (arguments_length != 1)
|
||||
report_error(Error_Type_Wrong_Number_Of_Arguments);
|
||||
|
||||
Reference in New Issue
Block a user