35 lines
591 B
ChaiScript
35 lines
591 B
ChaiScript
|
|
def add(x, y)
|
|
{
|
|
return x + y;
|
|
}
|
|
|
|
assert_equal(2, add.get_arity());
|
|
|
|
var b = bind(add, 2, _);
|
|
|
|
assert_equal(1, b.get_arity());
|
|
|
|
var c = bind(b, 3);
|
|
|
|
assert_equal(0, c.get_arity());
|
|
|
|
assert_equal(6, b(4));
|
|
assert_equal(5, c());
|
|
|
|
def concat2(a,b,c,d)
|
|
{
|
|
return to_string(a) + to_string(b) + to_string(c) + to_string(d);
|
|
}
|
|
|
|
var d = bind(concat2, _, " Hello ", _, " World");
|
|
assert_equal(2, d.get_arity());
|
|
|
|
assert_equal("1 Hello 3 World", d(1,3));
|
|
|
|
var e = bind(`<`, _, 5);
|
|
var types = e.get_param_types();
|
|
assert_equal(2, types.size());
|
|
assert_equal(true, types[0].bare_equal(bool_type));
|
|
|