Call a function: Difference between revisions
Content deleted Content added
m fixing alphabetic order |
→{{header|CoffeeScript}}: Add Déjà Vu example (WIP) |
||
Line 314: | Line 314: | ||
add2 1 #=> 3 |
add2 1 #=> 3 |
||
</lang> |
</lang> |
||
=={{header|Déjà Vu}}== |
|||
<lang dejavu># all functions except foo are from the standard library |
|||
# calling a function with no arguments: |
|||
random-int |
|||
# calling a function with a fixed number of arguments: |
|||
+ 1 2 |
|||
# calling a function with optional arguments: |
|||
# optional arguments are not really possible as such |
|||
# strategies are: |
|||
# 1) differently named functions: |
|||
sort [ 3 2 1 ] |
|||
sort-by @len [ "Hello" "World" "Bob" ] |
|||
# 2) differentiate by value of other arguments: |
|||
foo ????????????????????????????????????????????????????? |
|||
# calling a function with a variable number of arguments: |
|||
# generally with a special terminator value, which one depends |
|||
# on the function called |
|||
concat( 1 2 3 ) |
|||
[ 1 2 3 ] |
|||
set{ :foo :bar :spam } |
|||
# calling a function with named arguments: not possible |
|||
# using a function in first-class context within an expression |
|||
$ @-- @len # $ is "compose", so the function returned is "one less than the length" |
|||
# obtaining the return value of a function |
|||
# return values are always pushed on the stack, so you don't need anything special |
|||
random-int |
|||
# discarding the return value of a function |
|||
drop random-int |
|||
(WIP) |
|||
Distinguishing built-in functions and user-defined functions |
|||
Distinguishing subroutines and functions |
|||
Stating whether arguments are passed by value or by reference |
|||
Is partial application possible and how |
|||
=={{header|Erlang}}== |
=={{header|Erlang}}== |