# Do Functions Know Their Own Names?

Going back a long way when John Scholes and I were writing version 0 of Dyalog there was a big discussion about whether functions knew their own names. This discussion still surfaces, with John taking the side that they don’t and me taking the side that they do.

Essentially, John would argue that after `A←2`, the “2” does not know that it is called “A”. So after (in modern parlance):

``````      add←{
⍺+⍵
}``````

the part in `{}` does not know that it is called “add”.

The real question here can be put in different terms: Is the symbol `+` representing the addition function itself or is it one of the possible names of the addition function.

From an APL perspective, does this matter? Most of the time it makes no difference. However, when you view your SI stack it does. Consider:

``````      add←{
⍺+⍵
}``````
``````      times←{
⍺×⍵
}``````
``````      inner←{
⍺ ⍺⍺.⍵⍵ ⍵
}``````

Now if we trace into

``      1 2 add inner times 3 4``

and stop on `inner[1]` what do we want to see when we type `⍺⍺` in the session. There are two possibilities:

Either you see:

``````{
⍺+⍵
}``````

or you see:

``∇add``

Which of these is more useful?

Being more provocative, try putting the functions in a capsule:

``````[0] foo
[1] 1 2{
[2]     ⍺+⍵
[3] }{
[4]     ⍺ ⍺⍺.⍵⍵ ⍵
[5] }{
[6]     ⍺×⍵
[7] }3 4``````

and repeatedly trace until `[6]`:

``````      )SI
#.foo[6]*
.
#.foo[4]
#.foo[1]``````

Compare this with the following:

``````[0] goo
[2]     ⍺+⍵
[3] }
[4] inner←{
[5]     ⍺ ⍺⍺.⍵⍵ ⍵
[6] }
[7] times←{
[8]     ⍺×⍵
[9] }
[10] 1 2 add inner times 3 4``````
``````      )SI
#.times[1]*
.
#.inner[1]
#.goo[10]``````

In my view, the latter is much more communicative in a debugging environment.

Going back to the version 0 discussion: We didn’t have dfns or dops, so everything was traditional. The discussion was centred around:

``````∇r←a add b
[1] r←a+b
∇

∇r←a times b
[1] r←a×b
∇

∇ r←a (f inner g) b
[1] r←a f.g b
∇``````

Now trace this:

``      1 2 add inner times 3 4``

until at `times[1]`

The key question at the time was whether `)SI` should show this:

``````      )SI
#.times[1]*
.
#.inner[1]``````

or this:

``````      )SI
#.g[1]*
.
#.inner[1]``````

So naming things is good and using those names when reporting state information is also good. When the issue was disputed, David Crossley (who was managing the development of Dyalog) resolved it using the argument about the `)SI` output.