Talk:Order disjoint list items

From Rosetta Code
Revision as of 04:40, 13 May 2014 by rosettacode>TimToady (→‎Perl 6 entry: regarding members of N not in M)

Inspiration

I thought "what if you ordered part of a list, not by indices as in Sort disjoint sublist, but by giving a list of items ..." --Paddy3118 (talk) 09:17, 4 May 2014 (UTC)

Perl 6 entry

I don't have the 2014 version of Rakudo, but can someone who does test how the Perl 6 code reacts to the input M = <X X Y> and N = <Y>?

Edit: and M = <A X> and N = <Y A> for that matter. --Ledrug (talk) 02:20, 13 May 2014 (UTC)

I've added the requested cases; you'll note that the solution to A X ==> Y A assumes (reasonably, I think) that the N list elements are a subset of the M elements, as the task postulates without commentary on violations. The reason I think this assumption is okay is that it scales well to arbitrarily long M lists (indeed, Perl 6 could apply this function lazily to an infinitely long M list, though of course it can't work with an infinitely long N list due to the necessity of testing set/bag membership). We tend to avoid solutions that require an unnecessary prescan of a list for this reason, and it would take such an "unnecessary" prescan of M to enforce set membership in the other direction. In any case, whether or not your language supports infinite lists, it's extra work, and prevents the function from being used to substitute a list of words that weren't in the original, which seem like a kind of arbitrary restriction from a practical point of view. --TimToady (talk) 04:40, 13 May 2014 (UTC)