开发者

PLT Scheme sort function

开发者 https://www.devze.com 2022-12-19 15:09 出处:网络
PLT Scheme guide says that it\'s implemented sort function is able to sort a list according to an extarcted value using a lambda function. link text

PLT Scheme guide says that it's implemented sort function is able to sort a list according to an extarcted value using a lambda function. link text

The guide provides an unworking code example of this-

(sort '(("aardvark") ("dingo") ("cow") ("bear"))
      #:key car string<?)

Which returns an error.

How is this function is supposed to be calles so that it will actually sort a list acc开发者_开发知识库ording to values calculated by a given function?


It works for me. Which Scheme dialect are you using? And what error do you get? In my DrScheme setup, I have "Module" selected from the dropdown at the bottom left, and

 #lang scheme

run in the top window.


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.)

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号