Refresh Variables are pass by reference?

Okay so we came across a scenario that caused a bit of an argument:

a!localVariables(
  local!varA: a!refreshVariable(
    value: rand()*100,
  ),
  local!varB: a!refreshVariable(
    value: local!varA,
    refreshAlways: true
  ),
  a!sectionLayout(
    contents: {
      a!integerField(
        label: "Changes in this should change Var B",
        value: local!varA,
        saveInto: local!varA
      ),
      a!integerField(
        label: "What happens here",
        value: local!varB,
        saveInto: local!varB
      )
    }
  )
)

Obviously this is a terrible idea in practice, however if we can put this aside the real concern is that when you do this changing the value of varB the change somehow back propagates into varA, how is this happening? Is varB just a shallow copy of varA and vice versa?

In other not news, your site breaks every time I click on the tags box.

  Discussion posts and replies are publicly visible

Parents
  • The inline documentation for a!refreshVariable states:

    refreshAlways (Boolean): When true, the value of this local variable will be refreshed after each user interaction and each interval refresh. Because the variable is continually refreshed, you cannot update its value by saving into it. Default: false.

    Clearly the bolded text is not being enforced, but I'm guessing that's what's driving some of this behavior (i.e., you're not supposed to be doing this to begin with, so unexpected behavior may occur.)

    Notice that varA doesn't need to be a refresh variable itself. You can remove your refresh variable definition in lines 2-4 (still keeping varA there) and you'll see the same behavior. Moreover, you can move varA to a load() outside of a!localVariables and you'll still get the same behavior.

Reply
  • The inline documentation for a!refreshVariable states:

    refreshAlways (Boolean): When true, the value of this local variable will be refreshed after each user interaction and each interval refresh. Because the variable is continually refreshed, you cannot update its value by saving into it. Default: false.

    Clearly the bolded text is not being enforced, but I'm guessing that's what's driving some of this behavior (i.e., you're not supposed to be doing this to begin with, so unexpected behavior may occur.)

    Notice that varA doesn't need to be a refresh variable itself. You can remove your refresh variable definition in lines 2-4 (still keeping varA there) and you'll see the same behavior. Moreover, you can move varA to a load() outside of a!localVariables and you'll still get the same behavior.

Children