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

How to get the cudder of a list with foldr?

Name: Anonymous 2007-09-13 18:15 ID:a5wbLjYo

I have managed to write a cudder that requires equality checks... but that's not good enough -- there should be no required functions :/

Name: Anonymous 2007-09-13 18:41 ID:eok4nffL

How have you managed to write a cudder that requires equality checks?

Name: Anonymous 2007-09-13 18:49 ID:a5wbLjYo

>>2
let cudder l = foldr (\ a b -> if ((a:b) == l) then b else (a:b)) [] l

;)

Name: Anonymous 2007-09-13 18:54 ID:Heaven

What's wrong with pattern matching? Or just defining it to equal tail?

Name: Anonymous 2007-09-13 18:58 ID:a5wbLjYo

>>4
Of course, but I'm trying to figure out a way of defining it in terms of foldr.

Name: Anonymous 2007-09-13 19:07 ID:dymVHqkd

cons = λx. λy. λz. z x y
car = λz. λx. λy. x
cudder = λz. λx. λy. y

Name: Anonymous 2007-09-13 20:56 ID:UgYGPgiM

cudder [a,b,c,d..z] = [b,c,d...z]
cudder' [
foldr f i [a,b,c,d..z] =
(f a (f b(f c ... (f z i))... =
(f' a l (f' b l (f' c l (.... (f' z l i))....
.................


cudder l = foldr f [] [l]
            where f a:b _ = b

Name: Anonymous 2007-09-14 7:01 ID:hhRCbase

I gave up and implemented foldr in terms of cudder and car instead ;)
[def]foldr
     [ls]f x list[/ls]
     [if][empty][var]list[/var][/empty]
         [var]x[/var]
         [apply][var]f[/var]
                [car][var]list[/var][/car]
                [foldr][var]f[/var]
                       [var]x[/var]
                       [cdr][var]list[/var][/cdr]
                [/foldr]
         [/apply]
     [/if]
[/def]

Name: Anonymous 2007-09-14 7:14 ID:Heaven

[def]foldr
     [ls]f x list[/ls]
     [if][empty][var]list[/var][/empty]
         [var]x[/var]
         [apply][var]f[/var]
                [car][var]list[/var][/car]
                [foldr][var]f[/var]
                       [var]x[/var]
                       [c
udder][var]list[/var][/cudder]
                [/foldr]
         [/apply]
     [/if]
[/def]

Fixed.

Name: Anonymous 2007-09-14 7:19 ID:Heaven

>>9
Yeah, thanks, I copied the untested version (with a slight manual change to prevent infinite recursion).

Name: Anonymous 2007-09-14 7:21 ID:Heaven

>>8
>>9
I still don't like your BBCode syntax.

Name: Anonymous 2007-09-14 8:40 ID:FLITSqod

I still prefer Scheme BBCode

Name: Anonymous 2007-09-14 8:45 ID:Heaven

>>12
I don't like that, either.

Name: Anonymous 2010-11-14 17:28

Name: Anonymous 2011-02-03 4:02


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