unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Emanuel Berg <incal@dataswamp.org>
To: emacs-devel@gnu.org
Subject: recursion to iteration macro
Date: Fri, 22 Mar 2024 23:56:15 +0100	[thread overview]
Message-ID: <871q813mgg.fsf@dataswamp.org> (raw)

Did anyone try to write a macro or by using some other method
to translate arbitrary use of recursion into functionally
equivalent code that is iteration only?

I read [1] this is theoretically possible and that seems
reasonable as well, as with loops, local functions etc you
have everything you need to implement it.

You can even have an expanding data structure, e.g. a list, to
implement a virtual stack, still all within the one function,
if you are fond of it.

With execution all advantages should be with iteration but
sometimes recursion makes for compact, elegant code that can
also be more intuitive, more fun to write.

Recursion is not so common, in part for this exact reason, but
if we had this, maybe we would see a little recursion
renaissance and proliferation?

The best of both worlds anyone? You _will_ be assimilated!

[1] https://en.wikipedia.org/wiki/Recursion_(computer_science)
    https://stackoverflow.com/questions/931762/can-every-recursion-be-converted-into-iteration

-- 
underground experts united
https://dataswamp.org/~incal




             reply	other threads:[~2024-03-22 22:56 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-22 22:56 Emanuel Berg [this message]
2024-03-23  7:12 ` recursion to iteration macro Philip Kaludercic
2024-03-23 10:17   ` Emanuel Berg
2024-03-23 10:30     ` tomas
2024-03-23 10:40       ` Emanuel Berg
2024-03-23 13:25         ` tomas
2024-03-25 23:38           ` Richard Stallman
2024-03-26  5:40             ` tomas
2024-03-28 22:05               ` Richard Stallman
2024-03-29  6:36                 ` tomas
2024-03-30 22:37                   ` Richard Stallman

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

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=871q813mgg.fsf@dataswamp.org \
    --to=incal@dataswamp.org \
    --cc=emacs-devel@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 public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).