[plt-scheme] Quicksort in Scheme

From: John Clements (clements at brinckerhoff.org)
Date: Thu Jan 5 14:52:03 EST 2006

On Jan 4, 2006, at 12:36 PM, Greg Woodhouse wrote:

> --- Doug Orleans <dougorleans at gmail.com> wrote:
>> SRFI 1 has xcons:
>>   xcons d a -> pair
>>     (lambda (d a) (cons a d))
>>     Of utility only as a value to be conveniently passed to
>>     higher-order procedures.
>>       (xcons '(b c) 'a) => (a b c)
>>     The name stands for "eXchanged CONS."
> Maybe something like this
>> (define snoc
>     (lambda (l m)
>       (if (null? l) (list m)
>           (append (list (car l)) (snoc (cdr l) m)))))

Yikes!  how about replacing your (append...) with (cons (car l) (snoc  
(cdr l) m)) ? It's shorter & easier to read. (It's not asymptotically  
more efficient, though.)

Of course, if you already _have_ append, you can just define snoc as

(define snoc (lambda (l m) (append l (list m))))

I'm sorry, I just couldn't let that pass...

John Clements

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 2430 bytes
Desc: not available
URL: <http://lists.racket-lang.org/users/archive/attachments/20060105/e8444764/attachment.p7s>

Posted on the users mailing list.