⎕SI in DFNS : help

For users of dfns, both novice and expert
Post Reply
User avatar
giangiquario
Posts: 46
Joined: Thu Nov 26, 2009 8:55 am
Location: Milano, Italia

⎕SI in DFNS : help

Post by giangiquario »

Not able to understand the behaviour of ⎕SI and ⎕STACK in defined functions.

I prepared the following:

TOPFN←{
⎕←'§§§§§§§§§§§§§§'
⎕←'⎕SI at level 0:',⎕SI
⎕←'⍴⎕LC:',(⍴⎕LC),' ⊃⍴⎕STACK:',⊃⍴⎕STACK
⎕←⎕STACK
CALLED1←{
⎕←'§§§§§§§§§§§§§§'
⎕←'⎕SI at level 1:',⎕SI
⎕←'⍴⎕LC:',(⍴⎕LC),' ⊃⍴⎕STACK:',⊃⍴⎕STACK
⎕←⎕STACK
CALLED2←{
⎕←'§§§§§§§§§§§§§§'
⎕←'⎕SI at level 2:',⎕SI
⎕←'⍴⎕LC:',(⍴⎕LC),' ⊃⍴⎕STACK:',⊃⍴⎕STACK
⎕←⎕STACK

}
CALLED2 ⍵
}
CALLED1 ⍵
}


and executed
TOPFN ''

The result is (Dyalog 13/Classic 32):


§§§§§§§§§§§§§§
⎕SI at level 0: TOPFN
⍴⎕LC: 1 ⊃⍴⎕STACK: 2
∇TOPFN
*
§§§§§§§§§§§§§§
⎕SI at level 1: TOPFN
⍴⎕LC: 1 ⊃⍴⎕STACK: 3
∇CALLED1
∇TOPFN
*
§§§§§§§§§§§§§§
⎕SI at level 2: TOPFN
⍴⎕LC: 1 ⊃⍴⎕STACK: 4
∇CALLED2
∇CALLED1
∇TOPFN
*


Here the state indicator stack looks like correct, the state indicator is not aligned.
Please note that the function CALLED2 is local to CALLED1.

Thank you for help.
JohnS|Dyalog

Re: ⎕SI in DFNS : help

Post by JohnS|Dyalog »

This is a bug in ⎕STACK, which has not been made Dfn-aware.

In your example CALLED1 and CALLED2 are both tail calls and so should not show an increase in the size of the state indicator. In fact, internally, for a lexically-inward tail call, a vestigial stack frame is retained until the lexical level ({} nesting depth) drops, when it is removed.

The bug is that the code for ⎕SI and ⎕LC has been amended to ignore these "invisible" stack frames but the code for ⎕STACK hasn't yet.

Here is a simple repro:

      {{⍬∘⍴∘⍴¨⎕lc ⎕si ⎕stack}⍵}0    ⍝ should return 1 1 1
1 1 2

I have logged this as a bug, ref[7766].
User avatar
giangiquario
Posts: 46
Joined: Thu Nov 26, 2009 8:55 am
Location: Milano, Italia

Re: ⎕SI in DFNS : help

Post by giangiquario »

JohnS|Dyalog wrote:
      Here is a simple repro:

{{⍬∘⍴∘⍴¨⎕lc ⎕si ⎕stack}⍵}0 ⍝ should return 1 1 1
1 1 2




I think that 1 1 2 is correct.
In fact ⎕STACK must contain a second row related to "desk calculator level".

Do I miss something?
Post Reply