unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Chris Gray <chrismgray@gmail.com>
To: Daniel Colascione <dancol@dancol.org>
Cc: emacs-devel@gnu.org
Subject: Re: tail-call elimination
Date: Mon, 10 Dec 2012 22:45:38 -0800	[thread overview]
Message-ID: <87fw3dw0h9.fsf@stuffy.starviewtechnology.com> (raw)
In-Reply-To: <50C6CF11.2000706@dancol.org>

Daniel Colascione <dancol@dancol.org> writes:
> On 12/10/2012 6:57 PM, Chris Gray wrote:
>> Hello,
>> 
>> I have attached a patch that implements tail-call elimination for a subset of
>> emacs lisp.  This will be helpful in allowing coding styles which emphasize tail
>> recursion, such as is usual in languages like Scheme. 
>
> Your patch eliminates tail calls only in byte compiled code. Until the
> interpreter also supports guaranteed tail call elimination or we byte-compile
> all forms before evaluating them, elisp developers cannot rely on the
> optimization and cannot write idiomatic tail recursive code. As a purely
> opportunistic optimization, not as a guaranteed language feature, I doubt tail
> call elimination is worth the complexity.

I agree that the fact that the code must be byte-compiled makes it
harder to do interactive programming.  In many cases, however, small
tests can be done interactively to verify that the function is correct
before compiling it.  These would likely not blow up the stack, and thus
tail-call elimination would not be needed.  When the function has been
shown to work, it can be byte-compiled fairly simply.

I do, however, think that it's a bit inaccurate to say that this is a
purely opportunistic optimization.  It is guaranteed in the case that
your code is byte-compiled and lexically bound.  I would love to widen
that subset of the language to include things that aren't byte-compiled
(or to byte-compile automatically), but I've gotta start somewhere.

Cheers,
Chris



  reply	other threads:[~2012-12-11  6:45 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-12-11  2:57 tail-call elimination Chris Gray
2012-12-11  3:17 ` Stefan Monnier
2012-12-11  6:13 ` Daniel Colascione
2012-12-11  6:45   ` Chris Gray [this message]
2012-12-11 13:34   ` Stefan Monnier
2012-12-11 14:30     ` Wolfgang Jenkner
2012-12-11 15:13       ` Stefan Monnier
2012-12-31 18:16     ` Chris Gray
2013-01-07 18:28       ` Stefan Monnier

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=87fw3dw0h9.fsf@stuffy.starviewtechnology.com \
    --to=chrismgray@gmail.com \
    --cc=dancol@dancol.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).