TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Perl6: Unary Sort

66 点作者 patrickas超过 11 年前

7 条评论

ciderpunx超过 11 年前
I really need to take a proper looks at Perl 6 -- it has some nice characteristics. Maybe that's my new years resolution.
评论 #6953915 未加载
yxhuvud超过 11 年前
Somehow I prefer the Ruby solution to add another method to do the unary variant. Compare<p><pre><code> [&quot;A&quot;,&quot;b&quot;,&quot;C&quot;].sort {|a, b| a.downcase &lt;=&gt; b.downcase } </code></pre> to<p><pre><code> [&quot;A&quot;,&quot;b&quot;,&quot;C&quot;].sort_by {|k| k.downcase } </code></pre> (or equivalently)<p><pre><code> [&quot;A&quot;,&quot;b&quot;,&quot;C&quot;].sort_by &amp;:downcase</code></pre>
评论 #6954823 未加载
adrianmsmith超过 11 年前
Great stuff, nevertheless the following is a surely a regression:<p><i>&gt; Note that in Perl 6, cmp is smart enough to compare strings with string semantics and numbers with number semantics, so producing numbers in the transformation code generally does what you want.</i><p>Perl 5 had a clear distinction between &quot;cmp&quot; (string comparison) and &quot;&lt;=&gt;&quot; (numeric comparison). Trying to work out the data type, and thus the comparison approach, from the actual data itself, is surely going to create subtle bugs, that don&#x27;t appear in testing, but do appear with live data.
评论 #6954155 未加载
评论 #6954537 未加载
rmc超过 11 年前
Python has this with the &quot;key&quot; argument to &quot;sort&quot;.<p><pre><code> list.sort(key=lambda x: x.lower())</code></pre>
评论 #6955400 未加载
评论 #6954429 未加载
orblivion超过 11 年前
One thing this article does not cover is that, even if a comparison function doesn&#x27;t do anything slow, there is still the fact that it still has to do a Perl function call O(n log n) times. At least in the equivalent with Python, I think it is advised to use the key function rather than comparison funtion for this reason, for speed. Though I guess a key function needs to take more space if it is to memoize.
评论 #6954655 未加载
Grue3超过 11 年前
So, it&#x27;s a feature that has been available in every high-order language since forever, except with more line noise. Typical Perl!<p><a href="http://www.ai.mit.edu/projects/iiip/doc/CommonLISP/HyperSpec/Body/fun_sortcm_stable-sort.html" rel="nofollow">http:&#x2F;&#x2F;www.ai.mit.edu&#x2F;projects&#x2F;iiip&#x2F;doc&#x2F;CommonLISP&#x2F;HyperSpec...</a>
tarpden超过 11 年前
While it appears that Perl 6 has many impressive features, I&#x27;m much more interested in practical matters such as: module versioning, installation, &amp; removal; the state of MoarVM; and the state of the tutorial book.
评论 #6958771 未加载