Switch lambda syntax over to [](){} format, to line up with C++11.

This commit is contained in:
Jonathan Turner
2011-09-24 13:31:24 -06:00
parent 784ca41270
commit 3765c23598
15 changed files with 23 additions and 19 deletions

View File

@@ -406,7 +406,7 @@ namespace chaiscript
m->add(fun(&dispatch::Dynamic_Object::get_attrs), "get_attrs"); m->add(fun(&dispatch::Dynamic_Object::get_attrs), "get_attrs");
m->add(fun(&dispatch::Dynamic_Object::get_attr), "get_attr"); 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(&has_guard), "has_guard");
m->add(fun(&get_guard), "get_guard"); m->add(fun(&get_guard), "get_guard");

View File

@@ -1119,7 +1119,11 @@ namespace chaiscript
size_t prev_stack_top = m_match_stack.size(); 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; retval = true;
if (Char('(')) { if (Char('(')) {

View File

@@ -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\ int(find_last_not_of(this, list, -1)); \n\
} \n\ } \n\
def string::ltrim() { \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\ } \n\
def string::rtrim() { \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\ } \n\
def string::trim() { \n\ def string::trim() { \n\
ltrim(rtrim(this)); \n\ ltrim(rtrim(this)); \n\

View File

@@ -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.", []() { 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 = 2 } );

View File

@@ -1,4 +1,4 @@
//If the following succeeds, the test passes //If the following succeeds, the test passes
"Hello World".for_each(fun(x) { print(x) } ) "Hello World".for_each([](x) { print(x) } )

View File

@@ -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) assert_equal(get_eval_error(f).call_stack.size(), 16)

View File

@@ -1,3 +1,3 @@
auto v = {1,2,3}; auto v = {1,2,3};
auto r = range(v); auto r = range(v);
for_each(r, fun(x) { assert_equal(true, x>0); } ) for_each(r, [](x) { assert_equal(true, x>0); } )

View File

@@ -67,10 +67,10 @@ auto group = group_guard.get_contained_functions();
assert_equal(true, group[0].has_guard()) assert_equal(true, group[0].has_guard())
assert_equal(false, group[1].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", []() { 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", []() { without_guard.get_guard(); } );
auto guard = with_guard.get_guard(); auto guard = with_guard.get_guard();
assert_equal(false, guard.has_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(); } );

View File

@@ -1 +1 @@
assert_throws("Illegal const function assignment", fun() { clone = `-` } ); assert_throws("Illegal const function assignment", []() { clone = `-` } );

View File

@@ -1 +1 @@
assert_throws("Invalid function reassignment", fun() { auto x = 5; x = `-`; } ); assert_throws("Invalid function reassignment", []() { auto x = 5; x = `-`; } );

View File

@@ -1,2 +1,2 @@
auto bob = fun(x) { x + 1 } auto bob = [](x) { x + 1 }
assert_equal(4, bob(3)); assert_equal(4, bob(3));

View File

@@ -1,2 +1,2 @@
assert_throws("Parse failure", fun() { eval("{\"hello\":5,\"j\",\"k\"}") } ); assert_throws("Parse failure", []() { eval("{\"hello\":5,\"j\",\"k\"}") } );

View File

@@ -4,6 +4,6 @@ auto x = {1, 2,
assert_equal(1, x[0]) assert_equal(1, x[0])
auto y = map(x, auto y = map(x,
fun(x) { x + 1 }) [](x) { x + 1 })
assert_equal(2, y[0]) assert_equal(2, y[0])

View File

@@ -13,4 +13,4 @@ assert_equal(0, i -= i)
assert_equal(3, j *= 1.5) assert_equal(3, j *= 1.5)
assert_equal(1.5, j /= 2) assert_equal(1.5, j /= 2)
assert_equal(2.5, j += 1) assert_equal(2.5, j += 1)
assert_throws("No modulous for float", fun() { k % 2 } ); assert_throws("No modulous for float", []() { k % 2 } );

View File

@@ -28,7 +28,7 @@ def my_fun()
assert_equal(true, my_fun.has_parse_tree()); assert_equal(true, my_fun.has_parse_tree());
assert_equal(false, `+`.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(); auto parsetree := my_fun.get_parse_tree();