Erlang Easter-Eggs
I’m back! Cask removed, arm in recovery :) — Let’s celebrate with some funny bits of Erlang/OTP!
Up to this point, I’ve been sharing a good number of odd and/or confusing bits for and about erlangers out there. I’ll go back to that, probably next week. But, during the same period in which I collected all those battle-stories, I also found several nice bits of code and documentation that are shipped with the Erlang/OTP distribution. They go a long way to show how the language was created and how it evolved. It was programmed with fun! That’s certainly my favourite way to code.
Aliens Among Us
To begin with, let me show you a really nice utility you can find in Erlang/OTP: The erlang tracer. Yeah, erlang_tracer was a really long name back then (see below), so its authors called it et. And, of course, with a module like that who can miss the chance to create this function?
1> et:phone_home(1, from, to, msg, opts).
hopefully_traced
2>
I actually wrote a module using it a while back, and tweeted about it…
Hardcore Name Jokes
Picking a proper name for a function is not always easy, and therefore sometimes you have to document the reasoning behind that name. As Robert Virding did with lists:zf/1:
%%
%% The name zf is a joke!
%%
I had the chance to meet him last year and ask him what was the joke about and he told me it’s a joke about Zermelo and Fraenkel. Let’s see what these gentlemen have to say about that joke…
No Objective-C Devs Allowed Here
If you remember from one of my previous articles, you have many types for lists in Erlang. And in that article I only listed the proper ones (i.e. the ones that represent valid lists). Erlang allows you to use improper lists as well, but the developers found an excellent way to prevent devs from doing that. According to the note in that page:
The following built-in list types also exist, but they are expected to be rarely used. Hence, they have long names:
nonempty_maybe_improper_list() ::
nonempty_maybe_improper_list(any(), any())
nonempty_improper_list(Type1, Type2)
nonempty_maybe_improper_list(Type1, Type2)
True story, man! Who has time to use such long type names, right?
Mysterious Keywords
This one is a classic. In Erlang, both keywords and atoms are written as lowercase words (well… atoms can also be written within single quotes, but let’s forget about that for a bit). Most of the times, that’s not an issue: you know that if is a keyword, case is a keyword, my_function is not, etc.
But there are a few reserved words that are not actually keywords (in the sense that you can’t build expressions with them) but they’re also not atoms. They’re just reserved for the future. A while back (before OTP17) the one that everybody stepped over was query. Since then, you can finally write a function called query, but 2 other magic keywords still remain. Let’s see if you can spot them by comparing the list of reserved words here with the list of valid expressions here ;)
That’s All Folks!
Hope you have enjoyed it. See you next week with more battle stories!