Sign in

Erlang Battleground
Funny & Weird Stories found while coding on the BEAM

y la arquitectura de una aplicación Web

Tecnologías y lenguajes existen muchos, pero ninguno como Erlang para desarrollar un sistema completo. Como Joe Armstrong dijo, “si Java es ‘hazlo una vez y córrelo donde sea’, Erlang es entonces ‘hazlo una vez y córrelo para siempre’ ”.

El Inicio

Hace mucho tiempo, por azares del destino, me topé con el maravilloso mundo de las computadoras. Inicié programando con Cobol, aunque me hubiera gustado empezar desarrollando en el lenguaje C, por su sintaxis y eficiencia.

El camino que me llevaría a encontrarme con Erlang comenzó cuando conocí la tecnología Fault Tolerance in Tandem Computer Systems, tanto en hardware como en software

Or how to use Pattern-Matching for Tests

While acting as a mentor on the FutureLearn MOOC about Erlang I presented an idea that folks like Adolfo Neto loved (he even tweeted about it 🧡). It is, in fact, the way I introduce people to pattern-matching when I’m teaching them Erlang. It’s a way to write tests that let you naturally work your code out from them… Sounds familiar? Yes! It’s Test-Driven Development!

Airplane! (1980)

The Process

I learned TDD when I learned Smalltalk. It was such a life-changing lesson! And Smalltalk was the best environment to learn it since it’s built for it. In Smalltalk, I believe it’s actually harder to…

Particularly for Erlang

Good Will Hunting (1997)

So, I Gusti Ngurah Oka Prinarjaya was reading Joe’s Book and he found one of the most amazing examples of List Comprehensions I’ve ever seen…

perms([]) -> [[]];
perms(List) -> [ [H|T] || H <- List, T <- perms(List--[H]) ].
1> lib_misc:perms("123").

And, of course… he couldn’t understand it. And, as a seasoned Erlang trainer, I got to tell you: He’s not alone… by any means. …

Let’s go back to the origins of this blog with a bit of unexpected code behavior. This time, let’s try removing elements from a list…

Maxwell Smart — because I couldn’t find any proper image for this article

Let’s Subtract!

The beauty of this trick is that the code examples work in both Erlang and Elixir, with barely any changes at all… I’ll do it in Elixir, feel free to try them out in Erlang or efene if you like.

Now, this is a list…

iex(1)> [1, 2, 3]
[1, 2, 3]

And now, we can subtract a few elements from it…

iex(2)> [1, 2, 3] -- [1, 2]

Let’s now subtract that last…

…or Why you should use specs if you use opaque types

Following the steps from Devon and Stavros, I wanted to write this article to highlight a not so obvious dialyzer lesson about opaque types and specs…

Help me help you — Jerry Maguire


For the impatient ones…

If you define an opaque type, you have to add specs to all the exported functions that use it (i.e. your module’s API).

Opaque Types

Since this article is about opaque types, I will do a quick intro first…

In Elixir, there are 3 ways to specify a user-defined type:

@type t1 :: boolean | atom # this type is exported
@typep t2 :: String.t …

…for Erlang & Elixir

A few months ago, Fred gave me a copy of his latest book (Property-Based Testing with PropEr, Erlang, and Elixir) so I could review it. So, here I am, returning the favor. But I’ll also use this chance to express some of my feelings and opinions about Property-Based Testing in general, since reading the book elicited quite a few of them. This will not be one of the usual articles on this blog, but I hope you’ll enjoy it anyway.

The Book

In a nutshell, this book is a very extensive and detailed manual/hands-on-tutorial with which you’ll first learn the general concepts…

I remember around 2008 when I was submerged in the Java world I had a change to try awesome caching libraries and frameworks, such as: Hazelcast, EHCache, Spring Caching, etc. At that time, between researching and learning about distributed caching, one of the most interesting things I came across with, was a presentation from Cameron Purdy titled “Distributed Caching Essential Lessons”, it got my attention immediately, since it was one of the first materials talking about distributed caching topologies, taxonomies, pros/cons, etc. So I began to put all this in practice and there were tons of options to make it…

A while back this question popped up in one of the many places where the Erlang community gathers, I think it was IRC:

How many functions do you have in your Erlang node?

As an answer, Craig posted this beauty:

1> length([{M,F,A} || {M,_} <- code:all_loaded(), {exports,Fs} <- M:module_info(), {F,A} <- Fs]).
2> length([{M,F,A} || {M,_} <- code:all_loaded(), {exports,Fs} <- M:module_info(), {F,A} <- Fs]).
3> {ok,2}.
4> length([{M,F,A} || {M,_} <- code:all_loaded(), {exports,Fs} <- M:module_info(), {F,A} <- Fs]).
Original from KissPNG

What’s going on here?

As usual, it’s better if you try understanding this by yourself. If you are up for the challenge…

The year was 2008. I had a steady job as a .NET developer. Then I read an ad from a company that was looking for developers with knowledge of Erlang… or functional programming in general and I applied.

I had learned a bit of Haskell in college and I loved it but I was not even remotely close to having experience in functional programming. Nevertheless, something told me that it was the right path.

Totally unprepared but ready to just improvise and see, I arrived at Novamens for an interview. I met Juanjo there but, more importantly, I met Erlang!

Or The Semantic of Function Arguments

Reading ErlangExplained I noticed something that made me question my understanding of The Hitchhiker’s Guide to the Galaxy and also made me think about the way we choose our function clauses.

Original — by Stmed.NET

What I wondered was how to interpret the phrase “the Ultimate Question of Life, The Universe, and Everything”. In other words: would the Ultimate Question be a question about three combined but independent entities (i.e. Life, The Universe and Everything as a whole). Maybe it’s a question about either Life, The Universe or Everything. Or actually, as I understood when I read the book many years ago, it was…

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store