Repeat: Difference between revisions
Content added Content deleted
m (Applesoft BASIC - fixed broken link, included code from linked web page) |
LalaithMeren (talk | contribs) (→{{header|Chapel}}: added chapel solution) |
||
Line 673: | Line 673: | ||
{{works with|C++11}} |
{{works with|C++11}} |
||
<syntaxhighlight lang="cpp"> repeat([]{std::cout << "Example\n";}, 4);</syntaxhighlight> |
<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}}== |
=={{header|Clojure}}== |