{"id":2405,"date":"2015-05-06T08:20:21","date_gmt":"2015-05-06T08:20:21","guid":{"rendered":"http:\/\/www.dyalog.com\/blog\/?p=2405"},"modified":"2015-05-07T06:20:59","modified_gmt":"2015-05-07T06:20:59","slug":"do-functions-know-their-own-names","status":"publish","type":"post","link":"https:\/\/www.dyalog.com\/blog\/2015\/05\/do-functions-know-their-own-names\/","title":{"rendered":"Do Functions Know Their Own Names?"},"content":{"rendered":"<p>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&#8217;t and me taking the side that they do.<\/p>\n<p>Essentially, John would argue that after <code class=\"language-apl\">A\u21902<\/code>, the &#8220;2&#8221; does not know that it is called &#8220;A&#8221;. So after (in modern parlance):<\/p>\n<pre><code class=\"language-apl\">      add\u2190{\r\n          \u237a+\u2375\r\n      }<\/code><\/pre>\n<p>the part in <code class=\"language-apl\">{}<\/code> does not know that it is called &#8220;add&#8221;.<\/p>\n<p>The real question here can be put in different terms: Is the symbol <code class=\"language-apl\">+<\/code> representing the addition function itself or is it one of the possible names of the addition function.<\/p>\n<p>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:<\/p>\n<pre><code class=\"language-apl\">      add\u2190{\r\n          \u237a+\u2375\r\n      }<\/code><\/pre>\n<pre><code class=\"language-apl\">      times\u2190{\r\n          \u237a\u00d7\u2375\r\n      }<\/code><\/pre>\n<pre><code class=\"language-apl\">      inner\u2190{\r\n          \u237a \u237a\u237a.\u2375\u2375 \u2375\r\n      }<\/code><\/pre>\n<p>Now if we trace into<\/p>\n<pre><code class=\"language-apl\">      1 2 add inner times 3 4<\/code><\/pre>\n<p>and stop on <code class=\"language-apl\">inner[1]<\/code> what do we want to see when we type <code class=\"language-apl\">\u237a\u237a<\/code> in the session. There are two possibilities:<\/p>\n<p>Either you see:<\/p>\n<pre><code class=\"language-apl\">{\r\n    \u237a+\u2375\r\n}<\/code><\/pre>\n<p>or you see:<\/p>\n<pre><code class=\"language-apl\">\u2207add<\/code><\/pre>\n<p>Which of these is more useful?<\/p>\n<p>Being more provocative, try putting the functions in a capsule:<\/p>\n<pre><code class=\"language-apl\">[0] foo\r\n[1] 1 2{\r\n[2]     \u237a+\u2375\r\n[3] }{\r\n[4]     \u237a \u237a\u237a.\u2375\u2375 \u2375\r\n[5] }{\r\n[6]     \u237a\u00d7\u2375\r\n[7] }3 4<\/code><\/pre>\n<p>and repeatedly trace until <code class=\"language-apl\">[6]<\/code>:<\/p>\n<pre><code class=\"language-apl\">      )SI\r\n#.foo[6]*\r\n.\r\n#.foo[4]\r\n#.foo[1]<\/code><\/pre>\n<p>Compare this with the following:<\/p>\n<pre><code class=\"language-apl\">[0] goo\r\n[1] add\u2190{\r\n[2]     \u237a+\u2375\r\n[3] }\r\n[4] inner\u2190{\r\n[5]     \u237a \u237a\u237a.\u2375\u2375 \u2375\r\n[6] }\r\n[7] times\u2190{\r\n[8]     \u237a\u00d7\u2375\r\n[9] }\r\n[10] 1 2 add inner times 3 4<\/code><\/pre>\n<pre><code class=\"language-apl\">      )SI\r\n#.times[1]*\r\n.\r\n#.inner[1]\r\n#.goo[10]<\/code><\/pre>\n<p>In my view, the latter is much more communicative in a debugging environment.<\/p>\n<p>Going back to the version 0 discussion: We didn&#8217;t have dfns or dops, so everything was traditional. The discussion was centred around:<\/p>\n<pre><code class=\"language-apl\">\u2207r\u2190a add b\r\n[1] r\u2190a+b\r\n\u2207\r\n\r\n\u2207r\u2190a times b\r\n[1] r\u2190a\u00d7b\r\n\u2207\r\n\r\n\u2207 r\u2190a (f inner g) b\r\n[1] r\u2190a f.g b\r\n\u2207<\/code><\/pre>\n<p>Now trace this:<\/p>\n<pre><code class=\"language-apl\">      1 2 add inner times 3 4<\/code><\/pre>\n<p>until at <code class=\"language-apl\">times[1]<\/code><\/p>\n<p>The key question at the time was whether <code class=\"language-apl\">)SI<\/code> should show this:<\/p>\n<pre><code class=\"language-apl\">      )SI\r\n#.times[1]*\r\n.\r\n#.inner[1]<\/code><\/pre>\n<p>or this:<\/p>\n<pre><code class=\"language-apl\">      )SI\r\n#.g[1]*\r\n.\r\n#.inner[1]<\/code><\/pre>\n<p>We choose the first of these options as more informative.<\/p>\n<p>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 <code class=\"language-apl\">)SI<\/code> output.<\/p>\n<p>These days it might not be so obvious. In those days we were essentially thinking in terms of a scrolling paper terminal. It pre-dates the full screen experience that even the tty version gives you. We had to wait for Adam Curtis to join the team before we got that. With the context display whilst tracing there is a stronger argument that the eyes using the debugging information do not need the names. Whilst I admit to the weakening I don&#8217;t think it actually changes the balance of the case.<\/p>\n<p>We use a lot of C macros in the interpreter. On Linux, gdb gives us access to those macros when we debug the C code \u2013 lldb on MAC, dbx on AIX and Visual Studio on Windows all do not have that information and are, therefore, far less helpful.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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&#8217;t &hellip; <a href=\"https:\/\/www.dyalog.com\/blog\/2015\/05\/do-functions-know-their-own-names\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":20,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8,23],"tags":[],"class_list":["post-2405","post","type-post","status-publish","format-standard","hentry","category-apl-language","category-musings"],"_links":{"self":[{"href":"https:\/\/www.dyalog.com\/blog\/wp-json\/wp\/v2\/posts\/2405","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.dyalog.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.dyalog.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.dyalog.com\/blog\/wp-json\/wp\/v2\/users\/20"}],"replies":[{"embeddable":true,"href":"https:\/\/www.dyalog.com\/blog\/wp-json\/wp\/v2\/comments?post=2405"}],"version-history":[{"count":12,"href":"https:\/\/www.dyalog.com\/blog\/wp-json\/wp\/v2\/posts\/2405\/revisions"}],"predecessor-version":[{"id":2579,"href":"https:\/\/www.dyalog.com\/blog\/wp-json\/wp\/v2\/posts\/2405\/revisions\/2579"}],"wp:attachment":[{"href":"https:\/\/www.dyalog.com\/blog\/wp-json\/wp\/v2\/media?parent=2405"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.dyalog.com\/blog\/wp-json\/wp\/v2\/categories?post=2405"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.dyalog.com\/blog\/wp-json\/wp\/v2\/tags?post=2405"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}