O'Reilly logo

Learn You Some Erlang for Great Good! by Fred Hebert

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. Syntax in Functions

Now that we have the ability to store and compile our code, we can begin to write more advanced functions. The functions that we have written so far are extremely simple and a bit underwhelming. Now let’s get to more interesting stuff. In this chapter, we’ll work with functions that behave differently depending on the arguments passed to them and expressions that let us make decisions based on different conditions.

Pattern Matching

The first function we’ll write will greet someone differently according to gender. To achieve this in most procedural languages, you would need to write something similar to the following pseudocode:

function greet(Gender,Name) if Gender == male then print("Hello, Mr. %s!", Name) else if ...

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