From: Katalin Sinkov <lispstylist@gmail.com>
To: help-gnu-emacs@gnu.org
Subject: Re: How to cast an imperative loop into a readable recursive function ?
Date: Thu, 2 Dec 2010 19:12:38 -0800 (PST) [thread overview]
Message-ID: <b8ac9073-c2f9-4517-8679-afbee74b4034@s5g2000yqm.googlegroups.com> (raw)
In-Reply-To: rNOSPAMon-C72AE3.18481502122010@hello.network
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".
next prev parent reply other threads:[~2010-12-03 3:12 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-12-03 1:50 How to cast an imperative loop into a readable recursive function ? Katalin Sinkov
2010-12-03 2:17 ` Paul Rubin
[not found] ` <8a5ef1e1-aab3-47bd-80e3-081f8dc65b0e@c39g2000yqi.googlegroups.com>
[not found] ` <84a24d31-6379-4b81-ac65-b0d8642ab7da@37g2000prx.googlegroups.com>
2010-12-03 3:30 ` Paul Rubin
[not found] ` <0c1c00c1-61ef-42be-a2d3-db1ff31035e8@29g2000yqq.googlegroups.com>
2010-12-03 7:29 ` Paul Rubin
2010-12-03 9:44 ` Tim Bradshaw
2010-12-03 2:48 ` RG
2010-12-03 3:12 ` Katalin Sinkov [this message]
[not found] ` <7xk4jrmtmg.fsf@ruckus.brouhaha.com>
2010-12-03 3:22 ` Katalin Sinkov
[not found] ` <87ipzbpgft.fsf@kuiper.lan.informatimago.com>
2010-12-03 7:37 ` Katalin Sinkov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=b8ac9073-c2f9-4517-8679-afbee74b4034@s5g2000yqm.googlegroups.com \
--to=lispstylist@gmail.com \
--cc=help-gnu-emacs@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.