Cover by Fred Hebert

Safari, the world’s most comprehensive technology and business learning platform.

Find the exact information you need to solve a problem on the fly, or go deeper to master the technologies and skills you need to succeed

Start Free Trial

No credit card required

O'Reilly logo

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 ...

Find the exact information you need to solve a problem on the fly, or go deeper to master the technologies and skills you need to succeed

Start Free Trial

No credit card required