Jump to content

Repeat: Difference between revisions

905 bytes added ,  1 month ago
→‎{{header|Chapel}}: added chapel solution
m (Applesoft BASIC - fixed broken link, included code from linked web page)
(→‎{{header|Chapel}}: added chapel solution)
Line 673:
{{works with|C++11}}
<syntaxhighlight lang="cpp"> repeat([]{std::cout << "Example\n";}, 4);</syntaxhighlight>
 
=={{header|Chapel}}==
 
The most basic form, with generics.
<syntaxhighlight lang="chapel">
config const n = 5;
 
proc example()
{
writeln("example");
}
 
proc repeat(func, n)
{
for i in 0..#n do func();
}
 
repeat(example, n);
</syntaxhighlight>
 
With argument type hinting.
<syntaxhighlight lang="chapel">
config const n = 5;
 
proc example()
{
writeln("example");
}
 
proc repeat(func : proc(), n : uint)
{
for i in 0..#n do func();
}
 
repeat(example, n);
</syntaxhighlight>
 
Example of passing function which takes arguments. Chapel does not allow functions with generic arguments to be passed. First-class functions are in seemingly under-documentated state.
 
<syntaxhighlight lang="chapel">
config const n = 5;
 
proc example(x : uint)
{
writeln("example ", x);
}
 
proc repeat(func : proc(x : uint), n : uint)
{
for i in 0..#n do func(i);
}
 
repeat(example, n);
</syntaxhighlight>
 
=={{header|Clojure}}==
6

edits

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