O'Reilly logo

Erlang Programming by Francesco Cesarini, Simon Thompson

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 3. Sequential Erlang

Erlang’s design was heavily influenced by functional and logic programming languages. When dealing with sequential programs, those familiar with languages such as Prolog, ML, or Haskell will recognize the influence they have had on Erlang’s constructs and development techniques. When working in functional programming languages, you replace iterative constructs such as while and for loops with recursive programming techniques.

Recursion is the most useful and powerful of all the techniques in a functional programmer’s armory. It allows a programmer to traverse a data structure via successive calls to the same function, with the patterns of function calls mirroring the structure of the data itself. The resulting programs are more compact and easier to understand and maintain. Functional programs are, importantly, side-effect-free, unless side effects are specifically needed for printing or for access to external storage.

You control recursion using various conditional constructs that enhance the expressive power of pattern matching; in the example of data structure traversal, different patterns correspond to different traversals: bottom-up, top-down, breadth-first, and so forth.

This chapter also introduces other features directly related to sequential programming. The absence of a strong type system and the flexibility and dynamic nature of some of Erlang’s constructs result in runtime errors that, although rare, have to be handled. Through exception-handling ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required