Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Feature request: two level sorting



On Jun 15,  8:25pm, Mikael Magnusson wrote:
}
} Can we do what the oe:: flag does for globbing? Ie, pass each element
} to a custom code snippet that transforms it arbitrarily, and sort on
} the output.

We considered that a while back, but the problem is that if you allow
arbitrary shell code to be called from within the sort algorithm there
are way too many opportunities for madness.

With globbing, there's one well-defined place -- the read of the name
from the directory structure -- where the callback can be applied to
a single data element.  With a sort, the callback may be invoked many
times for pairs of data, sometimes even more than once for the same
pair depending on the algorithm, and unlike e.g. perl that has object
pointers and reference-count garbage collection and lexical scopiing
and a whole other panoply of protections against the user shooting
himself, in zshell code all sorts of havoc could be wrought.  (Yeah,
you can probably create the same havoc in perl if you work at it, but
it's a lot more difficult.)

Falling back to something lesser/safer amounts to inventing a whole
new mini-language.  It's just not worth it to internalize in the shell
something that (a) other languages do better and (b) was intended by
the original architecture to be done in an outside process anyway.



Messages sorted by: Reverse Date, Date, Thread, Author