unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: John Wiegley <jwiegley@gmail.com>
To: "Stephen J. Turnbull" <stephen@xemacs.org>
Cc: Emacs developers <emacs-devel@gnu.org>
Subject: Re: async 1.0
Date: Sat, 23 Jun 2012 16:05:08 -0500	[thread overview]
Message-ID: <m2txy1zqm3.fsf@gmail.com> (raw)
In-Reply-To: <877guya6jz.fsf@uwakimon.sk.tsukuba.ac.jp> (Stephen J. Turnbull's message of "Sat, 23 Jun 2012 15:25:20 +0900")

>>>>> Stephen J Turnbull <stephen@xemacs.org> writes:

> XEmacs efs (or maybe it's dired -- not to be confused with any dired in
> Emacs IIRC, you need the XEmacs versions) has an implementation of call/cc.
> I don't know how close to "true" call/cc it is.  For correct info, ask Mike
> Sperber <mike@xemacs.org>.

I'll have to check that out.

Eshell has a poor man's implementation of call/cc, called `eshell-do-eval'.
It throws `eshell-defer' as the equivalent of calling `call/cc', returning an
object you can `eval' later to resume execution.

The way it works is by taking the form you want to `eval' and transforming it
as it evaluates, performing substitutions so that (let ((a (+ 10 20))) ...)
becomes (let ((a 30)) ...), etc., on down to where you throw `eshell-defer'
(and of course removing the throw).  The next time you evaluate, no additional
evaluations are done until you reach the point where you deferred.

The downsides are: (a) it's slow to walk and eval in Lisp, (b) it doesn't work
with byte-compiled forms, and (c) it's limited to a subset of the Emacs Lisp
language, since each single special form needs to be treated specially, and I
only implemented transforms for the ones that Eshell actually used.  Oh, and
(a) it doesn't peer past function call boundaries.

That said, it could be extended to fully support Emacs Lisp; it would simply
require that nothing be byte-compiled.  Unless bytecode stream instrumentation
was added to the mix...

On the other hand, how hard would it be to make Emacs stackless and provide a
native call/cc that works not only with byte-compiled code, but with
interposing native function calls?  For example:

    (let* ((a (+ 10 20))
           (c '(1 2 3)))
           (d (mapcar #'(lambda (b) (+ b a) (call/cc)) c)))

I cannot think of any way to fake continuations here, other than having
intimate of every native function, and transforming the `let' into this:

    (let* ((a 30)
           (b '(2 3))
           (d (cons 1 (mapcar #'(lambda (b) (+ b a)) c))))

The problem gets pretty hairy fairly quickly.

John



  reply	other threads:[~2012-06-23 21:05 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <m2hau86tfk.fsf@vulcan.local.i-did-not-set--mail-host-address--so-tickle-me>
     [not found] ` <E1ShM8F-0006IY-L9@fencepost.gnu.org>
     [not found]   ` <m2txy51z1k.fsf@newartisans.com>
     [not found]     ` <E1ShiKM-0000Aa-5G@fencepost.gnu.org>
2012-06-21 21:23       ` async 1.0 John Wiegley
2012-06-22  7:00         ` Teemu Likonen
2012-06-22 10:54           ` John Wiegley
2012-06-22 12:39             ` Michael Albinus
2012-06-22 22:02               ` John Wiegley
2012-07-04 17:10                 ` Samuel Bronson
2012-07-05  4:09                   ` John Wiegley
2012-07-05 19:58                     ` Samuel Bronson
     [not found]             ` <82d34r8ej9.fsf@gmail.com>
2012-06-22 21:50               ` John Wiegley
2012-06-23  1:44                 ` Stefan Monnier
2012-06-23  3:00                 ` Stefan Monnier
2012-06-23 16:26                   ` Lennart Borgman
2012-06-23 21:08                   ` John Wiegley
2012-06-23 21:28                     ` Jeremiah Dodds
2012-06-23 21:50                     ` Thierry Volpiatto
2012-06-24 15:02                     ` Christopher Schmidt
2012-06-24 15:42                       ` Bastien
2012-06-24 21:01                       ` John Wiegley
2012-06-25 14:53                         ` Christopher Schmidt
2012-06-25 23:54                           ` John Wiegley
2012-06-24 21:12                       ` ELPA and core services John Wiegley
2012-06-24 21:40                         ` Lennart Borgman
2012-06-25  2:20                         ` Stefan Monnier
2012-06-25  4:39                         ` Stephen J. Turnbull
2012-06-25  6:01                         ` Achim Gratz
2012-07-03 14:38                           ` Tom Tromey
2013-01-22 19:13                             ` Achim Gratz
2012-06-25  4:32                       ` stdlib for Emacs? [was: async 1.0] Stephen J. Turnbull
2012-06-23  6:25                 ` async 1.0 Stephen J. Turnbull
2012-06-23 21:05                   ` John Wiegley [this message]
2012-07-01  8:16                   ` Michael Sperber
2012-06-22 11:38         ` Richard Stallman
2012-06-22 21:39           ` John Wiegley
2012-06-22 23:02             ` Richard Stallman
2012-06-23  7:46               ` zwz
2012-06-23 20:49                 ` 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=m2txy1zqm3.fsf@gmail.com \
    --to=jwiegley@gmail.com \
    --cc=emacs-devel@gnu.org \
    --cc=stephen@xemacs.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).