all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Michael Heerdegen <michael_heerdegen@web.de>
To: emacs-devel@gnu.org
Subject: Re: Delimited continuations
Date: Sun, 10 Dec 2017 17:53:00 +0100	[thread overview]
Message-ID: <87r2s2cyoj.fsf@web.de> (raw)
In-Reply-To: <m21sk4w9rk.fsf@newartisans.com> (John Wiegley's message of "Sat,  09 Dec 2017 01:06:23 -0800")

"John Wiegley" <johnw@gnu.org> writes:

>   ;; -*- lexical-binding: t -*-
>   
>   (defun shift (k entry)
>     (if (eq (nth 0 k) 'outer)
>         (throw (nth 1 k)
>                (funcall entry #'(lambda (val)
>                                   (funcall (nth 2 k)
>                                            (list 'inner val)))))
>       (nth 1 k)))
>   
>   (defun reset (thunk)
>     (let ((bound (make-symbol "reset--bound")))
>       (catch bound
>         (funcall thunk (list 'outer bound thunk)))))
   
This seems to be clever.

But one little disadvantage seems to be that a part of the code (the
part of the `reset' thunk that is evaluated until `shift' is reached) is
processed twice: once till the `shift' is reached (which `throw's and
hasn't access to this calculation, so that part of the calculation is
thrown away) and a second time when the delimited continuation is
called.

E.g. in

#+begin_src emacs-lisp
(reset (lambda (p)
         (+ (+ 1 2)
            (shift p (lambda (k) (funcall k 1))))))
#+end_src

(+ 1 2) is executed twice.  I think this isn't necessarily so?


BTW, I wonder what one can potentially do with this stuff.


Michael.



  reply	other threads:[~2017-12-10 16:53 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-12-09  9:06 Delimited continuations John Wiegley
2017-12-10 16:53 ` Michael Heerdegen [this message]
2017-12-10 19:59   ` John Wiegley
2017-12-12 14:27     ` Michael Heerdegen
2017-12-11 16:47   ` Stefan Monnier
2017-12-12 14:17     ` Michael Heerdegen
2017-12-12 22:24       ` John Wiegley
2018-01-02 18:39         ` Christopher Lemmer Webber
2018-01-02 22:29           ` John Wiegley
2018-01-03 16:01           ` Michael Heerdegen
2018-01-03 20:12             ` Stefan Monnier
2017-12-10 17:39 ` Real continuations (was: Delimited continuations) Michael Heerdegen
2017-12-11 16:16   ` Real continuations 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

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

  git send-email \
    --in-reply-to=87r2s2cyoj.fsf@web.de \
    --to=michael_heerdegen@web.de \
    --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 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.