Previously on BeamBA…

Fede presented the erlings

Run-length encoding of a list

Implement the so-called run-length encoding data compression method. Consecutive duplicates of elements are encoded as terms [N, E] where N is the number of duplicates of the element E.

1> lists_exercises:run_length_encode(



a solution

-module old.
-export [r/1].

r([]) -> [];
r([X|Xs]) -> r(X, r(Xs)).

r(X, [[C,X]|Xs]) -> [[C+1, X]|Xs];
r(X, Xs) -> [[1, X] | Xs].

Brujo's Idea 🧙‍♂️

People were confused

In order to understand recursion, one must first understand recursion.

-Donald Knuth (maybe?)

Plan for Today

  • Recursion over Lists
    • pattern-matching
    • auxiliary functions
  • Recursion over Maps
    • pattern-matching / guards
    • limitations
  • Higher-order functions
    • map
    • fold

Whatever you do,

you should never do


- Chad DePue



Una Charla Recurrente

By Brujo Benavides

Una Charla Recurrente

Una recurrente charla sobre recursión.

  • 362
Loading comments...

More from Brujo Benavides