I assume the same applies to the parameterization, that is, the following
should run in a constant space.  Correct?

(define p (make-parameter 0))
(let loop ()
   (parameterize ((p 1))
       (loop)))


On Wed, Oct 26, 2022 at 7:41 PM Marc Nieper-Wißkirchen <
marc.nie...@gmail.com> wrote:

> Am Mi., 26. Okt. 2022 um 23:43 Uhr schrieb Shiro Kawai <
> shiro.ka...@gmail.com>:
> >
> > Thanks.  I was implementing with-continuation-mark by just pushing
> key&value to the current dynamic environment (and let the newest shadow the
> previous one), but realized that the simple tail-call loop makes the
> dynamic environment keeps growing.
> >
> > It is, although, somewhat tricky if marks are interleaved.
> >
> > (let loop ()
> >    (with-continuation-mark 'a 1
> >       (with-continuation-mark 'b 2
> >           (with-continuation-mark 'a 3
> >              (with-continuation-mark 'b 4
> >                  (loop))))))
> >
> > So far, what I'm thinking is that each with-continuation-mark searches
> the marks in the current continuation and reconstruct the alist of marks if
> it's overriding the previous mark.  Is there a better way than that?
>
> You do not have to search the marks in the full continuation. It is
> enough to search the marks in the youngest continuation frame, but
> maybe this is what you had in mind.
>
> By the way, you made a good catch; my sample implementation also gets
> it wrong.  See the definition of `set-mark!' in
> `control-features.sls'.
>
> While I wrote "non-destructively" above, mutation can be done, of
> course, unless it is observable.  In the case of the set of marks of
> the youngest continuation frame, destructive updates can be made as
> long as this set is copied when queried by the program.  So you can
> scan the alist and just update it in place.  If you have
> ultra-efficient small hash tables, you can use them.
>
> Hope this helps,
>
> Marc
>
> >
> > --shiro
> >
> >
> > On Wed, Oct 26, 2022 at 10:48 AM Marc Nieper-Wißkirchen <
> marc.nie...@gmail.com> wrote:
> >>
> >> Yes, indeed. The inner `with-continuation-mark' just replaces
> >> (non-destructively) the value of the mark "a".
> >>
> >> The tail-call guarantee is essential for several use cases of
> >> continuation marks.  One is debugging; you can attach debugging
> >> information to frames, but you want to retain proper tail calls while
> >> doing so.
> >>
> >> Am Mi., 26. Okt. 2022 um 22:22 Uhr schrieb Shiro Kawai <
> shiro.ka...@gmail.com>:
> >> >
> >> > Quick question.  The following code is expected to run in a bounded
> space, correct?
> >> >
> >> > (let loop ()
> >> >    (with-continuation-mark 'a 'b
> >> >        (with-continuation-mark 'a 'c
> >> >            (loop))))
> >> >
> >> >
>

Reply via email to