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

Pages: 1-

give me some scheme

Name: Anonymous 2012-08-02 1:23

help me out /prog/, give me some programs to write in scheme, practice

Name: Anonymous 2012-08-02 1:25

implement a tail-recursive uniq

Name: Anonymous 2012-08-02 1:50

Implement loeb.

Name: Anonymous 2012-08-02 2:07

>>2
alright

(define repeat?
  (lambda (elem lst)
    (cond ((empty? lst) #f)
          ((= elem (first lst)) #t)
          (else (repeat? elem (rest lst))))))

(define uniq-iter
  (lambda (ret lst)
    (if (empty? lst)
        ret
        (uniq-iter (if (repeat? (first lst) ret)
                       ret
                       (cons (first lst) ret))
                   (rest lst)))))

(define uniq
  (lambda (lst)
    (reverse(uniq-iter (list (first lst)) lst))))

Name: Anonymous 2012-08-02 2:12

(reverse(uniq-iter (list (first lst)) lst))))

edit: (reverse(uniq-iter (list) lst))))

Name: Anonymous 2012-08-02 2:20

>>3
what is loeb?

Name: Anonymous 2012-08-02 3:51

>>6
LOEB LOEB LOEB

Name: Anonymous 2012-08-02 6:50

>>6
loeb = fix (fmap . flip id =<<)

Name: Anonymous 2012-08-02 12:56

>>6
It's what Haskell programmers wish their mothers did for them.

Name: Anonymous 2012-08-02 14:58

>>1
Project Euler. Anything math based, really.

Name: Anonymous 2012-08-02 16:34

GIVE ME SOME DUBZ

Name: Anonymous 2012-08-02 18:24

loeb (flip flip)

Name: Anonymous 2012-08-03 2:08

>>8
How does flip id typecheck? It seems simple enough looking at the definition of flip, but I don't see how the types match up.

Name: Anonymous 2012-08-03 5:35

loeb, loeb, loeb, loeb, loeb, loeb, loeb, loeb, loeb.
There's nothing you can do that can't be done.
Nothing you can sing that can't be sung.
Nothing you can say but you can learn how to play the game
It's easy.
There's nothing you can make that can't be made.
No one you can save that can't be saved.
Nothing you can do but you can learn how to be you
in time - It's easy.

All you need is loeb, all you need is loeb,
All you need is loeb, loeb, loeb is all you need.
loeb, loeb, loeb, loeb, loeb, loeb, loeb, loeb, loeb.
All you need is loeb, all you need is loeb,
All you need is loeb, loeb, loeb is all you need.
There's nothing you can know that isn't known.
Nothing you can see that isn't shown.
Nowhere you can be that isn't where you're meant to be.
It's easy.
All you need is loeb, all you need is loeb,
All you need is loeb, loeb, loeb is all you need.
All you need is loeb (all together now)
All you need is loeb (everybody)
All you need is loeb, loeb, loeb is all you need.

Name: Anonymous 2012-08-03 6:46

>>13

flip :: (a -> b -> c) -> b -> a -> c
id :: a -> a
id@a->b :: (a -> b) -> a -> b
flip id@a->b :: a -> (a -> b) -> b

(\f a b -> f b a) id
(\a b -> id b a)
(\a b -> b a) :: a -> (a -> b) -> b

Name: Anonymous 2012-08-03 6:54

>>13
it's the same as flip ($) or \ x f -> f x.

Name: Anonymous 2012-08-03 10:20

>>15
Yeah, I figured it out after I posted. I just didn't realize that it would treat id as (a -> b) -> a -> b. Thanks.

>>16
Not really, because id (usually) only takes one argument. That's what was confusing me.

Name: Anonymous 2012-08-03 11:12

>>17
In Haskell, functions that take multiple arguments are function-returning functions (they are ``curried''). There's a reason for all the arrows in the types. That's why you can treat id as (a -> b) -> a -> b.

Name: Anonymous 2012-08-03 13:30

>>18
I know that, and I don't see how currying is related unless you're talking about why (a -> b) -> a -> b is the same as (a -> b) -> (a -> b), which I understand. I didn't know that it would substitute a -> b for a in the type signature of id.

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