Inner procedure call modifying variable in outer scope
A Logo programming environment for Microsoft Windows
Brought to you by:
david_costanzo
I'm using version 8.4 in English under Wine under Linux and I have this code:
to b :captured
(show (ponA [[[E] :E] 1000]) :captured)
end
to ponA :ab
output apply [disruptor list ?1 ?2] :ab
end
to disruptor :captured
output apply [invoke ?1 ?2] :captured
end
When I run this line:
b 1
I was expecting
1000 1
instead, I get:
1000 [[[E] :E] 1000]
Tested the code using Ucblogo 6.2.2
and got what I feel is the correct result:
1000 1
The example isn't self-evident. I suppose you're saying that the
:capturedargument ofdisruptorshould shadow the:capturedinband therefore its assignment should not affect the value of:capturedinb.Yes. that interpretation is correct.
What's more, if I change the "b" procedure in this way:
The problem vanishes:
I changed this
to this:
[?]I'm not sure if this helps pin-point the problem or not.
another weird thing is that the value of captured is only wrong in the first show line, but not the last line show :captured below:
Thanks for the additional information, Daniel. I've simplified your original example to
To break down the behavior,
apply [[E] :E] [1000]should evaluate to 1000. Therefore,cshould also output 1000, which meansbshould also output 1000.It's clear that
a 1should throw an error, as:variablehas no value ina. Somehow the stack frame for the RUN/APPLY makes it toa. I suspect this is a bug in the interplay between tailcall optimization and macros, as RUN and APPLY are both macros. It might even be a duplicate of Bug #599. If you remove the tailcall fromc, the problem disappears.While the UCBLogo behavior seems better, it's not flawless. For example, on my Fedora 41 machine, after adding the above, UCBLogo crashes if asked to run
Related
Bugs:
#599I had previously written:
I fixed bug #599 and this bug (Bug #600) remains, so this is not duplicate.
I simplified the example as much as I could:
ashould throw an error because:variableis not defined. Instead, it prints2 1. The2is correct, as that's whatb 1outputs.If the named-slot template in the apply is changed to a named procedure template or an explicit slot template, then problem does not reproduce.
Diff:
I have committed a fix with [r6136].
Although the fix was relatively simple, it does not follow the code in UCBLogo, which makes less confident in it. The updated code passes all my tests, but that doesn't mean that my fix didn't introduce new problems. I have attached a pre-release version of the update, in case you'd like to test it before it's release in FMSLogo 8.5.0.
Related
Commit: [r6136]
Thanks David,
Very much appreciate the time you've spent tracking this bug down. I'm going to start using the attached pre-release version.
It loaded LogoFE normally (no issues there) and I ran a few commands that I thought might have some interplay with nested APPLYs, and so far so good.
I'll keep you posted if something related to this issue comes up again.