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

Pages: 1-

/PROG/SICP CHALLENGE

Name: Anonymous 2008-09-01 7:21

IMPLEMENT THE COLLECTOR!!!

(((((o) 'a) 'b) 'c)) ; => (a b c)

Name: Anonymous 2008-09-01 7:22

AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAALISPAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA

Name: Anonymous 2008-09-01 8:10

Do it in scheme /prog/

Name: Anonymous 2008-09-01 8:10

I desinged this puzzle for /prog/ only, why aren't you trying it?

Name: Anonymous 2008-09-01 8:27

I solved this problem in my head. Just use closures.

Name: Anonymous 2008-09-01 8:35

>>5
write your solution out and yes it uses closures fuckign obviosuly

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

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.

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:\>

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

Name: Anonymous 2008-09-01 9:50

>>7
tip use recursion

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

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

Name: Anonymous 2008-09-01 10:39

>>12
I cried when I saw that, such beautiful code............

Name: Anonymous 2008-09-01 10:45

>>12
I cried when I saw that, such useless code............

Name: Anonymous 2008-09-01 10:46

>15
I cried when I saw that, such YOU JUST LOST THE GAME code............

Name: Anonymous 2008-09-01 10:58

>>13
YHBT

>>12
This solution is inefficient.

Name: Anonymous 2008-09-01 11:04

Here's my solution:

def o(*args)
  args
end

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

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.

Name: Anonymous 2008-09-01 12:28

>>20
I'm a crazy twat, and that's that!

Name: crazy twat 2008-09-01 12:28

>>21
I'm a bit field operator

Name: Ham Operator 2008-09-01 12:29

>>22
Me too.

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

Name: Anonymous 2008-09-01 20:17

>>25
PROTIP: id is already defined in R5RS, it's just called values.

Name: Anonymous 2008-09-01 20:51

>>26
But is it in R6RS

Name: Anonymous 2008-09-01 21:39

>>27
But is it in R7RS?

Name: Anonymous 2008-09-02 5:08

>>26
nice tip actually thanks

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

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.

Name: Anonymous 2008-09-02 14:45

>>31
Example situation where M-expressions > S-expressions

Name: Anonymous 2008-09-02 15:00

>>32
ONE WORD, FORCED INDENTATION OF THE CODE, TDREAD OVER!!!!!!!!!!!!

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

Name: Anonymous 2008-09-02 15:31

Actually, wait, OP is written in lisp. Forget what I said.

Name: Anonymous 2008-09-02 16:18

>>35
gurk u

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

Name: Anonymous 2008-09-02 17:07

Java says: "Fuck you."
OP's dyke face: כּ_כּ

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