Call operator

The call operator () is used to extract elements by key from lists and to call functions.

For lists, the semantics are similar to the subscript operator [].

Yewslip> list = ["a" = 1, "b" = 2, "c" = 3, "c" = 4, "d" = 5]

Yewslip> print list("a"), list("c"), list("e")
1 3 (nil)

Yewslip> print list(["b", "c"])
[2, 3]

If several values have the same key, the element that comes first is always returned. Note how the nil value is assinged in the first "c" key in the following example.

Yewslip> list(["c", "e", "f"]) = [nil, 6, 7]

Yewslip> print list
[a = 1, b = 2, c = (nil), c = 4, d = 5, e = 6, f = 7]

For functions, a list of arguments is given in the parentheses.

Yewslip> func f(x, y) print "x =", x, "y =", y

Yewslip> f(1, 2)
x = 1 y = 2

Extra arguments given are not assigned to variables listed in the function definition. nil is assigned if not enough arguments are given.

Yewslip> f(1, 2, 3)
x = 1 y = 2

Yewslip> f(1)
x = 1 y = (nil)

Arguments may also be named in the function call to give them in a different order.

Yewslip> f("y" = 2, "x" = 1)
x = 1 y = 2

The special variable arg in the function contains the complete list of arguments.

Yewslip> func g() print arg

Yewslip> g(1, 2)
[1, 2]

The special call form value.argument may be used, which is equivalent to value("argument").

Yewslip> print list.a
1

Yewslip> f.foo
x = foo y = (nil)