Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Macgyver :D

Name: Anonymous 2009-10-14 0:22

i just wanna be like him
:)

Name: Anonymous 2009-10-16 19:23

What's the point in demanding functional implementations?
You can emulate state generally(not talking just about tail-recursion + TCO here!) in a functional manner, even if without a very smart compiler it would be terribly inefficient when compiled. Of course, a purely functional implementation that just did the right thing instead of emulating state would be much more proper and faster.

Name: Anonymous 2009-10-16 19:43

>>57
I'm too lazy to write the stable version, would you accept a 3 minute nonstable version?

Name: Anonymous 2009-10-16 19:46

>>60
Here's the non-stable version by the way. It could use a refactoring and I guess I'll do that when I write the stable verson.

(define (split num l)
  (let iter ((original l) (lt '()) (gt '()))
    (cond ((null? original)
           (list (reverse lt) (reverse gt)))
          ((< (car original) num)
           (iter (cdr original) (cons (car original) lt) gt))
          (else
           (iter (cdr original) lt (cons (car original) gt))))))

(define (qs l)
  (cond ((null? l) l)
        ((null? (cdr l)) l)
        (else
         (let* ((pivot-a (car l))
                (pivot-b (cadr l))
                (rest (cddr l))
                (first (min pivot-a pivot-b))
                (second (max pivot-a pivot-b))
                (split-at-first (split first rest))
                (start (car split-at-first))
                (split-at-second (split second (cadr split-at-first)))
                (middle (car split-at-second))
                (end (cadr split-at-second)))
           (append (qs start) (list first) (qs middle) (list second) (qs end))))))

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List