Call a function: Difference between revisions

Line 3,668:
 
=={{header|langur}}==
There are 3several ways to call a function in langur.
 
=== parentheses ===
You can always call a function using parentheses.
<syntaxhighlight lang="langur">x()</syntaxhighlight>
x()
</syntaxhighlight>
 
<syntaxhighlight lang="langur">write(somestring)</syntaxhighlight>
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>
writeln a, b, c
</syntaxhighlight>
 
=== forwarding operator ===
When passing a single argument, you can use the forwarding operator.
 
<syntaxhighlight lang="langur">a -> len
a -> len
# passes a to the len() function</syntaxhighlight>
</syntaxhighlight>
 
=== recursion ===
Use the fn token with double parentheses to call self.
 
<syntaxhighlight lang="langur">
val fibonacci = fn x:if x < 2 { x } else { fn((x - 1)) + fn((x - 2)) }
</syntaxhighlight>
 
=={{header|Latitude}}==
1,007

edits