help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to cast an imperative loop into a readable recursive function ?


From: Katalin Sinkov
Subject: Re: How to cast an imperative loop into a readable recursive function ?
Date: Thu, 2 Dec 2010 19:19:43 -0800 (PST)
User-agent: G2/1.0

On Dec 2, 7:03 pm, Katalin Sinkov <lispstyl...@gmail.com> wrote:
> On Dec 2, 6:17 pm, Paul Rubin <no.em...@nospam.invalid> wrote:
>
> > Katalin Sinkov <lispstyl...@gmail.com> writes:
> > > How to cast an imperative loop into a readable recursive function ?
> > > What questions to ask to guide thinking to it ?
>
> > The functional-programming answer is that you rarely need explicit
> > recursion.  You can instead usually use higher-order functions like map
> > and reduce, that are defined in terms of recursion.
>
> > Maybe you want to read SICP, if you haven't done so already?
>
> > > Here is the concrete problem.
> > > which is to find the nth character T_n in a string with erratic index
> > > reset and length of substring given. ie
>
> > I'm sorry, I couldn't understand the problem description.
>
> another smaller example
>
> s=index
> v=value
>
> series is
>
> s=2345789
> v=abcdwxy
>
> after 5 there is 7 because there was a reset in the form
> (s=7,l=whatever)
>
> (s=2,l=4)2345(s=7,l=whatever)
>
> only start index of the subseries is mentioned inside parens.
>
> hope it was clear, or i can try again

what I forgot to mention was that it should be possible to view the
subseries problem in a way that I dont have to go thru a loop but use
recursive definitions.

your iterate is again a loop, ie a non-functional construct

how is any looping construct defined in terms of
car/cdr/cons/quote/atom/eq/cond/



reply via email to

[Prev in Thread] Current Thread [Next in Thread]