PLT 方案指南说它实现的排序功能能够使用 lambda 函数根据提取的值对列表进行排序。链接文本
该指南提供了一个不起作用的代码示例-
(sort '(("aardvark") ("dingo") ("cow") ("bear"))
#:key car string<?)
返回错误。
这个函数应该如何被调用,以便它实际上根据给定函数计算的值对列表进行排序?
这个对我有用。您使用的是哪种方案方言?你得到什么错误?在我的 DrScheme 设置中,我从左下角的下拉列表中选择了“模块”,并且
#lang scheme
在顶部窗口中运行。
My guess is similar to Neil's: first, you should be using a recent version of PLT for that. Try to run this when DrScheme is in the Module language (the first choice in the language selection dialog):
#lang scheme
(sort '(("aardvark") ("dingo") ("cow") ("bear"))
#:key car string<?)
Second, that syntax uses keyword arguments, so if you're using some language like R6RS or R5RS or Pretty Big etc, then you won't be able to use sort with a keyword like that. (It's best to just stick with the module language and #lang scheme
.)