Logo

Programming-Idioms

New implementation

Be concise.

Be useful.

All contributions dictatorially edited by webmasters to match personal tastes.

Please do not paste any copyright violating resource.

Please try to avoid dependencies to third-party libraries and frameworks.

Other implementations
import std.range;
void foo(Range)(Range r) {
	r.fill(42);
}

foo(a.indexed(iota(0,m,2)));
! Caller:
  integer, dimension(n) :: a
  call foo(a(1:m:2))

! Callee:

  subroutine foo(a)
    integer, dimension(:), intent(inout) :: a
    a = 42
  end subroutine foo
Math
procedure foo(var L: Integer);
begin
  L := 42;
end;

begin
  for i := 0 to Min(m, n-1) do
    if not odd(i) then foo(a[i]);
end.
sub foo  {
    my ($A, @i) = @_;
    @$A[@i] = (42) x @i;
    return $A;
}
foo($A, grep { 0 == $_ % 2 } 0 .. $m);
def foo(data, r):
    for i in r: data[i] = 42
    return

foo(a, range(0, m+1, 2))
fn foo(el: &mut i32) {
    *el = 42;
}
a.iter_mut().take(m).step_by(2).for_each(foo);