views:

347

answers:

2

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 according to values calculated by a given function?

+1  A: 

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.

anon
+1  A: 

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

Eli Barzilay
@Eli All the recent questions on Scheme seem to be language/dialect related. As you obviously know what you are talking about (I just play with Scheme for fun) perhaps you could write a "best reference" answer to this (or to a question of your own origination)? Just an idea...
anon
Neil: I'm part of the PLT project, which is why I know about these things. If you're talking about a best reference question about PLT Scheme, then that should be pretty obvious (we have docs.plt-scheme.org, and it's also one of the major links at plt-scheme.org)... But I can't say that this is the best reference for Scheme in general since there are many other implementations.
Eli Barzilay