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.

void control (void (*f)()) {
        (*f)();
}
procedure Control (F : access procedure) is
begin
   F.all;
end Control;
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();
}
from typing import Callable
control: Callable = lambda f: f()
(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()
from typing import Callable
def control(f: Callable): f()
def control
    yield
end
fn control(f: impl Fn()) {
    f();
}
(define (control f) (f))

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