diff --git a/include/chaiscript/dispatchkit/bootstrap.hpp b/include/chaiscript/dispatchkit/bootstrap.hpp index 6be8a1bf..5156050c 100644 --- a/include/chaiscript/dispatchkit/bootstrap.hpp +++ b/include/chaiscript/dispatchkit/bootstrap.hpp @@ -406,7 +406,7 @@ namespace chaiscript m->add(fun(&dispatch::Dynamic_Object::get_attrs), "get_attrs"); m->add(fun(&dispatch::Dynamic_Object::get_attr), "get_attr"); - m->eval("def Dynamic_Object::clone() { auto new_o := Dynamic_Object(this.get_type_name()); for_each(this.get_attrs(), bind(fun(new_o, x) { new_o.get_attr(x.first) = x.second; }, new_o, _) ); return new_o; }"); + m->eval("def Dynamic_Object::clone() { auto new_o := Dynamic_Object(this.get_type_name()); for_each(this.get_attrs(), bind([](new_o, x) { new_o.get_attr(x.first) = x.second; }, new_o, _) ); return new_o; }"); m->add(fun(&has_guard), "has_guard"); m->add(fun(&get_guard), "get_guard"); diff --git a/include/chaiscript/language/chaiscript_parser.hpp b/include/chaiscript/language/chaiscript_parser.hpp index f8452ff5..dbf3631b 100644 --- a/include/chaiscript/language/chaiscript_parser.hpp +++ b/include/chaiscript/language/chaiscript_parser.hpp @@ -1119,7 +1119,11 @@ namespace chaiscript size_t prev_stack_top = m_match_stack.size(); - if (Keyword("fun")) { + //if (Keyword("fun")) { + if (Char('[')) { + if (!Char(']')) { + throw exception::eval_error("Closure list not currently supported", File_Position(m_line, m_col), *m_filename); + } retval = true; if (Char('(')) { diff --git a/include/chaiscript/language/chaiscript_prelude.hpp b/include/chaiscript/language/chaiscript_prelude.hpp index ca0a5853..b96aba41 100644 --- a/include/chaiscript/language/chaiscript_prelude.hpp +++ b/include/chaiscript/language/chaiscript_prelude.hpp @@ -305,10 +305,10 @@ def string::find_last_not_of(list) : is_type(list, "string") { \n\ int(find_last_not_of(this, list, -1)); \n\ } \n\ def string::ltrim() { \n\ - drop_while(this, fun(x) { x == ' ' || x == '\t' || x == '\r' || x == '\n'}); \n\ + drop_while(this, [](x) { x == ' ' || x == '\t' || x == '\r' || x == '\n'}); \n\ } \n\ def string::rtrim() { \n\ - reverse(drop_while(reverse(this), fun(x) { x == ' ' || x == '\t' || x == '\r' || x == '\n'})); \n\ + reverse(drop_while(reverse(this), [](x) { x == ' ' || x == '\t' || x == '\r' || x == '\n'})); \n\ } \n\ def string::trim() { \n\ ltrim(rtrim(this)); \n\ diff --git a/unittests/assign_const.chai b/unittests/assign_const.chai index ff6a8c3d..7b2ede58 100644 --- a/unittests/assign_const.chai +++ b/unittests/assign_const.chai @@ -1,2 +1,2 @@ -assert_throws("Mismatched types in equation, lhs is const.", fun() { 1 = 2 } ); -assert_throws("Mismatched types in equation, lhs is const.", fun() { 1 + 2 = 2 } ); +assert_throws("Mismatched types in equation, lhs is const.", []() { 1 = 2 } ); +assert_throws("Mismatched types in equation, lhs is const.", []() { 1 + 2 = 2 } ); diff --git a/unittests/const_range_test.chai b/unittests/const_range_test.chai index 5ebb5808..d8840f36 100644 --- a/unittests/const_range_test.chai +++ b/unittests/const_range_test.chai @@ -1,4 +1,4 @@ //If the following succeeds, the test passes -"Hello World".for_each(fun(x) { print(x) } ) +"Hello World".for_each([](x) { print(x) } ) diff --git a/unittests/eval_error.chai b/unittests/eval_error.chai index b2737a11..54eef2c4 100644 --- a/unittests/eval_error.chai +++ b/unittests/eval_error.chai @@ -34,6 +34,6 @@ def while_doing() } } -auto f = fun() { while_doing(); } +auto f = []() { while_doing(); } assert_equal(get_eval_error(f).call_stack.size(), 16) diff --git a/unittests/for_each_range.chai b/unittests/for_each_range.chai index 3a31fc02..7af3025d 100644 --- a/unittests/for_each_range.chai +++ b/unittests/for_each_range.chai @@ -1,3 +1,3 @@ auto v = {1,2,3}; auto r = range(v); -for_each(r, fun(x) { assert_equal(true, x>0); } ) +for_each(r, [](x) { assert_equal(true, x>0); } ) diff --git a/unittests/function_introspection.chai b/unittests/function_introspection.chai index 335dc1af..e58beb6e 100644 --- a/unittests/function_introspection.chai +++ b/unittests/function_introspection.chai @@ -67,10 +67,10 @@ auto group = group_guard.get_contained_functions(); assert_equal(true, group[0].has_guard()) assert_equal(false, group[1].has_guard()) -assert_throws("Function does not have a guard", fun() { group[0].get_guard(); } ); -assert_throws("Function does not have a guard", fun() { without_guard.get_guard(); } ); +assert_throws("Function does not have a guard", []() { group[0].get_guard(); } ); +assert_throws("Function does not have a guard", []() { without_guard.get_guard(); } ); auto guard = with_guard.get_guard(); assert_equal(false, guard.has_guard()); -assert_throws("Function does not have a guard", fun() { guard.get_guard(); } ); +assert_throws("Function does not have a guard", []() { guard.get_guard(); } ); diff --git a/unittests/invalid_function_assignment.chai b/unittests/invalid_function_assignment.chai index 99b098db..69ff5cab 100644 --- a/unittests/invalid_function_assignment.chai +++ b/unittests/invalid_function_assignment.chai @@ -1 +1 @@ -assert_throws("Illegal const function assignment", fun() { clone = `-` } ); +assert_throws("Illegal const function assignment", []() { clone = `-` } ); diff --git a/unittests/invalid_function_reassignment.chai b/unittests/invalid_function_reassignment.chai index 784372ac..d688a2a9 100644 --- a/unittests/invalid_function_reassignment.chai +++ b/unittests/invalid_function_reassignment.chai @@ -1 +1 @@ -assert_throws("Invalid function reassignment", fun() { auto x = 5; x = `-`; } ); +assert_throws("Invalid function reassignment", []() { auto x = 5; x = `-`; } ); diff --git a/unittests/lambda.chai b/unittests/lambda.chai index 9b717ec5..f2bd3db1 100644 --- a/unittests/lambda.chai +++ b/unittests/lambda.chai @@ -1,2 +1,2 @@ -auto bob = fun(x) { x + 1 } +auto bob = [](x) { x + 1 } assert_equal(4, bob(3)); diff --git a/unittests/malformed_inline_map.chai b/unittests/malformed_inline_map.chai index 618033d5..1cd8acf5 100644 --- a/unittests/malformed_inline_map.chai +++ b/unittests/malformed_inline_map.chai @@ -1,2 +1,2 @@ -assert_throws("Parse failure", fun() { eval("{\"hello\":5,\"j\",\"k\"}") } ); +assert_throws("Parse failure", []() { eval("{\"hello\":5,\"j\",\"k\"}") } ); diff --git a/unittests/multiline.chai b/unittests/multiline.chai index 0676d0c7..52a29122 100644 --- a/unittests/multiline.chai +++ b/unittests/multiline.chai @@ -4,6 +4,6 @@ auto x = {1, 2, assert_equal(1, x[0]) auto y = map(x, - fun(x) { x + 1 }) + [](x) { x + 1 }) assert_equal(2, y[0]) diff --git a/unittests/operators_float.chai b/unittests/operators_float.chai index 3f693786..7dcf6293 100644 --- a/unittests/operators_float.chai +++ b/unittests/operators_float.chai @@ -13,4 +13,4 @@ assert_equal(0, i -= i) assert_equal(3, j *= 1.5) assert_equal(1.5, j /= 2) assert_equal(2.5, j += 1) -assert_throws("No modulous for float", fun() { k % 2 } ); +assert_throws("No modulous for float", []() { k % 2 } ); diff --git a/unittests/reflection_test.chai b/unittests/reflection_test.chai index a35649e1..9db37a92 100644 --- a/unittests/reflection_test.chai +++ b/unittests/reflection_test.chai @@ -28,7 +28,7 @@ def my_fun() assert_equal(true, my_fun.has_parse_tree()); assert_equal(false, `+`.has_parse_tree()); -assert_throws("Function does not have a parse tree", fun() { `+`.get_parse_tree(); } ); +assert_throws("Function does not have a parse tree", []() { `+`.get_parse_tree(); } ); auto parsetree := my_fun.get_parse_tree();