Chapter 2. Intro to Elixir

 

This chapter covers

  • The basics of the Elixir programming language
  • Creating a module
  • Using built-in tools to help you work smarter

Now that you’ve learned a bit about the benefits Phoenix can bring to your web application development, you’ll need to know Elixir. Phoenix is a web framework that’s built on top of the Elixir language (which is built on the Erlang VM, known as BEAM). So what if you don’t know Elixir?

This chapter will get you up to speed on Elixir. If you already know Elixir, you can probably skip this chapter entirely. If you don’t know Elixir or need a refresher, this chapter will cover just enough Elixir to get you going. Some concepts won’t be covered in this chapter—I’ll teach you about them later in the book when you need to know them. I’ll also point you to more resources at the end of the chapter, in case you’d like to dive deeper into the language and all its features.

2.1. The basics

Before we begin writing Elixir, I’ll show you a quick example of what a module might look like (a module can be thought of as a collection of functions). Have you heard of the “fizz buzz” programming exercise? This is the basic idea:

  1. Take any series of numbers, one at a time.
  2. If the number is divisible by 3, print “fizz.”
  3. If the number is divisible by 5, print “buzz.”
  4. If the number is divisible by 3 and 5, print “fizzbuzz.”
  5. Otherwise, print the number.

2.2. Other idiomatic Elixir language features

Summary

sitemap