unless
unless
is not explained.
unless
unless
is not explained.
# This fails at compile time (missing required field) %User{name: "Alice"} # Error: missing required key :email
It says %User{name: "Alice"}
fails at compile time with a missing required field error, but when I tested it, it works fine and just sets the other fields to nil
. There doesn't seem to be any required field validation happening here.
↑ fields with defaults
This is pointing to the required fields instead of the fields with defaults
Enum.reduce(numbers, fn x, acc -> x + acc end)
The Python example uses reduce with a default value (0), but the Elixir translation uses Enum.reduce/2 without a default value. For a true equivalent, it should use Enum.reduce(numbers, 0, fn acc, x -> acc + x end) to match the Python behavior.
, do
This syntax is not explained. Why is the comma(,) needed before the do
, and why don't we write end
, why the colon(:) after the do
.
Since your goal is to evaluate Phoenix vs Rails
This seems out of place based on the 'Rules of the Game' - we're supposed to be Python devs who don't know Ruby. The Phoenix vs Rails comparison doesn't align with the established context, and it doesn't connect to the previous conversation either.
.title()
The Python example uses .title()
, but the Elixir version uses String.capitalize()
- these don't produce the same output. Should probably use .capitalize()
in Python for a true equivalent. since Elixir doesn't have a title()
function.
The outputs will also be different because of this.
def clean_name(raw_name) do raw_name |> String.trim() |> String.capitalize() end name = " alice johnson " result = clean_name(name) IO.puts(result) # "Alice Johnson"
The def
syntax keeps appearing in examples, but I can't replicate it in the iex terminal. It seems like this only works in .ex
files, but there's no explanation on how to create and run those files.
I can see you got 7 words instead of the expected 6, but let me check your logic… Looking at your final filtered list: ["Hello", "world", "Elixir", "love", "programming", "Code", "every"] You used >= 4 (4 or more characters), since exercise asked for filtering out words “shorter than 4 characters”, which means keeping words with 4 or more characters - so your logic is actually correct!
In the exercise above, it says 'Expected: 7', but here it says 'you got 7 words instead of the expected 6'. This part seems unnecessary.
iex(67)> sentences = Enum.map(sentences, fn x -> String.split(x) end) [ ["Hello", "world"], ["Elixir", "is", "fun"], ["I", "love", "programming"], ["Code", "every", "day"] ] iex(73)> words = Enum.filter(words, fn x -> String.length(x) >= 4 end) ["Hello", "world", "Elixir", "love", "programming", "Code", "every"] iex(74)> length(words) 7
This example missed out List.flatten
part
Your pipeline was flawless: ✅ FILTER: x > 0 kept [1, 3, 5, 7, 8, 10]
2.40 Summary: The 3 Core Functional Patterns
All the subheadings are in an incorrect format.
<>
This syntax gets used here but isn't explained until chapter 2.37. Feels a bit out of place - maybe add a quick note or move the explanation earlier?
2.24 Examples: Simple Case (Single Parameter, No Extra Processing)
From this section onwards, Elixir examples come first instead of Python. This breaks the established pattern from earlier sections.
↑
It could be better if the arrow were aligned directly under the dot instead of being offset.
# This needs parentheses for the inner function call Enum.map(words, fn x -> String.length(x) end)
This example says parentheses are needed for the inner function call, but Example 1 just said they're not needed for simple cases like that. These examples look pretty similar to me - I'm confused about when I should actually use parentheses.
# With parentheses (also valid) length([1, 2, 3]) # Also works IO.puts("hello") # Also works String.upcase("hello") # Also works
The parentheses examples could be shown first, since that's what Python devs are already familiar with, then introduce the optional syntax.
# def is also used to create named functions def add(x, y) do x + y end
As per the above explanation, Everything returns a value in Elixir
, isn't the def
a statement just as in Python in the above example
That is beautiful - almost artistic. So, let us see why parantheses are optional. I am wondering how that is even possible.
This question seems out of place, as all the above elixir examples have parentheses.
case
Didn't explain what it was doing, as it seems like a new concept.
AI Elixir Mentor
Heading got duplicated
Benefits
Needs proper formatting
This works in Elixir (but fails in Python):
I got a CompileError when using the ^
.
```elixir
iex(7)> x = 6
6
iex(8)> 6 = x
6
iex(9)> 6 = 5 + 1
6
iex(10)> a = 5
5
iex(11)> ^x = ^a + 1
error: misplaced operator ^a
The pin operator ^ is supported only inside matches or inside custom macros. Make sure you are inside a match or all necessary macros have been required └─ iex:11
** (CompileError) cannot compile code (errors have been logged) ```
a + 1 = x
I tried the example, but a + 1 = x
throws a compile error. The book says this should work 'both directions like algebra', but Elixir won't let me put an expression on the left side of the match. Am I missing something, or is this example incorrect?
Ok I understand that - but we started this discussion on pattern matching saying this is a match operator and not an assignment operator. So, how does assignment work in Elixir?
This is exactly what I was looking for when pattern matching was first mentioned! It would be great to have this detailed explanation right when the concept gets introduced, instead of after the inspect
topic.
edit: Just realized that it got explained in the Printing Values section
iex> a, b, c = numbers
In the previous conversation, we have initialized the [1, 2, 3]
in the list
variable, but now we are using the numbers
variable, which we have initialized in IPython.
It's confusing to use different variable names for the same operations.
Let me summarize - there are 2 ways to access the documentation 1. All the documentation of all packages in Elixir including the core packages are available in hexdocs.pm. 2. IEx’s h helper shows offline documentation for modules and functions that are part of Elixir itself or other libraries installed in your current project
The bullet points need proper line breaks.
h
It should be formatted as h
.
make you have installed iex
It should be "make sure you have installed iex" - the word "sure" is missing.