我一直在玩Red,我想出了如何对列表进行排序:
--== Red 0.5.1 ==--
Type HELP for starting information.
red>> list: [1 9 6 8]
== [1 9 6 8]
red>> sort list
== [1 6 8 9]
我想向后排序这个列表。我怎样才能做到这一点?我尝试了各种组合:
red>> sort !list
*** Script error: !list has no value
*** Where: sort
red>> !sort list
*** Script error: !sort has no value
*** Where: try
red>> sort reverse list
== [1 6 8 9]
red>> sort list reverse
*** Script error: reverse is missing its series argument
*** Where: reverse
答案 0 :(得分:5)
SORT有一个/反向细化,可以让你实现你想要的目标:
red>> sort/reverse [1 9 6 8]
== [9 8 6 1]
另请注意,SORT 会修改其参数。
您可以使用集成的帮助系统找到有关SORT(或任何其他功能)如何工作的更多信息:
red>> help sort
USAGE:
sort series /case /skip size /compare comparator /part length /all /reverse /stable
DESCRIPTION:
Sorts a series (modified); default sort order is ascending.
sort is of type: action!
ARGUMENTS:
series [series!]
REFINEMENTS:
/case => Perform a case-sensitive sort.
/skip => Treat the series as fixed size records.
size [integer!]
/compare => Comparator offset, block or function.
comparator [integer! block! any-function!]
/part => Sort only part of a series.
length [number! series!]
/all => Compare all fields.
/reverse => Reverse sort order.
/stable => Stable sorting.
答案 1 :(得分:3)
red>> reverse sort list
== [9 8 6 1]
它是基于堆栈的,所以你需要从右到左阅读它。你可以把它写成:
red>> reverse (sort list)
想象它更好。