Why does the starting namespace for ⍵⍵ change based on ⍺⍺?

General APL language issues

Why does the starting namespace for ⍵⍵ change based on ⍺⍺?

Postby petermsiegel on Fri Oct 09, 2020 10:26 pm

Any thoughts on why the starting namespace for a (dfn) function used as the right operand of an operator shifts to the operator's own namespace depending on whether the left operand is a function or an array? (Please note: this is a simplified case to demonstrate the problem. The actual code of interest is more complex, using ⍺⍺, ⍵, etc.)
      'Home namespace',⎕THIS 
Home namespace #
'ns' ⎕NS ''
ns.do←{⍵⍵ ⍵}
var←'success'
{1} ns.do {⎕←'This is',⎕THIS ⋄ var}⊣1 ⍝ ⍺⍺ is a fn {1}.
This is # ⍝ ⍵⍵'s namespace is as expected.
success
(1⍨) ns.do {⎕←'This is',⎕THIS ⋄ var}⊣1 ⍝ ⍺⍺ is a fn (1⍨). Ditto
This is #
success
1 ns.do {⎕←'This is',⎕THIS ⋄ var}⊣1 ⍝ ⍺⍺ is a scalar (1).
This is #.ns ⍝ ⍵⍵'s namespace shifts to ns
VALUE ERROR: Undefined name: var ⍝ <var> is ONLY defined in #, not ns
1 ns.do {⎕←'This is',⎕THIS ⋄ var}⊣1
Forcing ⍵⍵ to be in the target namespace does however work (however inelegant):
      1 ns.do #.{⎕←'This is',⎕THIS ⋄ var}⊣1
This is #
success
"Curiouser and curiouser!", cried Alice!
Version: 18.0.38756, Platform: Mac-64, Edition: Unicode/64, Date: Jul 16 2020 at 01:08:20
petermsiegel
 
Posts: 83
Joined: Thu Nov 11, 2010 11:04 pm

Re: Why does the starting namespace for ⍵⍵ change based on ⍺

Postby JoHo on Sat Oct 10, 2020 3:16 pm

Does the same happen with most recent version for Mac64 18.0.39263, 2020-10-02 ?
HTH
/J
User avatar
JoHo
 
Posts: 26
Joined: Sat Nov 28, 2009 12:51 pm
Location: Austria, EU

Re: Why does the starting namespace for ⍵⍵ change based on ⍺

Postby petermsiegel on Sat Oct 10, 2020 3:44 pm

I don't think I have access to that version (latest I see is the one I posted). Happy to try the newer version if someone can point me to it.
petermsiegel
 
Posts: 83
Joined: Thu Nov 11, 2010 11:04 pm

Re: Why does the starting namespace for ⍵⍵ change based on ⍺

Postby JoHo on Sat Oct 10, 2020 7:02 pm

Sorry, it seems that is a version listed for DSS members only.
User avatar
JoHo
 
Posts: 26
Joined: Sat Nov 28, 2009 12:51 pm
Location: Austria, EU

Re: Why does the starting namespace for ⍵⍵ change based on ⍺

Postby JoHo on Sat Oct 10, 2020 8:44 pm

At least I can answer my own question,
that with the latest v18.0 under Windows 32bit, your example shows the same behaviour.
So I think, this is a case for Support.

      '.' ⎕wg 'aplversion'
Windows 18.0.39262.0 W Development

'Home namespace',⎕THIS
Home namespace #
'ns'⎕NS''
ns.do←{⍵⍵ ⍵}
ns.var←'var_value_ns_'
var←'success'
{1}ns.do{⎕←'This is',⎕THIS ⋄ var}⊣1 ⍝ ⍺⍺ is a fn {1}.
This is #
success
(1⍨)ns.do{⎕←'This is',⎕THIS ⋄ var}⊣1 ⍝ ⍺⍺ is a fn (1⍨). Ditto
This is #
success
1 ns.do{⎕←'This is',⎕THIS ⋄ var}⊣1 ⍝ ⍺⍺ is a scalar (1).
This is #.ns
var_value_ns_
1 ns.do{⎕←'This is',⎕THIS ⋄ var}1 ⍝ ⍺⍺ is a scalar (1).
This is #.ns
var_value_ns_
User avatar
JoHo
 
Posts: 26
Joined: Sat Nov 28, 2009 12:51 pm
Location: Austria, EU

Re: Why does the starting namespace for ⍵⍵ change based on ⍺

Postby petermsiegel on Sun Oct 11, 2020 5:51 am

Thank you!
petermsiegel
 
Posts: 83
Joined: Thu Nov 11, 2010 11:04 pm

Re: Why does the starting namespace for ⍵⍵ change based on ⍺

Postby Vince|Dyalog on Tue Oct 13, 2020 10:17 am

Hi Peter and JoHo,

I can see the behaviour in our latest development code (what will probably be called 19.0) as well and will ask my colleagues about it.

Regards,

Vince
Vince|Dyalog
 
Posts: 334
Joined: Wed Oct 01, 2008 9:39 am

Re: Why does the starting namespace for ⍵⍵ change based on ⍺

Postby Phil Last on Tue Oct 13, 2020 1:18 pm

This looks very much like a new incarnation of "bug[17]". Was it ever fixed?
John Scholes - on 5 June 2018 - wrote:We have a known bug [17] - see repro below - but I'm keen to check in case the one to which our refer is different.

Cheers, John.

bug17←{ ⍝ should return 1
oper←{
⍺⍺ ⍵
}
VAR←'outer'
{
VAR←'inner'
f1←{
VAR≡'inner':f2 ⍵ ⍝ OK so far
0 ⍝ fails
}
f2←{
VAR≡'inner':1 ⍝ OK
0 ⍝ fails
}
⍵:⊢f1 oper ⍵ ⍝ stack call
f1 oper ⍵ ⍝ tail call
}⍵
}

bug17 0 ⍝ fails with tail call
0
bug17 1 ⍝ succeeds with stack call in V13.1 (fails in V≥13.2)
1

then after my repro


Yup, it's bug[17] - thanks.

Maria Wells reported this bug may years ago. Unfortunately, the fix requires a pretty major re-vamp of the way dfns lexical scoping is implemented and we have never quite had the time to devote to it. Plus, I now have only about a third of the number of grey cells I had when I first implemented dfns, so I'd need a young, brainy person to do the heavy lifting. Rest assured "it's still on the list".
User avatar
Phil Last
 
Posts: 548
Joined: Thu Jun 18, 2009 6:29 pm

Re: Why does the starting namespace for ⍵⍵ change based on ⍺

Postby Vince|Dyalog on Tue Oct 13, 2020 1:54 pm

Hi Peter,

I have logged this Dop issue as 18570.

Regards,

Vince
Vince|Dyalog
 
Posts: 334
Joined: Wed Oct 01, 2008 9:39 am

Re: Why does the starting namespace for ⍵⍵ change based on ⍺

Postby JoHo on Tue Oct 13, 2020 3:38 pm

Hello Phil,
IMO it is different,
with Peter's reproducible the globlal context of a fn inside an d-operator changed, depending of the data-type of different left operands to that d-op.

With Bug17 it seems, it was an intrinsic change of context depending on two different obscure calling methods of the very same code. Bug17 seems to be fixed.

      ⎕vr 'bug17'
∇ bug17←{ ⍝ should return 1
[1] oper←{
[2] ⍺⍺ ⍵
[3] }
[4] VAR←'outer'
[5] {
[6] VAR←'inner'
[7] f1←{
[8] VAR≡'inner':f2 ⍵ ⍝ OK so far
[9] 0 ⍝ fails
[10] }
[11] f2←{
[12] VAR≡'inner':1 ⍝ OK
[13] 0 ⍝ fails
[14] }
[15] ⍵:⊢f1 oper ⍵ ⍝ stack call
[16] f1 oper ⍵ ⍝ tail call
[17] }⍵
[18] }

'.' ⎕wg 'aplversion'
Windows 18.0.39262.0 W Development
bug17 0
1
bug17 1
1
User avatar
JoHo
 
Posts: 26
Joined: Sat Nov 28, 2009 12:51 pm
Location: Austria, EU

Next

Return to Language

Who is online

Users browsing this forum: No registered users and 1 guest