[Oberon] Oberon-07, recursion and type extension

Richard Hable informujo at aon.at
Mon Sep 5 21:47:52 CEST 2016


Am 2016-09-05 um 12:52 schrieb Lars:

> PROGRAM Clever;
> 
> FUNCTION Recursive(i: INTEGER): INTEGER;
> BEGIN
>   Write(i);
>   i := i + 1;
>   IF i <= 6 THEN Result := Recursive(i);
> END;
> 
> BEGIN
>   Write('EWD ');
>   Recursive(4);
>   Readln;
> END.

Only very unexperienced functional programmers would write something
like this.

> I find this more convoluted and clever than a simple non recursive
> solution.  It's almost as if functional programming is a competition to
> see how many tricks you can get away with and still get cheered on by your

Actually, a functional-programming expert once said that "recursion is
the goto of functional programming", since most recursive functions can
be replaced by higher-level standard functions like "map" and "filter".

In my favorite functional programming language the above algorithm could
be written as follows:

"EWD " + SET (4..6): to list: flat map [Character] (?(i) i:out)

Richard




More information about the Oberon mailing list