User loginNavigation 
FilterReduce OptimizationThis must be wellknow amongst functional programming researchers, but I kind of stumbled upon it by accident when studying Joy. Consider the following program to count even numbers: define count_evens = [2 mod 0 neq] filter 0 [inc] reduce So for those new to Joy, every program/function takes it parameter on the stack, and pushes its results onto the stack. Here is a brief explanation of the operators:
The program I showed takes a list on the stack, filters the list for only even numbers, and then counts them using a reduce function. Assuming you are following me so far, this program can be rewritten as follows (caveat: I'm doing this off the top of my head so I could have made a mistake in syntax): def count_evens_1 = 0 [2 mod 0 eq [inc] [] if] reduce What I've done here is eliminate the unneccessary filter operation and "folded" it (pun intended) into the reduce operation. My observation when working with Joy is that this optimization is trivial to automate. So my question to the group is: is this a well known optimization, and if so, is it as easily applied in other functional languages? For those whose curiosity has been piqued, I'm researching the viability of using a Joy dialect as an intermediate language. By cdiggins at 20060502 02:09  LtU Forum  previous forum topic  next forum topic  other blogs  5076 reads

Browse archivesActive forum topics 
Recent comments
1 week 6 days ago
1 week 6 days ago
2 weeks 6 days ago
3 weeks 14 hours ago
3 weeks 18 hours ago
3 weeks 18 hours ago
3 weeks 18 hours ago
3 weeks 6 days ago
4 weeks 41 min ago
4 weeks 4 hours ago