To expand a little on what has previously been said ...
dfns implement Static Single Assignment (SSA) - every time a value is named using ← the name automatically shadows any previous value. Thus in this example:
⎕cr 'ros'
ros←{
a←1
a←2
a
}
ros 0
2
a
VALUE ERROR: Undefined name: a
a
∧
the first assignment (a←1) shadows any previous a (there wasn't one), the second assignment shadows the first and then at the end of the function both instances of a are unshadowed, so it reverts to having no value.
Dyadic ⎕XT associates a name with the value within an external variable file, which does not easily fit into the dfn model. One important behavioural consideration is that the name is not automatically localised, which I can't decide is the right or wrong behaviour:
)vars
⎕cr 'ros2'
ros2←{
f←(739⌶0),'/x'
_←f ⎕XT'a'
⎕←⎕XT'a'
}
ros2 0
C:\Users\richard\AppData\Local\Temp\x.DXV
)vars
a
⎕EX 'a'
However, whether it shadowed the previous value or not, SSA prevents you from updating the external variable - the normal dfn rules apply: the previous value is automatically shadowed and you assign the value to
a different instance of the name, one that is not associated with the external variable:
⎕cr 'ros3'
ros3←{
f←(739⌶0),'/x'
_←f ⎕XT'a'
⎕←⎕XT'a'
a←1 ⍝ a "new" a not associated with the external variable
⎕←⎕XT'a' ⍝ no name shown; not associated with the external variable
}
This is awkward. If you are using dfns for their functional characteristics, external variables don't really fit. If you are using them as convenient inline functions, you probably want a way of preventing the automatic localisation. There are ways of doing it, but those of a purist nature may prefer to look away.
Technique 1:
_←⍎'a←1'
Technique 2:
a∘←2