Call a function: Difference between revisions
→{{header|langur}}
Langurmonkey (talk | contribs) |
Langurmonkey (talk | contribs) |
||
(6 intermediate revisions by the same user not shown) | |||
Line 3,668:
=={{header|langur}}==
Functions are first-order, and may be passed around, whether user-defined or built-in.
There are 3 ways to call a function in langur.▼
=== parentheses ===
You can always call a function using parentheses.
<syntaxhighlight lang="langur"
x()
</syntaxhighlight>
<syntaxhighlight lang="langur"
write(somestring)
</syntaxhighlight>
=== unbounded argument lists ===
In statement context, you can call a function with an unbounded list of arguments.
<syntaxhighlight lang="langur"
writeln a, b, c
</syntaxhighlight>
=== forwarding operator ===
When passing a single argument, you can use the forwarding operator.
<syntaxhighlight lang="langur">
a -> len
# passes a to the len() function
</syntaxhighlight>
=== recursion ===
Use the fn token with double parentheses for recursion.
<syntaxhighlight lang="langur">
val fibonacci = fn x:if x < 2 { x } else { fn((x - 1)) + fn((x - 2)) }
</syntaxhighlight>
=== argument expansion ===
Use the expansion operator (...) to pass a list as multiple arguments. The following example works if wordsets is a list of lists, and passes each list as a separate argument to the mapX function.
<syntaxhighlight lang="langur">
mapX(amb, wordsets...)
</syntaxhighlight>
=={{header|Latitude}}==
|