Special cases for Key

APL-related discussions - a stream of APL consciousness.
Not sure where to start a discussion ? Here's the place to be
Forum rules
This forum is for discussing APL-related issues. If you think that the subject is off-topic, then the Chat forum is probably a better place for your thoughts !

Special cases for Key

Postby Phil Last on Thu Oct 05, 2017 12:25 pm

Given that ,∘≢ is so much more obvious (and concise) than {⍺,≢⍵} and that they are barely different in execution time
      cmpx '{⍺,≢⍵}⍨z' ',∘≢⍨z' ⊣ z←?99⍴99
  {⍺,≢⍵}⍨z → 4.0E¯7 |   0% ⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕
  ,∘≢⍨z    → 3.5E¯7 | -14% ⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕     
      cmpx '{⍺,≢⍵}¨⍨z' ',∘≢¨⍨z' ⊣ z←?99⍴99
  {⍺,≢⍵}¨⍨z → 2.2E¯5 |  0% ⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕  
  ,∘≢¨⍨z    → 2.3E¯5 | +5% ⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕
I was surprised to find the enormous difference when applied to key (⌸)
      cmpx '{⍺,≢⍵}⌸z' ',∘≢⌸z' ⊣ z←?99⍴99
{⍺,≢⍵}⌸z → 7.4E¯7 | 0% ⎕
,∘≢⌸z → 2.7E¯5 | +3518% ⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕
I understand there are special cases for key similar but not quite the same as "idioms". The examples in the help for Key are all dfns.
    Are all special cases dfns?
    Are dfns easier to recognise in this context?
    Is there a list of special cases?
User avatar
Phil Last
 
Posts: 433
Joined: Thu Jun 18, 2009 6:29 pm

Re: Special cases for Key

Postby Roger|Dyalog on Thu Oct 05, 2017 5:19 pm

There is a list of the special codes. It is our intention that this be in the Dyalog documentation somewhere, but currently may have slipped through the cracks.

In the material for the SA3 workshop in the recent Dyalog User Meeting, there are lists of special codes for ⌺, ⍤, ⌸, and trains. You can get the workshop material here. The list for ⌸ is as follows:

      .
{f⌿⍵} for f one of + ⌈ ⌊ or ∧ ∨ = ≠ for boolean right arguments;
also / instead of ⌿ for vector right arguments
{⍺(f⌿⍵)}
{⍺,f⌿⍵} for numeric left arguments

{≢⍵}
{⍺(≢⍵)}
{⍺,≢⍵} for numeric left arguments

{≢∪⍵}
{⍺(≢∪⍵)}
{⍺,≢∪⍵} for numeric left arguments

{⊂⍵}
{⍺⍵}
{⍺} also ⊣

It is our intention that special codes in operators be dfns or primitive functions. There are a few exceptions "grandfathered in", implemented before we realized that dfns are much better for this purpose -- easier to understand, easier to remember, easier in more complicated cases (e.g. {⍺(≢⍵)}⌸ or {⍺(≢∪⍵)}⌸), fits better with the rest of Dyalog APL, etc.

Dfns can in fact be harder to recognize. For example (your example), {⍺,≢⍵} is harder to recognize than ,∘≢. But that is not (and should not) be a consideration from the user's point of view.
Roger|Dyalog
 
Posts: 107
Joined: Thu Jul 28, 2011 10:53 am


Return to APL Chat

Who is online

Users browsing this forum: No registered users and 1 guest