Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Potential bug on interacts using lists

Hello, Sage Community! While trying to solve this question, I have identified a potential bug. Consider the following code:

def test(xL=[]):
    xL.append(1)
    return xL

@interact
def _(x=slider(0,10,1,1)):
    f = test()
    show(f)

This is a MWE of the problem presented in the question I mentioned. For what I understand, this code should show an slide, and print [1], no matter where the slider is positioned. However, the actual behavior is that it actually shows [1] the first time the code is executed, but then, every time I move the slider, the list grows appending one more 1.

Even though the default value for xL in the first subroutine is xL = [], it seems that the previous value of xL (corresponding to the previous position of the slider) is passed every time the slider is moved. In particular, if I execute this code and move the slider three times, I get the output

[1, 1, 1, 1]

Can somebody confirm and explain this? Is this a bug?

Potential bug on interacts using lists

Hello, Sage Community! While trying to solve this question, I have identified a potential bug. Consider the following code:

def test(xL=[]):
    xL.append(1)
    return xL

@interact
def _(x=slider(0,10,1,1)):
    f = test()
    show(f)

This is a MWE of the problem presented in the question I mentioned. For what I understand, this code should show an slide, and print [1], no matter where the slider is positioned. However, the actual behavior is that it actually indeed shows [1] the first time the code is executed, but then, every time I move the slider, the list grows appending one more 1.

Even though the default value for xL in the first subroutine (test()) is xL = [], and I am calling it with no arguments, it seems that the previous value of xL (corresponding to the previous position of the slider) is passed every time the slider is moved. In particular, if I execute this code and move the slider three times, I get the output

[1, 1, 1, 1]

On the other hand, if I specifically pass the empty list [] to test(), like in

f = test([])

then, the result is always [1].

Can somebody confirm and explain this? Is this a bug?