unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: Noah Lavine <noah.b.lavine@gmail.com>
To: Stefan Israelsson Tampe <stefan.itampe@gmail.com>
Cc: Mark H Weaver <mhw@netris.org>, guile-devel <guile-devel@gnu.org>
Subject: Re: Special variables to relax boxing
Date: Thu, 21 Mar 2013 17:11:21 -0400	[thread overview]
Message-ID: <CA+U71=MYG10Vyg3zxDx40p8wRJv9fMZTq6kCHhxdiLHshkZwPg@mail.gmail.com> (raw)
In-Reply-To: <12515493.61rmnodEK6@warperdoze>

[-- Attachment #1: Type: text/plain, Size: 4271 bytes --]

Hi,

Stefan and Mark, I think you are talking past each other. Stefan is
offering a very concrete definition of what he wants, and Mark is looking
for a more abstract version. Here is what I think Stefan wants, in the
language of R5RS' storage model:

A variable is simply a name for a particular location, and each variable
refers to its own unique location. When a continuation is captured, that
continuation gets its own set of "mirror" locations, one for each variable
that is in the scope of the continuation. These "mirror" locations are
initialized with the same values that were in the locations of the
corresponding variables, but they are distinct from those locations and are
immutable.

When a continuation is called, it is run in an environment in which each of
the variables that was in scope when it was captured points to a new
location, which is initialized to have the same value as the corresponding
"mirror" location.

Note that each variable name gets at least three distinct locations in this
description: the original location, when the program was being run, the
"mirror" location, when the continuation was captured, and the new
location, when the continuation was called. I believe this is sufficient
(and necessary?) to give the semantics that Stefan wants.

Let me also give a more concrete example, which I believe captures *why*
this is important. Let's say you're writing a loop with a counter that says
when to terminate:

(let ((count 0))
  (let iter ()
    ... do-some-stuff ...
    (when (< count 1000000)
      (set! count (+ count 1))
      (iter))))

Now pretend that do-some-stuff captures its continuation when count is
equal to 10. Stefan wants a situation where, no matter how many times that
continuation is called, *each call* to the continuation will have (= count
10). I think this is very natural if you're using an imperative style, but
I'm not sure what the best way is to achieve it.

Best,
Noah


On Thu, Mar 21, 2013 at 4:15 PM, Stefan Israelsson Tampe <
stefan.itampe@gmail.com> wrote:

> On Thursday, March 21, 2013 03:03:06 PM Mark H Weaver wrote:
> > Stefan, you're still describing your proposal in terms of low-level
> > implementation details such as stacks.  In the general case, we cannot
> > store environment structures on the stack.  Furthermore, in the
> > general case *all* variables in scheme are bound to locations, not
> > values.  Only in special cases can we use stacks, and only in special
> > cases can we avoid boxing variables.  These are only _optimizations_.
> >
> > If you're serious about this proposal, please read sections 3.1 and
> > 3.4 of the R5RS carefully.  Explain your proposed _semantics_ (not
> > the implementation details) in those terms, where *all* variables are
> > bound to _locations_, and where there is no stack at all (everything
> > is conceptually stored in a garbage-collected heap).
> >
> > We need to understand the *semantics* in the simplest possible terms
> > before we even begin to think about how to implement it.
> >
> >     Thanks,
> >       Mark
>
> Ok, the sematics for the simple version is are,
>
> Assume k, the continuation associated with with a dynamic wind or
> unwind assume that there is a map from each continuation (k,id)
> to a value and getting and setting of this value is done through
> ref-get and ref-set, assume that the winder and the rewinder lambda
> takes a first argument k beeing the continuation under action, finally
> make-id will make a unique object. then the semantic would be:
>
> (define-syntax-rule (with-special (a) code)
>   (let ((id (make-id)))
>     (dynamic-wind
>        (lambda (k) (set! a (ref-get k id)))
>        (lambda () code)
>        (lambda (k)  (ref-set! k id a)))))
>
> A possible refinment of this is
> associate to k two predicates e.g.
>  (do-wind? k kind) predicate and a (do-unwind? k kind) wich takes
> a parameter kind, then use the semanics
>
> (define-syntax-rule (with-special (a kind) code)
>   (let ((id (make-id)))
>     (dynamic-wind
>        (lambda (k)
>          (when (do-wind? k kind)
>            (set! a (ref-get k id))))
>        (lambda () code)
>        (lambda (k)
>          (when (do-unwind? k kind)
>            (ref-set! k id a))))))
>
> Hopes this helps!
>
> /Stefan
>
>
>

[-- Attachment #2: Type: text/html, Size: 5231 bytes --]

  reply	other threads:[~2013-03-21 21:11 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-03-19 22:05 Special variables to relax boxing Stefan Israelsson Tampe
2013-03-21  6:00 ` Mark H Weaver
2013-03-21  9:35   ` Stefan Israelsson Tampe
2013-03-21 15:35     ` Noah Lavine
2013-03-21 16:28       ` Stefan Israelsson Tampe
2013-03-21 19:03     ` Mark H Weaver
2013-03-21 20:15       ` Stefan Israelsson Tampe
2013-03-21 21:11         ` Noah Lavine [this message]
2013-03-22 22:33           ` Stefan Israelsson Tampe
2013-03-23  0:18             ` Daniel Hartwig
2013-03-23 15:34       ` Stefan Israelsson Tampe
2013-03-23 18:31         ` Stefan Israelsson Tampe
  -- strict thread matches above, loose matches on Subject: below --
2013-03-23 10:30 Stefan Israelsson Tampe

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='CA+U71=MYG10Vyg3zxDx40p8wRJv9fMZTq6kCHhxdiLHshkZwPg@mail.gmail.com' \
    --to=noah.b.lavine@gmail.com \
    --cc=guile-devel@gnu.org \
    --cc=mhw@netris.org \
    --cc=stefan.itampe@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).