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
  • 0
    Certified Lead Developer

    Interestingly, with just a small change to the definition of local!varB, the form starts behaving how I would expect (i.e. refusing to saveInto directly into varB).

    For example:

    a!localVariables(
      local!varA: a!refreshVariable(
        value: rand()*100,
      ),
      local!varB: a!refreshVariable(
        value: local!varA + 2,
        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
          )
        }
      )
    )

Reply
  • 0
    Certified Lead Developer

    Interestingly, with just a small change to the definition of local!varB, the form starts behaving how I would expect (i.e. refusing to saveInto directly into varB).

    For example:

    a!localVariables(
      local!varA: a!refreshVariable(
        value: rand()*100,
      ),
      local!varB: a!refreshVariable(
        value: local!varA + 2,
        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
          )
        }
      )
    )

Children