Learn Functional Programming with Elixir (Pragprog)

The book even link to this thread:

Recursion! :smile:

6 Likes

Nice one @georgeguimaraes :023:

The URL has been updated since mind - though it will still get to this thread. The new URL is:

https://elixirforum.com/t/learn-functional-programming-with-elixir-pragprog/5114

Though if you wanted to, you could use:

https://elixirforum.com/t/learn-functional-programming-with-elixir/5114

:slight_smile:

Blog post outlining the story behind this book :slight_smile:

I’m sure it will be great @ulissesalmeida :023:

1 Like

@AstonJ Thanks!

I need to update the book with thew new URL :laughing:

1 Like

First chapter of this book is currently available as a free download :023:

1 Like

I am not sure how to post a question but I started going over the book and I like it a lot. I got stuck with the Enum.each exercise.

I do: apply_tax = fn price -> " Price: #{price} - tax: #{price*0.12}" and when I check it alone it works fine
I then do:Enum.each([12.5, 30.99, 250.49, 18.8], apply_tax ) and it just print :ok:
I also tried: Enum.each([12.5, 30.99, 250.49, 18.8], fn(n) -> apply_tax.(n) end ) with same results please help. Also how do I post regula questions on the forum? I could not find it like onn other forums?

Thank you Amos Madanes

  1. apply_tax returns a string
  2. You are using Enum.each/2 - this suggests you are going through the list for a side effect (rather than generating a new result).

You probably want to show the string on the screen in iex - the piece you are missing is IO.puts/2:

Interactive Elixir (1.5.2) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)> apply_tax = fn price -> "Price: #{price} tax: #{price * 0.12}" end
#Function<6.99386804/1 in :erl_eval.expr/5>
iex(2)> Enum.each([12.5, 30.99, 250.49, 18.8], fn(n) -> IO.puts(apply_tax.(n)) end)
Price: 12.5 tax: 1.5
Price: 30.99 tax: 3.7188
Price: 250.49 tax: 30.0588
Price: 18.8 tax: 2.256
:ok
iex(3)> Enum.each([12.5, 30.99, 250.49, 18.8], fn(n) -> n |> apply_tax.() |> IO.puts() end)
Price: 12.5 tax: 1.5
Price: 30.99 tax: 3.7188
Price: 250.49 tax: 30.0588
Price: 18.8 tax: 2.256
:ok
iex(4)> 

FYI:
The book’s forum is actually
https://forums.pragprog.com/forums/440

Though I suspect that you’ll get a much faster response here - as long as you are OK with people answering who haven’t actually read the book.

1 Like

Thank you @peerreynders.

@amadanes You can also download the source code files of the book in https://pragprog.com/titles/cdc-elixir/source_code

There are several folders for each book’s topic. Some of them has answers folder that you can find my suggested answers for the book’s exercises.

The printed version announcement. If you already have bought e-book version, you might have received a coupon discount in your e-mail if you want to purchase the printed version.

https://media.pragprog.com/newsletters/2018-02-28.html

3 Likes

Whoo hoo I finished it! Here’s…

My Review

I really enjoyed this book! I think it’s going to prove incredibly useful for those of us who are coming to Elixir as our first functional programming language. But before I go into the details, I want to say that this book reminded me that you should never judge a book by its cover!!

Why? Well when I first heard about this book I immediately thought it was going to be Elixir’s version of the Ruby book by Chris Pine, called Learn to Program (an amazing book btw!). But it’s not - this book goes much further down the rabbit hole! In fact, I reckon it could even drop ‘learn’ from the title and simply be called Functional Programming with Elixir. Having ‘learn’ in the title makes it sound as though it’s for newcomers to programming in general - but maybe that’s just because I’m aware of the aforementioned Ruby book which also happens to be published by PragProg.

For the same reason, I’m also glad I read this book after Programming Elixir and Elixir in Action. Because the focus of those books are the fundamentals of the Elixir language and OTP, and that’s why they cover them in great detail. The focus of this book however, is functional programming …with Elixir. So the aim of this book isn’t to teach you the ins and outs of Elixir and OTP, it’s to teach you the fundamentals of functional programming - and just so happens to be using Elixir, but, while also showcasing Elixir’s advantages in the area and how it approaches and tackles common problems using functional programming.

So this book is for you if Elixir is your first functional programming language or maybe even if it’s not, and you want to see how Elixir is functionally minded. It will go into detail about things like recursion - (which btw, is a deeper topic than I first thought!) for instance, just like in Elixir in Action where you build a genserver and supervisor from scratch using bare processes, here you build a Map function using recursion. I LOVE it when books do this, because it helps give you a much better understanding of what is going on and helps make things ‘click’.

If you still don’t think you need this book - here are some questions for you: Do you know functional concepts and terms such as Divide and Conquer, Decrease and Conquer, Unbounded Recursion, Pure Functions, Impure Functions, Higher Order Functions? Do you know what Map and Reduce are really doing under the hood? Do you know when to use Comprehensions or Monads or Try and Rescue/Throw or With? Or what about when to use Protocols or Module Behaviours? If not, this book will teach you, and much more!

I’m glad I read this book - and if you read it, I think you will be too!

Well done @ulissesalmeida, this book definitely fills a void and I think will prove very useful to a lot of people :023:

19 Likes

Since the book’s forum is down, posting a question here.

I’m on the Dungeon Crawl app part, and I’m getting stuck near the beginning when I try to run iex -S mix. Page 111 of 160 in my version of the book, Creating the Character with Structs.

I receive this error in Visual Studio Code:

"PS D:\code\Functional_Programming_with_Elixir_Book\dungeon_crawl> iex -S MixInvoke-Expression : A parameter cannot be found that matches parameter name ‘S’.
At line:1 char:5

  • iex -S Mix
  • ~~
    
    • CategoryInfo : InvalidArgument: (:slight_smile: [Invoke-Expression], ParameterBindingException
    • FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.PowerShell.Commands.InvokeExpressionCommand"

I’ve tried googling and that hasn’t yielded anything I’ve found helpful so far. Any help would be appreciated.

Please do not use Powershell, it has a built-in function iex, which shadows the iex of elixir.

1 Like

What would you suggest in lieu of Powershell? I’m pretty new to all of this.

Good old cmd.exe. Or Linux :wink:

2 Likes

Okay, I ran cmd.exe in the Powershell terminal and that switched the terminal to cmd.

Trying ‘iex -S mix’ worked as intended after that. Thanks!

1 Like

You can start it directly, just do win+R and then type cmd.exe and Enter.

2 Likes

Just finished this book. It was a fantastic introduction to functional programming and the elixir syntax for an absolute beginner. If you have prior experience programming but not with functional programming then I’d still highly recommend this as a starting point.

7 Likes

Is the Discount still on? I get a message saying it is expired when I enter it at checkout

2 Likes

Hi Tom, we have a new coupon coming soon - can you hold off a few weeks? :smiley:

2 Likes

Yeah no problem! Thanks for the quick reply. I’ll keep my eye out for when it comes out :slight_smile:

2 Likes