bug-apl
[Top][All Lists]

## Re: Reassignment of a nested array element

 From: Hans-Peter Sorge Subject: Re: Reassignment of a nested array element Date: Tue, 7 Mar 2023 18:46:59 +0100 User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.8.0

Hello Jürgen, Elias

The difference I mention is in
(1/3⊃V)←1
vs
(3⊃V)←1

The second _expression_ is the one discussed in the Mail.
And I agree with your statement
Jürgen that, even if not specified, your solution is correct.
3⊃V is the third elemnt in V and that is being set to 1.

The first _expression_ however is
1/3⊃V  which is selecting all elements of the third element of V
then set it's supposed be
1 1 1
1 1 1
1 1 1
as with Dyalog.

Further...

(c  is equvalent to 3⊃V)

Expected :
c←3 3⍴0
(1/c)←3
c
3 3 3
3 3 3
3 3 3

Not expected 3
V should remain a Matrix
V←0 0 (3 3⍴0)
(1/3⊃V)←1
V
0 0 1

Expected:
c←3 3⍴0
((,3 3⍴1 0 0 0)/, c)←3
c
3 0 0
0 3 0
0 0 3

The "mapping" of  3 3⍴1 0 0 0 gets ignored.
V←0 0 (3 3⍴0)
((,3 3⍴1 0 0 0)/, 3⊃V)←3
V
0 0 3

Expected:
c←3 3⍴0
(↑¨c)←2
c
2 2 2
2 2 2
2 2 2

I would say it's inconsistent.
V←0 0 (3 3⍴0)
(↑¨3⊃V)←1
V
0 0   1 0 0
0 0 0
0 0 0

Expected:
c←3 3⍴0
(↑c)←2
c
2 0 0
0 0 0
0 0 0

differs here too.
V←0 0 (3 3⍴0)
(↑3⊃V)←1
V
0 0 1

Or why go
V←0 0 (3 3⍴0)
c←3⊃V
(1/c)←3
(3⊃V)←c
when
(1/3⊃V)←3
would hold?

Best Regards
Hans-Peter

Am 07.03.23 um 17:39 schrieb Elias Mårtenson:
I think this is because monadic ⊃ is first in Dyalog, as opposed to disclose in GNU, APL2 (and, incidentally, KAP 😀).

Den ons 8 mars 2023 00:34Dr. Jürgen Sauermann <mail@jürgen-sauermann.de> skrev:
Hi Hans-Peter,

I believe that GNU APL, Dyalog, and IBM APL2 only now behave
the same while GNU APL did not before the fix:

TryAPL Version 3.6.1 (enter ]State for details)
Tue Mar 07 2023 16:59:04
Q←0 0 0
(3⊃Q)←2 2⍴2
Q
┌─┬─┬───┐
│0│0│2 2│
│ │ │2 2│
└─┴─┴───┘

(3⊃Q)←33
Q
0 0 33

GNU APL SVN 1656:

Q←0 0 0
(3⊃Q)←2 2⍴2
Q
0 0   2 2
2 2

(3⊃Q)←33
Q
0 0 33

The cleanest way to achieve the previous (incompatible)
behaviour in GNU APL is to disclose the left of →

Q←0 0 0
(3⊃Q)←2 2⍴2
Q
0 0   2 2
2 2

(⊃3⊃Q)←33
Q
0 0   33 33
33 33

For dubious reasons this does not work on Dyalog
because they only assign the first item:

(⊃3⊃Q)←33
Q
┌─┬─┬────┐
│0│0│33 2│
│ │ │ 2 2│
└─┴─┴────┘

which is not consistent with (Dyalog):

W←⊂2 2⍴2
W
┌───┐
│2 2│
│2 2│
└───┘

(⊃W)←33
W
33

Although this is a discrepancy between GNU APL and Dyalog,
I believe that Dyalog is wrong here. IBM APL2 says
DOMAIN ERROR in this case.

Best Regards,
Jürgen

On 3/6/23 9:16 PM, Hans-Peter Sorge wrote:
Hello Jürgen,

I agree with your case 1/2  Statement.

The examples I was showing is actually "off by 1".

I was referring to
(1/3⊃V)←1

having
a←1
b←'ABC'
c←3 3⍴⍳9
V←a b c
(3⊃V)
1 2 3
4 5 6
7 8 9
As expected with case 1:
(3⊃V)←1

V
1 ABC 1

V←a b c
Not expected:
(1/3⊃V)←1

V
1 ABC 1

Expected:
(1/3⊃V)←1
V
1 ABC   1 1 1
1 1 1

1 1 1

as with

(1/c)←1
c
1 1 1
1 1 1
1 1 1

And that's Dyalog too.

Best Regards
Hans-Peter

Am 06.03.23 um 16:10 schrieb Dr. Jürgen Sauermann:
Gentlemen,

thanks for the discussion, fixed in SVN 1655.

Hans-Peter, I am sorry that this change creates an incompatibility in your code.

V←0 0 0
◊   V←1 ◊ V   ∩ case 1.
1

V←0 0 0  ◊   V[]←1 ◊ V   ⍝ case 2.
1 1 1

This applies to GNU APL, APL2, and Dyalog. The question is then if (A⊃V) in
(A⊃B)←X should behave like case 1 or like case 2 above. The case (A⊃B)←X
with nested (A⊃B)is described neither in the "IBM APL2 Language Reference"
nor in the "ISO 13751" standard, leaving some room for interpretation.

However, both APL2 and Dyalog agree on case 1 and therefore I changed
GNU APL to behave the same.

Best Regards,
Jürgen

On 3/4/23 8:25 PM, Hans-Peter Sorge wrote:
Hi,

Works as expected

⊃'Sue' 'Maria' 'Annalisa'
is an array 3 by 8.

⊂⊃'Susan' 'Mary' 'Annalisa'
is an element (⊂) of a 3 by 8  array (⊃'Susan' 'Mary' 'Annalisa' ).

Finally each element in  ⊃'Sue' 'Maria' 'Annalisa' gets assigned an array of  ⊃'Susan' 'Mary' 'Annalisa'

Greetings
Hans-Peter

Am 04.03.23 um 16:53 schrieb Mr. Sunday:
Hi,

I have an issue with reassigning an element of a nested array.  Here is an example.

14535:15a:~% apl --version
BUILDTAG:
---------
Project:        GNU APL
Version / SVN:  1.8 / SVN: 1651M
Build Date:     2023-03-02 00:25:07 UTC
Build OS:       Darwin 21.6.0 x86_64
config.status:  default ./configure options
Archive SVN:    1621

var←0 0 0 ⋄ (1⊃var)←5 4 ⋄ (2⊃var)←3 4⍴⍳12 ⋄ (3⊃var)←⊃'Sue' 'Maria' 'Annalisa' ⋄ var ⋄ (3⊃var)←⊂⊃'Susan' 'Mary' 'Annalisa' ⋄ var
┌→────────────────────────────┐
│┌→──┐ ┌→─────────┐ ┌→───────┐│
││5 4│ ↓1  2  3  4│ ↓Sue     ││
│└───┘ │5  6  7  8│ │Maria   ││
│      │9 10 11 12│ │Annalisa││
│      └──────────┘ └────────┘│
└ϵ────────────────────────────┘
┌→───────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│┌→──┐ ┌→─────────┐ ┌→──────────────────────────────────────────────────────────────────────────────────────┐│
││5 4│ ↓1  2  3  4│ ↓┌→───────┐ ┌→───────┐ ┌→───────┐ ┌→───────┐ ┌→───────┐ ┌→───────┐ ┌→───────┐ ┌→───────┐││
│└───┘ │5  6  7  8│ │↓Susan   │ ↓Susan   │ ↓Susan   │ ↓Susan   │ ↓Susan   │ ↓Susan   │ ↓Susan   │ ↓Susan   │││
│      │9 10 11 12│ ││Mary    │ │Mary    │ │Mary    │ │Mary    │ │Mary    │ │Mary    │ │Mary    │ │Mary    │││
│      └──────────┘ ││Annalisa│ │Annalisa│ │Annalisa│ │Annalisa│ │Annalisa│ │Annalisa│ │Annalisa│ │Annalisa│││
│                   │└────────┘ └────────┘ └────────┘ └────────┘ └────────┘ └────────┘ └────────┘ └────────┘││
│                   │                                                                                       ││
│                   │┌→───────┐ ┌→───────┐ ┌→───────┐ ┌→───────┐ ┌→───────┐ ┌→───────┐ ┌→───────┐ ┌→───────┐││
│                   │↓Susan   │ ↓Susan   │ ↓Susan   │ ↓Susan   │ ↓Susan   │ ↓Susan   │ ↓Susan   │ ↓Susan   │││
│                   ││Mary    │ │Mary    │ │Mary    │ │Mary    │ │Mary    │ │Mary    │ │Mary    │ │Mary    │││
│                   ││Annalisa│ │Annalisa│ │Annalisa│ │Annalisa│ │Annalisa│ │Annalisa│ │Annalisa│ │Annalisa│││
│                   │└────────┘ └────────┘ └────────┘ └────────┘ └────────┘ └────────┘ └────────┘ └────────┘││
│                   │                                                                                       ││
│                   │┌→───────┐ ┌→───────┐ ┌→───────┐ ┌→───────┐ ┌→───────┐ ┌→───────┐ ┌→───────┐ ┌→───────┐││
│                   │↓Susan   │ ↓Susan   │ ↓Susan   │ ↓Susan   │ ↓Susan   │ ↓Susan   │ ↓Susan   │ ↓Susan   │││
│                   ││Mary    │ │Mary    │ │Mary    │ │Mary    │ │Mary    │ │Mary    │ │Mary    │ │Mary    │││
│                   ││Annalisa│ │Annalisa│ │Annalisa│ │Annalisa│ │Annalisa│ │Annalisa│ │Annalisa│ │Annalisa│││
│                   │└────────┘ └────────┘ └────────┘ └────────┘ └────────┘ └────────┘ └────────┘ └────────┘││
│                   └ϵ──────────────────────────────────────────────────────────────────────────────────────┘│
└ϵϵ──────────────────────────────────────────────────────────────────────────────────────────────────────────┘

-- Everyday is Sunday.