Special cases for Key
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 !
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 !
2 posts
• Page 1 of 1
Special cases for Key
Given that ,∘≢ is so much more obvious (and concise) than {⍺,≢⍵} and that they are barely different in execution time
cmpx '{⍺,≢⍵}⍨z' ',∘≢⍨z' ⊣ z←?99⍴99I was surprised to find the enormous difference when applied to key (⌸)
{⍺,≢⍵}⍨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% ⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕
cmpx '{⍺,≢⍵}⌸z' ',∘≢⌸z' ⊣ z←?99⍴99I 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.
{⍺,≢⍵}⌸z → 7.4E¯7 | 0% ⎕
,∘≢⌸z → 2.7E¯5 | +3518% ⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕
- Are all special cases dfns?
Are dfns easier to recognise in this context?
Is there a list of special cases?
-
Phil Last - Posts: 628
- Joined: Thu Jun 18, 2009 6:29 pm
- Location: Wessex
Re: Special cases for Key
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:
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.
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: 238
- Joined: Thu Jul 28, 2011 10:53 am
2 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 1 guest
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group