Symbols for sort idioms

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 !

Symbols for sort idioms

Postby michaelk on Mon Nov 08, 2021 6:30 am

Would it be possible to replace the two sort idioms ({(⊂⍋⍵)⌷⍵} and its counterpart) by symbols in a future release?
michaelk
 
Posts: 34
Joined: Wed Feb 10, 2010 8:38 am

Re: Symbols for sort idioms

Postby Morten|Dyalog on Mon Nov 08, 2021 6:54 am

Personally, I feel that this is important enough to consider making a rare breaking change to the language, starting by converting the existing dyadic ⍋ into a system function (⎕GRADE or ⎕SORT). In my opinion, sorting using a collation sequence should not have been a primitive, this is a library function. I believe that most existing uses could easily be found and converted in existing applications.

This would allow us to redefine dyadic ⍋ as "sort ⍵ by ⍺", as I believe it is in J (written /:~). This would make it possible to sort any array using "sort self", or ⍋⍨.
User avatar
Morten|Dyalog
 
Posts: 451
Joined: Tue Sep 09, 2008 3:52 pm

Re: Symbols for sort idioms

Postby petermsiegel on Mon Nov 08, 2021 8:09 pm

Since you (Morton) mention "library" functions, is Dyalog thinking about expanding its notion of libraries to allow dfns workspace-based routines and user-selectable routines to be available to calling functions in a more integrated way, similar to what's available in Python et al.? Currently, to use a display function (like disp or display) from a major user function, one might copy it in (each time) via ⎕CY, create by convention a homegrown namespace (e.g. ⎕SE.SYSLIB), or simply copy-and-paste wholesale as a local function.

Wouldn't it be nice if we had some more overt ⎕REQUIRE or ⎕IMPORT (or perhaps a :DIRECTIVE like :REQUIRE) type of feature whereby the run-time environment would take care of resolving imported names (based on a list of standard and user libraries) and caching imported objects? There are a number of useful routines in ⎕SE.Dyalog.Utils, as well as dfns.dws, that are imported in an ad hoc way today...

Just a thought...
petermsiegel
 
Posts: 140
Joined: Thu Nov 11, 2010 11:04 pm

Re: Symbols for sort idioms

Postby Morten|Dyalog on Mon Nov 08, 2021 8:25 pm

Short answer is "Yes", there will be some sessions taking a look at this problem space at Dyalog'21 tomorrow.
User avatar
Morten|Dyalog
 
Posts: 451
Joined: Tue Sep 09, 2008 3:52 pm

Re: Symbols for sort idioms

Postby Phil Last on Mon Nov 08, 2021 11:10 pm

Morten|Dyalog wrote:Personally, I feel that this is important enough to consider making a rare breaking change to the language,[...]
or you could give ⎕ML a negative value (given that Dyalog would be creating a new incompatibilty with all other APLs) that would make APL think you meant {(⊂⍋⍵)⌷⍵} and run the optimised code for it whenever it encountered .

Or how about removing the block on being able to re-assign primitives? Then we could just do
      ⍋ ← {(⊂⍋⍵)⌷⍵}

That would have the added benefit of allowing us to do other useful stuff like
      ÷ ← ⌊÷
or
      - ← |-
to avoid wasting time with those annoying fractions and negative numbers.
User avatar
Phil Last
 
Posts: 624
Joined: Thu Jun 18, 2009 6:29 pm
Location: Wessex

Re: Symbols for sort idioms

Postby Phil Last on Mon Nov 08, 2021 11:10 pm

Sorry Morten. I couldn't resist it.
User avatar
Phil Last
 
Posts: 624
Joined: Thu Jun 18, 2009 6:29 pm
Location: Wessex

Re: Symbols for sort idioms

Postby michaelk on Tue Nov 09, 2021 2:11 am

I had in mind some alteration of the ⍋ and ⍒ symbols to make two new symbols, perhaps by placing a hyphen at the bottom, much as ∊ and ⍷ are different symbols.
michaelk
 
Posts: 34
Joined: Wed Feb 10, 2010 8:38 am

Re: Symbols for sort idioms

Postby Morten|Dyalog on Tue Nov 09, 2021 5:35 am

Phil Last wrote:Sorry Morten. I couldn't resist it.


Hi Phil, I can see that! I'm trying to understand whether this is just your normal good sense of humour, or the jokes are your way of expressing that you think this would be a really bad idea and that countless lines of code would be broken by this change.

Making a breaking change to APL is not something to be considered lightly, I agree - and if there are strong feelings in the user community that this would cause significant problems, we obviously will not do it - but I could not resist floating the idea now that this discussion has started.

The reason why I feel that we might just want to consider it this one time is that, in 40 years of using APL, I have only met two or three people who fully understood the definition of dyadic grade and were able to use it for anything non-trivial. And, in all cases where I say dyadic grade used, it was embedded in a cover-function with a name like "SORT".

Finally, dyadic grade doesn't really allow you to do the kind of language-dependent sorting (phonetic etc) that modern applications really need - so a system function to tap into facilities to do that would be more useful.

Obviously with Unicode, there are lots of other symbols available - but even so, symbols will always be precious commodities.
User avatar
Morten|Dyalog
 
Posts: 451
Joined: Tue Sep 09, 2008 3:52 pm

Re: Symbols for sort idioms

Postby Phil Last on Tue Nov 09, 2021 10:01 am

To be serious. I don't like the idea of a breaking change unless it's to correct a long term error such as that that finally returned ⊂⍬ for ⍳⍬ rather than ⎕IO.

But I fully agree with your reservations regarding: (i) sort's reliance on grade when Roger has pointed out that sort is potentially a simpler or quicker operation than grade - i.e. grade is potentially a bi-product of sort rather than vice versa; (ii) that a way to make sort an inbuilt - whether system or primitive - operation is very desirable; and (iii) that the dyad is fairly incomprehensible - certainly more so than transpose - and probably very seldom used.

Nevertheless given that sort - with the same additional requirements you mention above under grade - would probably need the same plethora of arguments.

It seems to me that the problem is more to do with (i), which problem is currently mitigated by idiom recognition where optimised code replaces the need for separate grade then index operations. What we need is a way - using the same criteria - to choose either the sorted array or the result of grade by a simple switch and although I've railed against variant, preferring KEI's original name of "ad hoc" emphasising its complete arbitrariness, it offers itself as a (fairly) neat solution.
User avatar
Phil Last
 
Posts: 624
Joined: Thu Jun 18, 2009 6:29 pm
Location: Wessex

Re: Symbols for sort idioms

Postby Adam|Dyalog on Sun Nov 14, 2021 3:40 pm

michaelk wrote:Would it be possible to replace the two sort idioms ({(⊂⍋⍵)⌷⍵} and its counterpart) by symbols in a future release?

In principle, I agree with Morten about the classification of library functions and what should be primitives. The pairing of grade with sort-by makes a lot of sense to me too. However, I personally value backwards compatibility (and keeping existing books correct!) too highly to support such a breaking change.

Instead, I would make monadic ∧ and ∨ be sorting primitives because they are mnemonic as simpler versions of the glyphs ⍋ and ⍒. Think: ∧ overstruck with + or ⸸ gives ⍋ and ∨ overstruck with + or † gives ⍒.

A slight downside is that this pairs logical/number theoretical dyadic functions with comparison monadic functions, but we already have other such cross-field pairings like ∊ being comparison and structural (or type) while ≡ and ≢ perform comparisons together with structural/shape analysis.
User avatar
Adam|Dyalog
 
Posts: 134
Joined: Thu Jun 25, 2015 1:13 pm

Next

Return to APL Chat

Who is online

Users browsing this forum: No registered users and 1 guest