{"id":6548,"date":"2020-12-10T13:34:26","date_gmt":"2020-12-10T13:34:26","guid":{"rendered":"https:\/\/www.dyalog.com\/blog\/?p=6548"},"modified":"2020-12-10T13:34:26","modified_gmt":"2020-12-10T13:34:26","slug":"enhanced-debugging-with-function-keys-evaluate-selection","status":"publish","type":"post","link":"https:\/\/www.dyalog.com\/blog\/2020\/12\/enhanced-debugging-with-function-keys-evaluate-selection\/","title":{"rendered":"Enhanced Debugging with Function Keys &#8211; Evaluate selection"},"content":{"rendered":"<p><i>See also <a href=\"https:\/\/www.dyalog.com\/blog\/2018\/09\/enhanced-debugging-with-function-keys\/\">Enhanced Debugging with Function Keys<\/a>.<\/i><\/p>\n<p>When tracing through a complex dfn and reaching a guard (<code class=\"language-apl\">condition:result<\/code>), I am often wary of tracing into that line because if the condition evaluates to <code class=\"language-apl\">1<\/code> then the current function I&#8217;m tracing through will terminate and return the result, leading to me losing situational awareness. Normally, I&#8217;d select the condition expression, copy it, move to the session and execute the expression, so I can predict what will happen next. Can we automate this? Yes we can.<\/p>\n<p>Now, I usually prefer the Windows IDE for my daily development, but this is actually a case where RIDE has neat feature that&#8217;s missing from the IDE (but if you keep reading, I&#8217;ll show you how to achieve a similar effect in the IDE). In RIDE, go to <strong>Edit \u21d2 Preferences \u21d2 Shortcuts<\/strong> (or simply click \u2328\ufe0e at the right end of the language bar), then type the name of a function key you want to use for this purpose, followed by a space, for example &#8220;F6 &#8221; for <button>F6<\/button>. You&#8217;ll see exactly one entry in the listing. In the input field, write &#8220;&lt;VAL&gt;&#8221; (without quotes):<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-6559\" src=\"https:\/\/www.dyalog.com\/blog\/wp-content\/uploads\/2020\/11\/Screenshot-2020-11-11-102525.png\" alt=\"\" width=\"787\" height=\"696\" srcset=\"https:\/\/www.dyalog.com\/blog\/wp-content\/uploads\/2020\/11\/Screenshot-2020-11-11-102525.png 787w, https:\/\/www.dyalog.com\/blog\/wp-content\/uploads\/2020\/11\/Screenshot-2020-11-11-102525-300x265.png 300w, https:\/\/www.dyalog.com\/blog\/wp-content\/uploads\/2020\/11\/Screenshot-2020-11-11-102525-768x679.png 768w, https:\/\/www.dyalog.com\/blog\/wp-content\/uploads\/2020\/11\/Screenshot-2020-11-11-102525-339x300.png 339w\" sizes=\"auto, (max-width: 787px) 100vw, 787px\" \/><\/p>\n<p>I defined a simple function to test it with, and traced into that:<\/p>\n<pre><code class=\"language-apl\">      \u2395VR\u2395FX'f\u2190{' '\u237a\u2227\u2375:''both''' '\u237a\u2228\u2375:''either''' '''neither''' '}'\r\n     \u2207 f\u2190{\r\n[1]        \u237a\u2227\u2375:'both'\r\n[2]        \u237a\u2228\u2375:'either'\r\n[3]        'neither'\r\n[4]    }\r\n     \u2207 \r\n      f<\/code><\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-6552\" src=\"https:\/\/www.dyalog.com\/blog\/wp-content\/uploads\/2020\/11\/TraceIn.png\" alt=\"Tracing into f\" width=\"767\" height=\"480\" srcset=\"https:\/\/www.dyalog.com\/blog\/wp-content\/uploads\/2020\/11\/TraceIn.png 767w, https:\/\/www.dyalog.com\/blog\/wp-content\/uploads\/2020\/11\/TraceIn-300x188.png 300w, https:\/\/www.dyalog.com\/blog\/wp-content\/uploads\/2020\/11\/TraceIn-479x300.png 479w\" sizes=\"auto, (max-width: 767px) 100vw, 767px\" \/><br \/>\nUpon reaching a guard, I select the condition:<br \/>\n<img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-6554\" src=\"https:\/\/www.dyalog.com\/blog\/wp-content\/uploads\/2020\/11\/Select.png\" alt=\"Selecting the condition\" width=\"767\" height=\"480\" srcset=\"https:\/\/www.dyalog.com\/blog\/wp-content\/uploads\/2020\/11\/Select.png 767w, https:\/\/www.dyalog.com\/blog\/wp-content\/uploads\/2020\/11\/Select-300x188.png 300w, https:\/\/www.dyalog.com\/blog\/wp-content\/uploads\/2020\/11\/Select-479x300.png 479w\" sizes=\"auto, (max-width: 767px) 100vw, 767px\" \/><br \/>\nAnd Press <button>F6<\/button>:<br \/>\n<img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-6553\" src=\"https:\/\/www.dyalog.com\/blog\/wp-content\/uploads\/2020\/11\/PressF6.png\" alt=\"Pressing F6\" width=\"767\" height=\"480\" srcset=\"https:\/\/www.dyalog.com\/blog\/wp-content\/uploads\/2020\/11\/PressF6.png 767w, https:\/\/www.dyalog.com\/blog\/wp-content\/uploads\/2020\/11\/PressF6-300x188.png 300w, https:\/\/www.dyalog.com\/blog\/wp-content\/uploads\/2020\/11\/PressF6-479x300.png 479w\" sizes=\"auto, (max-width: 767px) 100vw, 767px\" \/><br \/>\nVoil\u00e0!<\/p>\n<h2>Cool, but how about the IDE?<\/h2>\n<p>Right, the Windows IDE doesn&#8217;t support the <b>VAL<\/b> command code, but we can easily emulate it by combining multiple command codes and assigning them to an F-key using <code class=\"language-apl\">\u2395PFKEY<\/code>.<\/p>\n<p>What we need to do is:<\/p>\n<ol>\n<li>Copy the current selection<\/li>\n<li>Jump to the session<\/li>\n<li>Paste<\/li>\n<li>Execute<\/li>\n<li>Jump back again<\/li>\n<\/ol>\n<p><strong>Options \u21d2 Configure\u2026 \u21d2 Keyboard Shortcuts \u21d2 Description<\/strong> gives that the command codes for &#8220;Copy&#8221;, &#8220;JumP between current window and session window&#8221;, and &#8220;Paste&#8221; are <code>CP<\/code>, <code>JP<\/code>, and <code>PT<\/code>. We use <code>ER<\/code> (you can find all but <code>JP<\/code> using the <code class=\"language-apl\">]KeyPress<\/code> user command too) to press <button>Enter<\/button>. Here we go:<\/p>\n<pre><code class=\"language-apl\">      'CP' 'JP' 'PT' 'ER' 'JP' \u2395PFKEY 6\r\n\u250c\u2500\u2500\u252c\u2500\u2500\u252c\u2500\u2500\u252c\u2500\u2500\u252c\u2500\u2500\u2510\r\n\u2502CP\u2502JP\u2502PT\u2502ER\u2502JP\u2502\r\n\u2514\u2500\u2500\u2534\u2500\u2500\u2534\u2500\u2500\u2534\u2500\u2500\u2534\u2500\u2500\u2518<\/code><\/pre>\n<h2>Keep it so!<\/h2>\n<p>RIDE keeps its setting, but of course, I wouldn&#8217;t want to be bothered with setting this up for every IDE session. So here&#8217;s a trick to set up F-keys (or anything else for that matter). When Dyalog APL starts up, it will look for <strong>MyUCMDs\\setup.dyalog<\/strong> in your <strong>Documents<\/strong> folder (<strong>$HOME\/MyUCMDs\/setup.dyalog<\/strong> on non-Windows). If this file contains a function named <code>Setup<\/code>, it will be run whenever APL starts:<\/p>\n<pre><code class=\"language-apl\">      \u2207Setup\r\n[1]  '&lt;F6&gt; is: ','CP' 'JP' 'PT' 'ER' 'JP' \u2395PFKEY 6\r\n[2]  \u2207\r\n      (\u2282\u2395NR'Setup')\u2395NPUT'C:\\Users\\Adam.DYALOG\\Documents\\MyUCMDs\\setup.dyalog'\r\n<\/code><\/pre>\n<p>And now, when I start APL:<br \/>\n<img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-6555\" src=\"https:\/\/www.dyalog.com\/blog\/wp-content\/uploads\/2020\/11\/Start.png\" alt=\"Upon start\" width=\"887\" height=\"375\" srcset=\"https:\/\/www.dyalog.com\/blog\/wp-content\/uploads\/2020\/11\/Start.png 887w, https:\/\/www.dyalog.com\/blog\/wp-content\/uploads\/2020\/11\/Start-300x127.png 300w, https:\/\/www.dyalog.com\/blog\/wp-content\/uploads\/2020\/11\/Start-768x325.png 768w, https:\/\/www.dyalog.com\/blog\/wp-content\/uploads\/2020\/11\/Start-500x211.png 500w\" sizes=\"auto, (max-width: 887px) 100vw, 887px\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>See also Enhanced Debugging with Function Keys. When tracing through a complex dfn and reaching a guard (condition:result), I am often wary of tracing into that line because if the condition evaluates to 1 then the current function I&#8217;m tracing &hellip; <a href=\"https:\/\/www.dyalog.com\/blog\/2020\/12\/enhanced-debugging-with-function-keys-evaluate-selection\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":25,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[18,19],"tags":[],"class_list":["post-6548","post","type-post","status-publish","format-standard","hentry","category-tips-tricks","category-tools"],"_links":{"self":[{"href":"https:\/\/www.dyalog.com\/blog\/wp-json\/wp\/v2\/posts\/6548","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\/25"}],"replies":[{"embeddable":true,"href":"https:\/\/www.dyalog.com\/blog\/wp-json\/wp\/v2\/comments?post=6548"}],"version-history":[{"count":16,"href":"https:\/\/www.dyalog.com\/blog\/wp-json\/wp\/v2\/posts\/6548\/revisions"}],"predecessor-version":[{"id":6613,"href":"https:\/\/www.dyalog.com\/blog\/wp-json\/wp\/v2\/posts\/6548\/revisions\/6613"}],"wp:attachment":[{"href":"https:\/\/www.dyalog.com\/blog\/wp-json\/wp\/v2\/media?parent=6548"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.dyalog.com\/blog\/wp-json\/wp\/v2\/categories?post=6548"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.dyalog.com\/blog\/wp-json\/wp\/v2\/tags?post=6548"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}