Hi Jürgen,
thank for your detailed information.
------------------------------------------------------------
The simple sequence of ...
A←1
B←2
A←B
... will (obviously) not change the variable name of A.
A
2
The alike assignments in structured variables
behave differently from regular variable assignment.
(1) -----------
The expressions
A.B←1
X.Y←2
A ←X.Y ⍝ variable A.B replaced by variable A
A
2
A.K ← 10 ⍝ The structured variable root A is gone
DOMAIN ERROR+
A.K←10
^ ^
... and the expressions
(2) -----------
A.B←1
X.Y←2
A ← X ⍝ A remains structured
A.K ←10 ⍝ New name elements can be established
A
.Y: 2
.K: 10
A.B.C ← 1
X.Y.Z ← 2
A←X
A
.Y:
.Y.Z: 2
... as well as the expressions
(3)
A.B.C ← 1
X.Y.Z ← 2
A.B.C ← X
A.B.C ← X
DOMAIN ERROR+
A.B.C←X
^ ^
... differ in their "assign consequences" from plain variable assignment:
In (1) the Variable Tree of A gets deleted and the variable A gets
established but can't be 'turned back' into a structured variable.
In (2) the Variable Tree below A gets deleted (A.B), the variables
A.Y and A.K get established.
in (3) the DOMAIN ERROR on A.B.C ← X could be prevented by ⎕EX
'A.B.C' ⋄ A.B.C ← X. The outcome is the same as if non-leaf-node could
be target of an assignment.
I think this 'inconsistency feeling' let me conclude that
"A.B.C ← name" is just an assignment of the content of name to the C-node
and "A.B.C*.* ←name" is an append of name (structured or plan variable
name) to the C-node
Best Regards
Hans-Peter
Am 14.12.20 um 17:54 schrieb Dr. Jürgen Sauermann:
Hi Hans-Peter,
thanks a lot for your feedback. See my comments below.
Best Regards,
Jürgen
On 12/14/20 4:39 PM, Hans-Peter Sorge wrote:
Hi,
I could not resist to experiment.....
)clear
CLEAR WS
A←0
A.A←1
DOMAIN ERROR+
A.A←1
^ ^
)clear
CLEAR WS
A.A←1
A←0 ⍝ Just replacing content of A.
B.B←2
A←B.B ⍝ Generates a trace. - probably should be A.B ←→ 2
Incomplete value at Symbol.cc:130
Addr: 0x1ce1990
Rank: 0
..............
Fixed in *SVN 1377*.
⍝ A structured variable of any depth can be replaced by an assignment
to the root variable.
A.B.C.D←4
A
.B:
.B.C:
.B.C.D: 4
A←1 ⍝ Consistent with current assignment: replace variable
content with RV. No DOMAIN ERROR.
A
1
⍝ Assignment working one time only ..
A.B.C ←1
X.Y.Z ←2
A.B.C←X.Y
A
.B:
.B.C:
.B.C.Z: 2
⍝ should be repeatable:
A.B.C←X.Y
DOMAIN ERROR+
A.B.C←X.Y
^ ^
Actually no.
A.B.C←X.Y turns leaf A.B.C into a non-leaf, therefore an assignment to
it it gives you DOMAIN ERROR.
Proposal:
Allow a non-leaf node to be replaced by a RV. it would then be
consistent with how the current assignment works.
I was thinking of this myself quite a bit. My current thoughts are
that overriding a non-leaf can
destroy an arbitrary number of sub-variables, just like *rm -R /* and
common *nix- wisdom has it that
this should be refused and that *rm -Rf* should be required instead. I
actually spent a very long
night at the end of the 1970s after my boss did *rm -R /* by mistake.
The counter-argument is that
you can erase arbitrary large non-structured values with an assignment
in APL.
/The same is true for assigning a value to the root variable (A.B.C.D←4,
A←0)./
I also believe that assignment to a non-leaf is an implicit ⎕EX of the
non-leaf which is not
consistent with plain variable assignment. In plain variable
assignments, you can create a
variable and change a variable, but not erase a variable. That
requires an explicit ⎕EX or )ERASE.
Above A.B.C is a (sub-) variable with value Z, so you can change it as
long as it is a leaf (including
changing it to the value of another structured variable X.Y ←→ Z). But
overriding it after it has
become a non-leaf is not allowed because that would implicitly ⎕EX it
(which in the case of
plain variables is not possible resp. requires ⎕EX or )ERASE).
The model here is that ABC behaves like a variable but A.B does not
(it is a collection of variables
and the questions is essentially whether it should be possible to
override several (sub-) variables
by a single assignment).
I belive both alternatives have arguments speaking for them and I
would like to hear more opinions
before allowing assignments to non-leaf sub-variables.
The assignment above "A.B.C ← X.Y" is actually an append -> A.B.C.Z
rather than a replace, what a "←" normally does.
I think the assignment should result in A.B.C ← X.Y. ←→ A.B.Z
It probably would if the assignment were legal.
The append could be covered by the idiom A.B.C. ← X.Y. ←→ A.B.C.Z
.. just my thoughts.
A.B.C ←1
X.Y.Z ←2
K.L.M ←3
A.B.C ← X.Y K.L
DOMAIN ERROR+
A.B.C←X.Y K.L
^ ^
'Idea:'
A.B.C ← X.Y. K.L. ←→ A.B.Z A.B.M
and:
A.B.C. ← X.Y. K.L. ←→ A.B.C.Z A.B.C.M
Basically saying:
Using a trailing dots lets operators work with a structured name element.
A.B. ←→ C
given
A.B.a←1 ⋄ A.B.b←2 ⋄ A.B.c←3
X.Y.x←10 ⋄ X.Y.y←20 ⋄ X.Y.z←30
A.B. could result in structured name elements a b c. That is listing
the leaf-node names.
A.B. ← X.Y. could result in structured names A.B.x, A.B.y, A.B.z
Without trailing dots we get the content of a variable.
A.B.C ←→ 1
A.B.a←1
A.B.b←2
A.B.c←3
A
A.B
.a: 1
.b: 2
.c: 3
A.B + 1
DOMAIN ERROR
A.B+1
^ ^
⍝ could be
A.B + 1
2 3 4
Sorry for the lengthy note.
Best Regards
Hans-Peter