As an aspiring FP connoisseur, I spend my free time thinking about higher order functions, data-ing all the things, and hating on blub. One of my favorite new twitter follows is @jessitron (seriously, just go watch everything you can find, especially Functional Principles for OO Development).
In any case, she recently tweeted:
Procedure: we can replace each call with the body of the routine. Function: we can replace a call with the result. Do you see the power?
— Jessica Kerr (@jessitron) May 29, 2013
Which got me thinking — what if the procedure was pure? Then, you could replace it with nothing! Talk about power.
On my way to work today, I banged out a prototype, and so, I proudly introduce fishbike — pure procedural programming. Admittedly, uses are limited.
You can use the fbc command as either an interpreter or compiler, so, first create a text file called primes.fb (you can use touch). This is a fishbike program to find all primes not divisible by themselves. Since this is a procedure, it can’t return anything. So, if it finds any, it will do some side-effect (update your database, tweet the answer, email your mom, etc). Run it with:
Or compile it with
fbc primes.fb > primes chmod +x primes ./primes