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-15 21:22

>>39
The right answer is that lambda calculus could be used to emulate the behaviour of a memory manager. It can't be used to make a real memory manager as it's just a formal mathemathical system which has nothing to do with how hardware works. That said, you might be able to implement one if you defined a concrete language based on it and give it an FFI, or just access to primitive memory management functions, but that will no longer be lambda calculus, but a practical language based on it.

Name: >>41 2009-10-15 21:23

>>40
I'm a Lisper, and you can read my opinion in >>41.

Name: Anonymous 2009-10-15 22:55

>>43
I'm a >>41, and you can read my opinion in LISP

Name: Anonymous 2009-10-15 23:28

>>44
I'm a troll, and you have been trolled consistently.

Name: Anonymous 2009-10-15 23:39

>>44
トロールにトロールをトロールング。

Name: Anonymous 2009-10-16 5:51

>>40
Looks like someone went to a JavaSchool and thinks he can't write Generic Sort Algorithm #39 in functional languages.

Name: Anonymous 2009-10-16 15:35

>>46
Well..... You can't.

Name: Anonymous 2009-10-16 16:06

>>47
Shows wat you know.

(define bubble_sort
   X -> (bubble_again_perhaps (bubble X) X))

(define bubble
  [] -> []
  [X] -> [X]
  [X Y | Z] -> [Y | (bubble [X | Z])]   where    (> Y X)
  [X Y | Z] -> [X | (bubble [Y | Z])])

(define bubble_again_perhaps
   X X -> X
   X _ -> (bubble_sort X))

Name: Anonymous 2009-10-16 16:09

>>48
Far from elegant

Name: Anonymous 2009-10-16 16:16

>>48
It's like you took the worst part of Haskell syntax and LISP syntax, and mashed them together. And added toenail clippings.

Name: Anonymous 2009-10-16 16:19

>>50
Only that lisp doesn't have a worse part to have a worst part.

Name: Haxus the Liskellite 2009-10-16 16:34

>>50
U MENA LISKELL

Name: Anonymous 2009-10-16 16:50

>>48
Oh god, is that... Qi?!

Name: UMH memesmith !gNlkr4vCuc 2009-10-16 16:53

>>52
...shut up...

Name: Anonymous 2009-10-16 16:55

>>53
Qi
*fap fap fap*

Name: Anonymous 2009-10-16 17:00

>>53
Damn straight it is. I mostly like this example for its bubble_again_perhaps function.

Name: Anonymous 2009-10-16 18:35

>>56
Now write a dual-pivot quicksort in your precious functional language, without using any imperative features (loops, selection, state, etc...). Ensure that it is stable (equal keys appear in order).

Name: Anonymous 2009-10-16 18:39

i demand a functional implementation of a binary tree sort!

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

Name: Anonymous 2009-10-16 19:51

>>59-61
My point is functional languages will never be elegant or "better" in almost every real-world situation. Don't get me wrong, it's pretty neat being able to define factorial using pattern matching, but it really doesn't belong in mainstream programming.

Name: Anonymous 2009-10-16 19:54

Here's someone else's implementation in Common Lisp:

(defun quicksort (lst)
  (when lst
    (let ((pivot (car lst)))
      (append
       (quicksort (remove-if-not (lambda (x) (<= x pivot)) (cdr lst)))
       (list pivot)
       (quicksort (remove-if-not (lambda (x) (>  x pivot)) (cdr lst)))))))

Name: Anonymous 2009-10-16 19:55

>>62
Surely that's just being rather pedantic, It doesn't have to be better in almost every real-world situation. I'm from the SICP school of thought and I use the best form of modelling for the problem at hand. If it's expressed more clearly/efficiently with state, then I'll use state, but in many cases a functional approach is best.

Name: Anonymous 2009-10-16 19:55

>>63
It's not dual pivot ;)

Name: Anonymous 2009-10-16 19:56

>>62
I don't know about purely functional languages, but some more pragmatic ones make a lot of things much easier, but I don't care about what other people use(mainstream programming), as long as there's enough community to keep developing libraries and implementations for the language of my choice, in this case, Common Lisp.

Name: Anonymous 2009-10-16 20:06

>>62
Yaroslavskiy's Java implementation is three pages long. So there's one metric functional languages are “better” by.

Name: Anonymous 2009-10-16 20:09

>>67
How much of that is optimisations? Or is it just a vanilla dual-pivot quicksort? I know Java is verbose, but really?

Name: Anonymous 2009-10-16 20:16

>>68
A fair bit. Plus there's the colossal number of newlines (hurr, brace on its own line).

Name: Anonymous 2009-10-16 20:44

>>61
The stable version isn't substantially longer, but is UGLY AS FUCK™!. If anyone cares, I'll post after a refactor.

Name: Anonymous 2009-10-16 21:33

partition is stable, so:

import List

quicksort (p1': p2': l) =
   quicksort ltp1 ++ p1: quicksort gep1_lep2 ++ p2: quicksort gtp2
   where
      (p1, p2) = if p1' > p2' then (p2', p1') else (p1', p2')
      (ltp1,      gep1) = partition (< p1) l
      (gep1_lep2, gtp2) = partition (<=p2) gep1

quicksort l = l

Name: Anonymous 2009-10-16 21:36

>>71
Wait. Nevermind, that's unstable. Oh, well.

Name: Anonymous 2009-10-16 21:47

Now it's stable:

import List

quicksort (p1': p2': l)
   | p1 == p2  = quicksort ltp1 ++ p1: p2: quicksort gep1_lep2 ++ quicksort gtp2
   | otherwise = quicksort ltp1 ++ p1: quicksort gep1_lep2 ++ p2: quicksort gtp2
   where
      (p1, p2) = if p1' > p2' then (p2', p1') else (p1', p2')
      (ltp1,      gep1) = partition (< p1) l
      (gep1_lep2, gtp2) = partition (<=p2) gep1

quicksort l = l

Name: Haxus the Liskellite 2009-10-17 6:25

U MENA LISKELL

Name: Anonymous 2011-02-03 4:45

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