Monthly Archives: April 2011

Side effects for fun and profit

Consider this infinite Fibonacci sequence:       var fib = fcn(ab){a,b:=ab; ab.del(0)+(a+b); a}.fp(L(0,1)); Ask it for a Fibonacci number and you get the first one. Ask again and you get the next one and so on:       > do(15){print(fib(),”,”)} → 0,1,1,2,3,5,8,13,21,34,55,89,144,233,377It never restarts, … Continue reading

Posted in Uncategorized | Leave a comment

Side effects – Don’t leave home without them

For me, one of the coolest things about functional programming languages is using [arglist] pattern matching and recursion to concisely express an algorithm. However, there are other ways to juice the pomegranate. I was staring at the Pure code for … Continue reading

Posted in Uncategorized | Leave a comment

Symmetry Symmetry

I was implementing the [un]zip family of functions (from Haskel, see List functions) and noticed this lovely symmetry: unzip(unzip(a)) –> a One element lists:listUnzip(L(L(1,2,3,4,5,6,7,8,9,0))) –> L(L(1),L(2),L(3),L(4),L(5),L(6),L(7),L(8),L(9),L(0))listUnzip(L(L(1),L(2),L(3),L(4),L(5),L(6),L(7),L(8),L(9),L(0))) –> L(L(1,2,3,4,5,6,7,8,9,0)) Pairs:listUnzip(L( L(1,2), L(3,4), L(5,6), L(7,8), L(9,0))) –> L( L(1,3,5,7,9), L(2,4,6,8,0))listUnzip(L( L(1,3,5,7,9), L(2,4,6,8,0))) … Continue reading

Posted in Uncategorized | Leave a comment

Queen of the Races

The Queens N puzzle has lots of opportunity for parallelism so I thought I’d see what my dual core Windows system could do. Using the code from the previous post, pretty much what I’d expect: Two cores, two threads is … Continue reading

Posted in Uncategorized | Leave a comment

Queen for a day

I was reading the Pure manual (“Pure is a modern-style functional programming language based on term rewriting”) trying to learn the basics of functional programming (which, for some reason, I find very difficult) and saw this nice solution to the … Continue reading

Posted in Uncategorized | Leave a comment