Make setq bind locally
This commit is contained in:
@@ -152,14 +152,14 @@ struct ucl_object *ucl_special_while(struct ucl_scope *scope, struct ucl_object
|
|||||||
struct ucl_object *ucl_special_setq(struct ucl_scope *scope, struct ucl_object *args) {
|
struct ucl_object *ucl_special_setq(struct ucl_scope *scope, struct ucl_object *args) {
|
||||||
// TODO: Check arguments
|
// TODO: Check arguments
|
||||||
struct ucl_object *sym = ucl_car(args);
|
struct ucl_object *sym = ucl_car(args);
|
||||||
struct ucl_scope *root_scope = ucl_scope_get_root(scope);
|
|
||||||
if (sym->type != UCL_TYPE_SYMBOL) {
|
if (sym->type != UCL_TYPE_SYMBOL) {
|
||||||
return ucl_error_create("First argument to setq must be a symbol");
|
return ucl_error_create("First argument to setq must be a symbol");
|
||||||
}
|
}
|
||||||
|
|
||||||
struct ucl_object *value = ucl_evaluate(scope, ucl_list_nth(args, 1));
|
struct ucl_object *value = ucl_evaluate(scope, ucl_list_nth(args, 1));
|
||||||
|
UCL_RET_IF_ERROR(value);
|
||||||
|
|
||||||
ucl_scope_put(root_scope, sym->symbol, value);
|
ucl_scope_put(scope, sym->symbol, value);
|
||||||
|
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -152,6 +152,10 @@ void test_setq(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void test_setq_from_function(void) {
|
void test_setq_from_function(void) {
|
||||||
|
response = eval("(setq bar 1)");
|
||||||
|
|
||||||
|
TEST_ASSERT_OBJ_INT_V(response, 1);
|
||||||
|
|
||||||
response = eval("(defun foo (a) (setq bar a))");
|
response = eval("(defun foo (a) (setq bar a))");
|
||||||
|
|
||||||
TEST_ASSERT_OBJ_SYMBOL_V(response, "foo");
|
TEST_ASSERT_OBJ_SYMBOL_V(response, "foo");
|
||||||
@@ -162,7 +166,7 @@ void test_setq_from_function(void) {
|
|||||||
|
|
||||||
response = eval("bar");
|
response = eval("bar");
|
||||||
|
|
||||||
TEST_ASSERT_OBJ_INT_V(response, 2);
|
TEST_ASSERT_OBJ_INT_V(response, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_lambda(void) {
|
void test_lambda(void) {
|
||||||
|
|||||||
Reference in New Issue
Block a user