Advanced quickstart
From Reia
Doing operations on individual numbers is boring! Let's try out a list of numbers:
>> [1,2,3] => [1,2,3]
Here we entered a list of numbers. Since we didn't do anything to the list we just get the same list back. There's also a shortcut for entering lists of sequential numbers:
>> 1..10 => [1,2,3,4,5,6,7,8,9,10]
How about we do something with our list? What if we wanted just the even numbers in the list? How could we get them? Well, we could try out a handy dandy language feature which is extremely powerful but might be a bit confusing:
>> [n | n in 1..10, n % 2 == 0] => [2,4,6,8,10]
Holy crap! What just happened here? There's pipes and commas all over the place, yet it magically spat out all the even numbers. Rather than explaining what's going on just yet, I'm going to show you how to get all the even numbers... times five!
>> [n * 5 | n in 1..10, n % 2 == 0] => [10,20,30,40,50]
Hey would you look at that? There it is. So what is this crazy contraption and how does it work?
What we just performed is called a list comprehension. It's a really neat way of working with lists. If you're used to a language which doesn't have them, list comprehensions wrap up an awful lot of operations which may seem hard to do in other languages or require special functions.
There's three bits to pay attention to here: the beginning part before the pipe (n * 5), the middle part before the comma (n in 1..10), and the last part after the comma (n % 2 == 0). We're going to step through these out-of-order so you can follow the flow of what's going on. We're going to begin with the middle part: n in 1..10
This part iterates through a list which serves as the input to our function, in this case the list of numbers from 1 to 10. The second part, n % 2 == 0, acts as a filter on this input list. We will only iterate through values in the 1..10 list which when divided by two equal zero.
The first part acts as a transformation on the return value. In this case, we're multiplying by five.
List comprehensions can work on more than one list at a time. For example, what if we wanted the intersection of two lists?
>> [a | a in [1,2,3,6,7,9], b in [3,4,6,7,10,12], a == b] => [3,6,7]

