zach chen
zach chen

Reputation: 119

sorting strings in lexicographical order in scheme

I'm new to scheme. I'm wondering how to sort strings in lexicographical order in scheme. For example:

(sort (list "cat" "apple" "dog"))
(apple cat dog)

In C++, I can have 'A'<'B', but it seems not work in scheme. I have referred online, but most are implemented in popular language, there are very few in scheme. So Can someone provide with an actual code in scheme and explain it? Thank you

Upvotes: 2

Views: 2247

Answers (1)

John Clements
John Clements

Reputation: 17203

An idiomatic answer to this question is going to depend a lot on which scheme implementation you're using. So, for instance, in Racket I would write

(sort (list "cat" "apple" "dog") string<?)

I see that you've tagged this question r5rs, and perhaps you're asking whether you can write this in R5RS scheme. Yes, you definitely can. But it's probably simpler just to use whatever your scheme implementation provides.

Upvotes: 1

Related Questions