02.23.08
Why can’t I name a lambda?
So I’m working on a quick run at 99 Lisp Problems in Erlang, because I’m a little bored of Project Euler, and I write myself a tiny little testing rig.
run_all_tests() ->
TestList = lists:seq(1, ?LastQuestion),
TestResults = [ { TestNum, apply( ?MODULE, list_to_atom("t" ++ integer_to_list(TestNum)), [] ) } || TestNum <- TestList ],
{ Pass, Fail } = lists:partition( fun({_,TestStatus}) -> TestStatus end, TestResults ),
{ { pass, [ P || {P,_} <- Pass ] },
{ fail, [ F || {F,_} <- Fail ] } }.
And it occurs to me: if I had the ability to slap a name on that fun - say, strip_tuple - then its purpose would be far more obvious, and the whole block of code would suddenly be much easier to read. I realize that the purpose of lambdas is to just write out as functions what couldn’t easily be expressed otherwise and yet stay inline, which has enormous space-savings, readability and debugging benefits. But, there’s nothing in there that actually requires my inability to paste a label on it, is there?
Why can’t I name a lambda?