tail call and bounded space requirement Shiro Kawai (26 Oct 2022 20:22 UTC)
Re: tail call and bounded space requirement Marc Nieper-Wißkirchen (26 Oct 2022 20:48 UTC)
Re: tail call and bounded space requirement Shiro Kawai (26 Oct 2022 21:43 UTC)
Re: tail call and bounded space requirement Marc Nieper-Wißkirchen (27 Oct 2022 05:41 UTC)
Re: tail call and bounded space requirement Shiro Kawai (28 Oct 2022 20:55 UTC)
Re: tail call and bounded space requirement Marc Nieper-Wißkirchen (28 Oct 2022 21:02 UTC)
Re: tail call and bounded space requirement Shiro Kawai (28 Oct 2022 23:44 UTC)

Re: tail call and bounded space requirement Marc Nieper-Wißkirchen 27 Oct 2022 05:41 UTC

Am Mi., 26. Okt. 2022 um 23:43 Uhr schrieb Shiro Kawai <xxxxxx@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 <xxxxxx@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 <xxxxxx@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))))
>> >
>> >