Call a function: Difference between revisions

Adds slope example
m (Automated syntax highlighting fixup (second round - minor fixes))
(Adds slope example)
Line 5,429:
var adder = curry(add, 1);
say adder(3); #=>4</syntaxhighlight>
 
=={{header|Slope}}==
 
Define and call a procedure:
<syntaxhighlight lang="slope">(define hello-world (lambda () (display "Hello, world!\n"))
(hello-world)</syntaxhighlight>
 
Call an anonymous procedure/lambda:
<syntaxhighlight lang="slope">((lambda () (display "Hello, world!\n")))</syntaxhighlight>
 
Define and call a procedure with arguments:
<syntaxhighlight lang="slope">(define hello (lambda (name) (display "Hello, " name "!\n")))
(hello "Rosetta Code")</syntaxhighlight>
 
Define and call an anonymous procedure with arguments:
<syntaxhighlight lang="slope">((lambda (name) (display "Hello, " name "!\n")) "Rosetta Code")</syntaxhighlight>
 
Defining a procedure that takes option arguments and defining one
that takes a variable number of arguments works the same. `...`
as a paramater represents a list of all arguments passed in from that
paramater forward. Here is an example usage for variable arguments:
<syntaxhighlight lang="slope">((lambda (op ...)
(if (null? ...)
(! "At least one argument is required")
(apply op ...)))
* 1 2 3 4)</syntaxhighlight>
 
Here is an example with an optional value:
<syntaxhighlight lang="slope">((lambda (first ...)
(define last (if (null? ...) "" (append " " (car ...))))
(display "Hello " first last "\n")) "John" "Kimball")</syntaxhighlight>
 
Partial application varies by procedure. Some built-ins use partial application
(such as `or`). Macros created with `macro` do not evaluate any arguments and the
macro definition is responsible for evaluating what it needs to. But macros likely
fall into a different category than the scope of this task.
 
=={{header|Smalltalk}}==
Where f is a closure and arguments is an array of values for f to operate on.
37

edits