Built Map, Reduce, & Filter

26 views
Skip to first unread message

Liam Goodacre

unread,
Jan 28, 2012, 3:39:47 PM1/28/12
to last...@googlegroups.com
Hey, I just found this and I'm having lots of fun with it!

I've built 'map', 'reduce', and 'filter' functions.

What do you think?

I've added 'add', 'add10', 'mul', 'sub', and 'myfn' for testing they work.

Cheers,
Liam.
Message has been deleted

Liam Goodacre

unread,
Jan 28, 2012, 4:04:03 PM1/28/12
to last...@googlegroups.com
These are my function definitions:

map(Fn) = map(Fn)
map(Fn)([]) = []
map(Fn)([H...T]) = [Fn(H)...map(Fn)(T)]

reduce(Fn) = reduce(Fn)
reduce(Fn)([H...T]) = reduce(Fn)(H)(T)
reduce(Fn)(V)([]) = V
reduce(Fn)(V)([H...T]) = reduce(Fn)(Fn(V)(H))(T)

filter(Fn) = filter(Fn)
filter(Fn)([]) = []
filter(Fn)([H...T]) = if Fn(H) then [H...filter(Fn)(T)] else filter(Fn)(T)
Message has been deleted

Ian Clarke

unread,
Jan 28, 2012, 6:46:09 PM1/28/12
to last...@googlegroups.com
Liam,

I'm very excited that you're having fun :-)

Actually, I didn't anticipate doing function application in the way that you are doing it, although it makes perfect sense.  I guess that it is a good sign when people start doing things in ways I didn't anticipate :-)

On my to-do list is an explicit syntax for applying a pre-defined function, perhaps "apply X to BLAH".

Ultimately I want to add "native" support for a lot of these functional programming constructs, since they will be a lot faster than the user-defined versions.

Thanks for you interest, please keep playing around and let me know if you have any suggestions about how to make things better :-)

Ian.

--
You received this message because you are subscribed to the LastCalc Group
http://groups.google.com/group/lastcalc?hl=en?hl=en



--
Ian Clarke
Reply all
Reply to author
Forward
0 new messages