Jump to content

Call a function: Difference between revisions

m
Added the Sidef language
m (→‎{{header|Ada}}: Linguistic fixes)
m (Added the Sidef language)
Line 2,625:
 
* Call-by-name parameters use a function in first-class context. The function [http://seed7.sourceforge.net/examples/map.htm doMap] from the examples section of the Seed7 homepage uses a given expression to modify the elements of an array:<lang seed7>seq := doMap([](1, 2, 4, 6, 10, 12, 16), x, succ(x));</lang>
 
=={{header|Sidef}}==
All functions in Sidef are first-class closures
<lang ruby>foo(); # without arguments
foo(1, 2); # with two arguments
foo(args...); # with a variable number of arguments
foo(name: 'Bar', age: 42); # with named arguments
 
var f = foo; # store the function foo inside 'f'
var result = f(); # obtain the return value of a function
 
var arr = [1,2,3];
foo(arr); # the arguments are passed by object-reference</lang>
 
Partial application is possible by using a curry function:
 
<lang ruby>func curry(f, *args1) {
func (*args2) {
f(args1..., args2...);
}
}
 
func add(a, b) {
a + b
}
 
var adder = curry(add, 1);
say adder(3); #=>4</lang>
 
=={{header|Smalltalk}}==
2,747

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.