Function definition: Difference between revisions
Add lang example
(→{{header|Ruby}}: end-less method) |
(Add lang example) |
||
Line 1,996:
-> 720
</syntaxhighlight>
=={{header|Lang}}==
=== Function decleration ===
<syntaxhighlight lang="lang">
fp.multiply = ($a, $b) -> {
return parser.op($a * $b)
}
</syntaxhighlight>
=== One-line function decleration ===
<syntaxhighlight lang="lang">
fp.multiply = ($a, $b) -> return parser.op($a * $b)
</syntaxhighlight>
=== Function decleration by using operator functions ===
<syntaxhighlight lang="lang">
fp.multiply = fn.mul
</syntaxhighlight>
=== Function decleration by using combinator functions ===
Combinator functions can be called partially, fn.argCnt2 is used to force the caller to provide 2 arguments to prevent partially calling fp.multiply
<syntaxhighlight lang="lang">
fp.multiply = fn.argCnt2(fn.combA2(fn.mul))
</syntaxhighlight>
=== Function decleration with call by pointer ===
<syntaxhighlight lang="lang">
fp.multiply = ($[a], $[b]) -> {
return parser.op($*a * $*b) # Pointers can be dereferenced by using *
}
</syntaxhighlight>
|