unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: Amirouche Boubekki <amirouche.boubekki@gmail.com>
To: Catonano <catonano@gmail.com>, Chris Vine <vine35792468@gmail.com>
Cc: guile-user@gnu.org
Subject: Re: dynamic-wind
Date: Sat, 08 Jul 2017 20:03:53 +0000	[thread overview]
Message-ID: <CAL7_Mo_jv=U+_novfchtBh7-H8TitNeMxQGEt5zhL8_ZwhxxBw@mail.gmail.com> (raw)
In-Reply-To: <CAJ98PDxsMStZKFnTuG1VYxpdnTXZcEPh1gmoYOR9BZzj+82fbg@mail.gmail.com>

Héllo all!

On Wed, Jul 5, 2017 at 8:14 AM Catonano <catonano@gmail.com> wrote:

> My point is that the manual does not a good job of _introducing_ people to
> the concept of dynamic wind
>
> Especially people wo have not clear in mind a complete map of the use cases
> with relative possible solutions.
>
> The manual tends to be a very good reference for already educated people.
> But it's not as good in educating people in the first place, in my view.
>

Maybe you are right. Maybe [0] is missing some more usecases. I consider
dynamic-wind an advanced concept not required for usual hacking. It's like
"if you don't know what you are doing, don't use it"

[0]
https://www.gnu.org/software/guile/manual/html_node/Dynamic-Wind.html#Dynamic-Wind



2017-07-02 13:58 GMT+02:00 Chris Vine <vine35792468@gmail.com>:
>
> > On Sun, 2 Jul 2017 08:00:58 +0200
> > > aahh I see now
> > >
> > dynamic-wind is much more general than just for dealing with database or
> > network connections, which I think would be a poor focus for the manual.
> >
>
> I was not suggesting to _narrow_ the focus of the manual
>
> I was suggesting to use a more mundane example as an _introduction_ to the
> functionality of dynamic wind
>
> The current example could still be given, maybe as the last one
>
> A general principle for the Wikipedia pages is to use an informal
> description first and then move on to more formal discssion later in the
> page
>
> To allow both audiences (interested in a quick overview and interested in a
> deeper analisys) to be served
>
> So I was thinking that the same principle could be used for the discussion
> of dynamic wind
>

I agree with you. A small introduction and a deeper look should both make
up the manual for each entry. That's said, the current page does in fact
have an introduction but starts with some C stuff which I don't understand,
which is why I prolly only skimmed over it the first time. Also the whole
article only cite call/cc in the example. My understanding now is that
dynamic-wind is only useful if you do use call/cc or one of its surrogate.
So call/cc should appear be in the introduction paragraph.


> That seems to confirm my view that the manual is not a great introduction
>

You are prolly more informed than me. I learned scheme from r7rs small
paper [1] and I use the manual mainly as a reference.

[1] http://trac.sacrideo.us/wg/raw-attachment/wiki/WikiStart/r7rs.pdf


>
> That said, Amirouche observed that in his Wiredtiger access layer, a state
> depending on the db is created and when leaving the dynamic wind context
> that sould be unrolled
>
> When reentering it should be properly reproduced
>
> He also considered taht probably in his case, the oprtions of leaving the
> context because of an exception and because of an intentional step should
> be treated diferently, as you observed
>

Indeed, in wiredtiger the with-context procedure which is not perfect, but
still does the job is implemented as follow:

(define-syntax-rule (with-context env body ...)
  (let ((env* env))
    ;; get or create a context and set it as current *context* value
    (let ((context (get-or-create-context env*)))
      (with-fluids ((*context* context))
        ;; execute the body
        (call-with-values
          (lambda () (begin body ...))
          (lambda out
            ;; push back the context to the context pool
            (with-mutex (env-mutex env*)
              (env-contexts! env* (cons context (env-contexts env*))))
            (apply values out)))))))

(define-syntax-rule (with-context* body ...)
  (let ((env (fluid-ref *env*)))
    (with-context env body ...)))

(define-syntax-rule (with-env env body ...)
  (let ((env* env))
    (with-fluids ((*env* env*))
      (call-with-values
        (lambda () (with-context* body ...))
        (lambda out
          (env-close env*)
          (apply values out))))))

It's inspired from ports procedures [2]. Like it tried to explain to
Catonano it's wrong to say that all with-fu procedure must be written using
dynamic wind. A proof of that is the port procedures in [2]. In fact, if
you can't re-compute the state before the dynamic context is escaped,
dynmaic wind is useless, which is the case of wiredtiger's with-context.

[2] http://git.savannah.gnu.org/cgit/guile.git/tree/module/ice-9/ports.scm


>
>
> > Having said all that, dynamic-wind is not the answer to all cases where
> > control leaves a block of code non-locally.  It is best suited to cases
> > where invocation of a continuation object or the raising of an
> > exception fall to be dealt with in the same way, say by releasing a
> > resource such as by unlocking a mutex or closing a port.  But that is by
> > no means always the case - the invocation of a continuation object is
> > usually a deliberate programmatic strategy, whereas the raising of an
> > exception is usually not so and instead represents an unexpected
> > failure event of some kind in the program.
>
>
> Wrapping up: I concede that dynamic wind is more general than network or
> dbs, and that doesn't even exhaust the whole range of possible cases
> (thanks !)
>
> But the manual could be improved nonetheless (unless it is meant to NOT be
> a tutorial)
>
> One last note: Amirouche lost this thread in his email client and asked me
> to post something so he can recuperate this thread and intervene, perhaps
>

I figured I have a backup solution in my gmail account...


  parent reply	other threads:[~2017-07-08 20:03 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-06-30 20:33 dynamic-wind Catonano
2017-06-30 21:48 ` dynamic-wind Panicz Maciej Godek
2017-07-02  6:00   ` dynamic-wind Catonano
2017-07-02  6:01     ` dynamic-wind Catonano
2017-07-02 11:58     ` dynamic-wind Chris Vine
2017-07-05  6:14       ` dynamic-wind Catonano
2017-07-05  8:23         ` dynamic-wind David Kastrup
2017-07-08 20:03         ` Amirouche Boubekki [this message]
2017-07-08 21:34           ` dynamic-wind Marko Rauhamaa
2017-07-09  7:21             ` dynamic-wind David Kastrup
  -- strict thread matches above, loose matches on Subject: below --
2017-07-09 12:59 dynamic-wind Chris Vine
2017-07-09 14:09 ` dynamic-wind Vítor De Araújo
2017-07-09 14:49   ` dynamic-wind Chris Vine
2017-07-17 10:04     ` dynamic-wind Catonano

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/guile/

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

  git send-email \
    --in-reply-to='CAL7_Mo_jv=U+_novfchtBh7-H8TitNeMxQGEt5zhL8_ZwhxxBw@mail.gmail.com' \
    --to=amirouche.boubekki@gmail.com \
    --cc=catonano@gmail.com \
    --cc=guile-user@gnu.org \
    --cc=vine35792468@gmail.com \
    /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.
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).