[nem-en] Re: Mutually recursive local functions.
Radu Grigore
radugrigore at gmail.com
Tue Jul 3 14:31:06 CEST 2007
On 7/3/07, Elifant <elifantu at mail.ru> wrote:
> Michal Moskal пишет:
> I've added it at
> http://nemerle.org/Grok_Base_structure_of_programs#Local_functions,
> but I can't think out simple and useful example of use. So I just wrote
> dumb code.
One (common?) use is to log the parameters and the return value of a
recursive function.
def fib(n)
if (n<2) n
else fib(n-1)+fib(n-2)
gets changed into
def fibNoLog(n)
if (n<2) n
else fib(n-1)+fib(n-2)
and fib(n)
def r = fibNoLog(n)
WriteLine($"fib($n)=$r")
The transformation is automatic and easy to do. Modifying a
complicated recursive function might not be as convenient especially
if it has multiple return points.
--
regards,
radu
http://rgrig.blogspot.com/
More information about the devel-en
mailing list