Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint
Share this Page URL
Help

Chapter 3. Sequential Erlang > Conditional Evaluations

3.1. Conditional Evaluations

Erlang has three forms of conditional evaluation that are (at least partially) interchangeable. The first form you encountered in Chapter 2: the choice of a function clause to evaluate through pattern matching over the arguments to the function. The second is the case statement, which works in a similar way to function clause selection. The third form is the if construct, which you can view as a simplified form of the case construct. Let’s start with the case construct.

3.1.1. The case Construct

The case construct relies on pattern matching to choose what code to evaluate, in a strikingly similar manner to the selection of function clauses by pattern matching. Instead of matching actual parameters against patterns for the formal parameters to the function, case evaluates an expression and matches the result against a list of pattern-matching clauses, separated by semicolons.


  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint