Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!

Idiom #93 Pass a runnable procedure as parameter

Implement the procedure control which receives one parameter f, and runs f.

procedure Control (F : access procedure) is
begin
   F.all;
end Control;
void control (void (*f)()) {
        (*f)();
}
void control(invocable auto&& f)
{
 f();
}
T control(Func<T> f) {
	return f();
}
void control(void function() f)
{
    f();
}
import std.traits;
void control(alias f)()
if (isCallable!f)
{
    f();
}
control(Function f) => f();
def control(f) do
	f()
end
module x
  implicit none
contains
  subroutine control(f)
    interface
       subroutine f()
       end subroutine f
    end interface
    call f
  end subroutine control
end module x
func control(f func()) {
	f()
}
void control(Closure f) {
    f()
}
control f = f
function control(f){
	f();
}
static void control(Runnable f) {
    f.run();
}
(defun control (f)
   (funcall f))
function control(f)
	f()
end
function control($f) {
    $f();
}
procedure control(f: tprocedure);
begin
  if Assigned(f) then f;
end; 
sub control {
    my $f = shift;
    $f->();
}
def control(f):
    f()
def control
    yield
end
fn control(f: impl Fn()) {
    f();
}
(define (control f) (f))

New implementation...
< >
programming-idioms.org