Jump to content

Call a function: Difference between revisions

Line 3,668:
 
=={{header|langur}}==
There are 3 ways to call a function in langur.
User-defined and built-in functions can be called using parentheses.
 
Built-in functions can also be called using an "unbounded list," which ends at a line return, EOF, closing parenthesis, curly brace, or square bracket, or before a comma preceding a line return.
 
=== parentheses ===
You can always call a function using parentheses.
<syntaxhighlight lang="langur">.x()
#<syntaxhighlight call user-defined function<lang="langur">x()/syntaxhighlight>
 
<syntaxhighlight lang="langur">write(.key, ": ", .value)
# call built-in with parentheses</syntaxhighlight>
 
<syntaxhighlight lang="langur">.xwrite(somestring)/syntaxhighlight>
=== unbounded lists ===
<syntaxhighlight lang="langur">write .key, ": ", .value
# call built-in with unbounded list</syntaxhighlight>
 
=== unbounded argument lists ===
<syntaxhighlight lang="langur">writeln "numbers: ", join ", ", [.a1, .a2, .a3, .a4]
In statement context, you can call a function with an unbounded list of arguments.
# unbounded lists on writeln and join
# later function join takes remaining arguments</syntaxhighlight>
 
<syntaxhighlight lang="langur">writeln "numbers: "a, join("b, ", [.a1, .a2, .a3, .a4]), " === "c</syntaxhighlight>
# unbounded list on writeln
# join using parentheses so it doesn't take remaining arguments</syntaxhighlight>
 
=== forwarding operator ===
<syntaxhighlight lang="langur">val .sum = foldfrom(
When passing a single argument, you can use the forwarding operator.
fn(.sum, .i, .c) { .sum + number(.c, 36) * .weight[.i] },
0,
pseries len .code,
split .code,
)
# split, pseries, and len using unbounded lists, ending before comma preceding line return</syntaxhighlight>
 
<syntaxhighlight lang="langur">fora .key-> in sort(keys .tests) {len
# passes a to the len() function</syntaxhighlight>
...
}
# unbounded list on keys bounded by closing parenthesis of sort</syntaxhighlight>
 
=={{header|Latitude}}==
990

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.