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:12:38 -0800 (PST)
User-agent: G2/1.0

On Dec 2, 6:48 pm, RG <rNOSPA...@flownet.com> wrote:
> In article
> <ffc3587e-3cb3-41f6-9b2f-80a22d509...@e20g2000vbn.googlegroups.com>,
>  Katalin Sinkov <lispstyl...@gmail.com> wrote:
>
> > How to cast an imperative loop into a readable recursive function ?
>
> What is a readable function?

for a beginner like me, i was able to read those in McCarthy's paper,
beautifully written recursive functions.

> Ignoring that part, you can always rewrite something like:
>
> (while condition ...)
>
> as
>
> (iterate loop ()
>   (when condition ... (loop)))
>
> where iterate is defined as:
>
> (defmacro iterate (name args &rest body)
>   `(labels ((,name ,(mapcar 'first args) ,@body))
>      (,name ,@(mapcar 'second args))))
>
> Is that what you meant?
>

I am sorry that this is not what I have in mind.

I am thinking of how McCarthy wrote all those difficult concepts
nicely as recursive functions. He dissected a problem ingeniously to
not have to iterate.

In my case, I have a pattern that is often interrupted by a reset of
the index.

It is trivial to go to nth character in a string because the indices
are contiguous.

However, in this case, the indices are often reset, but mercifully,
although not necessary, the length of the contiguous index sequence is
also given so we dont have to look for beginning paren at every step.

Take a look at my lisp code. it can be modified simply to run it and
it runs in an emacs "ide".



reply via email to

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