Yukihiro Matsumoto wrote:
> Hi,
> 
> In message "Bug? String interpolation and continuations"
>     on 04/07/22, Sam McCall <tunah.usenet / tunah.net> writes:
> 
> |The following gives me weird results:
> |(Typed into IRB. The results are similar in ruby but because of the 
> |simple example you get an infinite loop)
> 
> It's not a bug.  It's a feature.
Just to be clear, I did expect the infinite loop :-) But I assumed that 
it would reinterpolate the string rather than continue appending.

> |$cont.call("hello")
> |# prints '[]hello]hello]hello]...'
> |# expected '[hello]'
> 
> By calling the continuation the execution goes back to the saved
> point, but no other states are restored, so that the value of
> generating string (referenced from the local variable) remains the
> last generated value after the jump.  Then execution concatenate
> "hello", then "]".  Repeat forever.
> 
> That's what happened.
Thanks, that makes sense, although it is surprising until I think about 
implementation details. (I haven't read the spec yet... not a native C 
speaker ;-)

I expected
s="#{foo()}-#{callcc &store_cont}-#{bar()}"
to have the interpolated values evaluated first (left to right), and 
then have the string assembled afterwards (by analogy with method calls 
having arguments evaluated first). foo() would be called once, but bar() 
would be called every time the continuation was resumed.

On the other hand even if this was better behaviour I guess it isn't 
work the performance costs, just for continuations.

Sam