24 lines
532 B
Plaintext
24 lines
532 B
Plaintext
include "cowgol.coh";
|
|
|
|
# Only functions that implement an interface can be passed around
|
|
# The interface is a type and must be defined before it is used
|
|
# This defines an interface for a function that takes no arguments
|
|
interface Fn();
|
|
|
|
# This function repeats a function that implements Fn
|
|
sub Repeat(f: Fn, n: uint32) is
|
|
while n != 0 loop
|
|
f();
|
|
n := n - 1;
|
|
end loop;
|
|
end sub;
|
|
|
|
# Here is a function
|
|
sub Foo implements Fn is
|
|
print("foo ");
|
|
end sub;
|
|
|
|
# Prints "foo foo foo foo"
|
|
Repeat(Foo, 4);
|
|
print_nl();
|