Scheme/Racket
1
Name:
Anonymous
2012-11-19 14:07
Can someone explain this shit to me?
CODE
(define insertion-sort
(lambda (lst)
(if (null? lst)
'()
(insert (car lst)
(insertion-sort (cdr lst))))))
(define insert
(lambda (elt sorted-lst)
(if (null? sorted-lst)
(list elt)
(if (<= elt (car sorted-lst))
(cons elt sorted-lst)
(cons (car sorted-lst)
(insert elt (cdr sorted-lst))))))))
RESULT
(insertion-sort '(5 9 8 4 2))
(2 4 5 8 9)
2
Name:
Anonymous
2012-11-19 15:03
What part don't you understand exactly?
If you don't get how Lisp expressions return values, then obviously you won't know why the control flow is written the way it is. But there are a lot of other things to not get about this code. Please narrow it down.
3
Name:
Anonymous
2012-11-19 23:49
>>1
insertion-sort sorts le list and insert inserts le elt into le sorted list.
4
Name:
Anonymous
2012-11-20 0:01
This would be three lines in C and not look like dick.
5
Name:
Anonymous
2012-11-20 1:19
>>4
HEY functional programming is very expressive. You shut your whore mouth, BITCH!
6
Name:
Anonymous
2012-11-20 2:17
Optimize your function definitions, Ahmed .
7
Name:
noko
2012-11-20 3:33
>>4
>anything taking three lines in C
>anything in C not looking like dick.
8
Name:
Anonymous
2012-11-20 3:35
>>7
Back to le /g/redditnews,
shitstain .
9
Name:
Anonymous
2012-11-20 5:40
isort :: (Ord a) => [a] -> [a]
isort [] = []
isort (x:xs) = ins x (isort xs)
ins :: (Ord a) => a -> [a] -> [a]
ins x [] = [x]
ins x (y:ys)
| x <= y = x : y : ys
| otherwise = y : ins x ys
10
Name:
Anonymous
2012-11-20 5:57
11
Name:
Anonymous
2012-11-20 5:58
NIGGERs
12
Name:
Anonymous
2012-11-20 7:51
I'm gonna need the Symta of this too.
13
Name:
Anonymous
2012-11-20 8:45
>>8
C is undefined shit, faggot.
14
Name:
Anonymous
2012-11-20 10:32
>>12
Symta:
f l @ . $ ! [-] a - + / 54adsfasdfasdfadsf
15
Name:
Anonymous
2012-11-20 12:56
>>14
What happened to the Symta implementation of WC2?
16
Name:
Anonymous
2012-11-20 14:28
>>14
optimized symta:
סוג הכניסה ( ͡° ͜ʖ ͡°)
17
Name:
Anonymous
2012-11-20 14:50
>>16
( ͡° ͜ʖ ͡°) le /frog/ face
18
Name:
Anonymous
2012-11-20 15:36
( ͜° ʖ ͜°)
19
Name:
( ͡° ͜ʖ ͡°)
2012-11-20 15:45
( ͡° ͜ʖ ͡°)