/PROG/SICP CHALLENGE
1
Name:
Anonymous
2008-09-01 7:21
IMPLEMENT THE COLLECTOR!!!
(((((o) 'a) 'b) 'c)) ; => (a b c)
2
Name:
Anonymous
2008-09-01 7:22
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAALISPAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
3
Name:
Anonymous
2008-09-01 8:10
Do it in scheme /prog/
4
Name:
Anonymous
2008-09-01 8:10
I desinged this puzzle for /prog/ only, why aren't you trying it?
5
Name:
Anonymous
2008-09-01 8:27
I solved this problem in my head. Just use closures.
6
Name:
Anonymous
2008-09-01 8:35
>>5
write your solution out and yes it uses closures fuckign obviosuly
7
Name:
Anonymous
2008-09-01 8:40
(define (o)
(let ((lst ()))
(define (collect . x)
(cond ((null? x)
lst)
(#t
(set! lst (append lst x))
collect)))
collect))
8
Name:
Anonymous
2008-09-01 9:03
>>6
I don't need to write solutions, I have everything I need in my head. Writing them would be a waste of time.
9
Name:
Anonymous
2008-09-01 9:33
Oh hai
sub o{
my($o,@list);
$o=sub{@_ and push @list,@_ and return $o or @list};
}
$,=", ";
print o->('a','b','c')->('x','yy')->();
------------
b:\> perl collect.pl
a, b, c, x, yy
b:\>
10
Name:
Anonymous
2008-09-01 9:49
>>7
fooi ATTEMPT, but it can be done much shortor
>>9
fuck off this a serious thread with real languages such as scheme
11
Name:
Anonymous
2008-09-01 9:50
12
Name:
Anonymous
2008-09-01 10:23
since none of you fuckwits could ever get it anyway
(define (o . y) (lambda x (if (null? x) y (apply o (append y x)))))
13
Name:
Anonymous
2008-09-01 10:29
>>8
fucks like you think you know everything then you try to write a real program and fail
14
Name:
Anonymous
2008-09-01 10:39
>>12
I cried when I saw that, such beautiful code............
15
Name:
Anonymous
2008-09-01 10:45
>>12
I cried when I saw that, such useless code............
16
Name:
Anonymous
2008-09-01 10:46
>15
I cried when I saw that, such YOU JUST LOST THE GAME code............
17
Name:
Anonymous
2008-09-01 10:58
>>13
YHBT
>>12
This solution is inefficient.
18
Name:
Anonymous
2008-09-01 11:04
Here's my solution:
def o(*args)
args
end
19
Name:
Anonymous
2008-09-01 11:13
class Collect a where
collect :: ([Int] -> [Int]) -> a
instance Collect [Int] where
collect acc = acc []
instance (Integral t, Collect b) => Collect (t -> b) where
collect acc x = collect (acc . (fromIntegral x:))
*Main> o 1 2 3 :: [Int]
[1,2,3]
o :: (Collect a) => a
o = collect id
20
Name:
Anonymous
2008-09-01 11:15
>>18
You're a twat
>>19
gb2/ reading Crazy Catamorphisms and Happy Hylomorphisms, Dancing a Figgly Jig in a Hindly Milner WHIRL.
21
Name:
Anonymous
2008-09-01 12:28
>>20
I'm a crazy twat, and that's that!
22
Name:
crazy twat
2008-09-01 12:28
>>21
I'm a bit field operator
23
Name:
Ham Operator
2008-09-01 12:29
25
Name:
Anonymous
2008-09-01 19:58
(define (id x) x)
(define (curry f)
(lambda (x)
(lambda (y)
(f x y))))
(define (compose f g)
(lambda (x) (f (g x))))
(define (col acc)
(case-lambda
(() (acc '()))
((x) (col (compose acc ((curry cons) x))))))
(define (o)
(col id))
26
Name:
Anonymous
2008-09-01 20:17
>>25
PROTIP:
id is already defined in R5RS, it's just called
values.
27
Name:
Anonymous
2008-09-01 20:51
28
Name:
Anonymous
2008-09-01 21:39
29
Name:
Anonymous
2008-09-02 5:08
>>26
nice tip actually thanks
30
Name:
Anonymous
2008-09-02 8:26
let y = (\f-> (\x-> f (x (unsafeCoerce x))) (unsafeCoerce (\x -> f (x (unsafeCoerce x))))) :: (a -> a) -> a
(y (\factorial n -> if n == 0 then 1 else n * factorial (n-1))) 3
6
31
Name:
Anonymous
2008-09-02 10:40
token = object()
def f(x=token, y=[]):
return y if x is token else lambda z=token: f(z, y + [x])
def o(): return f
>>> o()(3)(4)(7)()
[3, 4, 7]
Doingitrite? What an amazingly useless function.
32
Name:
Anonymous
2008-09-02 14:45
>>31
Example situation where M-expressions > S-expressions
33
Name:
Anonymous
2008-09-02 15:00
>>32
ONE WORD, FORCED INDENTATION OF THE CODE, TDREAD OVER!!!!!!!!!!!!
34
Name:
Anonymous
2008-09-02 15:28
>>31
I think this thing should modify collector, not return new one.
a=o()(3)(4) # a is now 3,4
a(5) # a is now 3,4,5
35
Name:
Anonymous
2008-09-02 15:31
Actually, wait, OP is written in lisp. Forget what I said.
36
Name:
Anonymous
2008-09-02 16:18
37
Name:
Anonymous
2008-09-02 16:39
>>34
No, that would be easier though.
class o(list):
def __call__(self, x):
self.append(x)
return self
38
Name:
Anonymous
2008-09-02 17:07
Java says: "Fuck you."
OP's dyke face: כּ_כּ