wintermeyer / elixir-phoenix-ash Goto Github PK
View Code? Open in Web Editor NEWAn Elixir, Phoenix and Ash Beginner's Guide
Home Page: https://elixir-phoenix-ash.com
License: Other
An Elixir, Phoenix and Ash Beginner's Guide
Home Page: https://elixir-phoenix-ash.com
License: Other
This issue is intended to help us decide on which format we should use for the code examples.
Currently, we use the following format:
iex(1)> defmodule Area do
...(1)> def circle(radius) do
...(1)> pi() * radius * radius
...(1)> end
...(1)>
...(1)> defp pi do
...(1)> 3.14
...(1)> end
...(1)> end
{:module, Area, ...
iex(2)> Area.circle(10)
314.0
iex(3)> Area.pi <3>
** (UndefinedFunctionError) function Area.pi/0 is undefined or private
Area.pi()
The Elixir getting-started guide (example taken from the Modules and Functions page:
iex> defmodule Math do
...> def sum(a, b) do
...> a + b
...> end
...> end
iex> Math.sum(1, 2)
3
Compared with our current format, the getting-started guide does not include the command numbers, and it does not show the module return value (it displays a blank line instead).
If we find any examples of other formats, we can add them in the comments below.
Hello. Thank you for writing such a great guide.
I am currently working my way through the Elixir guide and I am not getting the same results when I run the example in String Interpolation locally.
In the first cell in the following image, I expected to get something like "The list is [72, 101, 108, 108, 111]."
, but I am getting something like "The list is Hello"
.
The second Cell expects to get a result like "The tuple is {72, 101, 108, 108, 108, 111}."
when executed, but gets a Protocol.UndefinedError
error.
I suspected it was an issue with the Livebook environment, so I tried running it through iex, but I'm getting the same results as when I ran it in Livebook.
The link to the twitter profile of Ulisses Almeida is broken. It contains an extra ).
I think we can move the Modules and Functions
section to an earlier and more prominent position (before the Anonymous Functions
section) in the elixir-introduction
. This is because most of the functions that developers will read and write are regular functions (within modules) and it makes it easier to look at anonymous functions (and the capture operator) in the way they are most often used (as arguments in higher-order functions) if we look at them after covering regular functions.
My proposal is to move the Modules and Functions
section to after the Strings
section and to move the Anonymous Functions
and Capture Operator
sections to subsections before the Hierarchical Modules
section. Also, I want to add more examples using higher-order functions to the Anonymous Functions
and Capture Operator
sections.
Hello.
While looking at Type Conversions in Elixir
in the Elixir guide, I ran the following example code locally and did not get the same result as the example.
iex> to_string([1, 2, 3])
"[1, 2, 3]"
iex> to_string({:ok, "Hello"})
"{:ok, \"Hello\"}"
In addition to this problem, Now, how can i string interpolate variables of types like List and Tuple?
Hello.
While looking at Pattern Matching With Various Data Structures
in Elixir in the Elixir guide, I ran the following example code locally and did not get the same result as the example.
defmodule User do
def greet(name, opts \\ []) do
greet(name, opts)
end
defp greet(name, [role: "admin"]) do
"Welcome, #{name}. You have admin privileges."
end
defp greet(name, [role: "moderator"]) do
"Welcome, #{name}. You can moderate content."
end
defp greet(name, _) do
"Welcome, #{name}."
end
end
IO.puts User.greet("Alice") # Outputs: "Welcome, Alice."
IO.puts User.greet("Bob", role: "admin") # Outputs: "Welcome, Bob. You have admin privileges."
IO.puts User.greet("Carol", role: "moderator") # Outputs: "Welcome, Carol. You can moderate content."
If the content of the example code is not available in the latest version of Elixir, what is the latest alternative approach?
In the 'link class' subsection in the phoenix-basics file, there is the following example:
<%= link "Ping!", to: Routes.page_path(@conn, :ping, class: "btn") %>
Has this been tested? I think class: "btn"
should be added to the link function, not to the Routes.page_path
function, so I think it should be:
<%= link "Ping!", to: Routes.page_path(@conn, :ping), class: "btn" %>
We will need to include some information about keyword lists. They are often used to set options in a function, and anyone creating a Phoenix app will see them very soon because the render
function uses keyword lists to populate the assigns values.
We could add a short Keyword Lists
section just before, or just after, the Maps
section.
We need to provide information about queries for single entries that use attributes instead of the primary key.
We also need to add some introductory information about associations.
In the ecto-basics
file, there is the following line:
Note: One can argue that get_author!(id) is not easier/better than Repo.get!(Author, id).
This touches upon one of the reasons for organizing code into context modules - that is, to provide an interface between the controller and the data layer. The trend now, since Phoenix 1.3, is to query / manipulate data in the context modules, rather than doing so directly in the controller code.
I propose that we edit this line to point out that, although there does not seem to be much point in creating the get_author/1
function (as we could just call Repo.get/2
from the controller), there is a clear design rationale for creating this new function and not calling any of the Repo
functions directly in the controllers.
It is important that we keep this mention of context modules brief and try not to overwhelm the reader.
Useful links:
Parts that I think we can remove:
{:module ...}
return value when defining a module
Parts that we can simplify:
DateTime
, and then add links to the docs for the other date / time types~
introduces a sigil and then provide brief examples of using the regex and string sigilsNeben der der Erklärung von "import" und "alias", solltest du auch "use" erklären. Die Unterschiede sind auf den ersten Blick nicht klar, wenn man von anderen Sprachen kommt. Aber sie sind durchaus relevant zu wissen.
Hello, thank you for providing the learning content. Currently in my computer and phone, \00a7
becomes \<?>a7
. My computer is a Window 11 Laptop and my phone is an Android phone.
Then I use this e0d0ca42a72a7698beb7e71b867a0369a9ab56fb
commit and npx antora antora-playbook.yml
and VS Code's Five Server(Live Server) extension, \00a7
can display normally.
I do not get the match error described. Perhaps the behavior has changed? I have started with elixir recently so I'm not familiar with much history, but I was very surprised to see the example of the match error in this section and was not able to reproduce it.
Interactive Elixir (1.15.6) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)> x = 5
5
iex(2)> x = 7
7
This proposal is to add a brief outline of certain principles / benefits of function programming near the beginning of the elixir-introduction
file.
This might provide users with pointers to keep in mind while they read the rest of the book - especially if they are used to languages that belong to other paradigms.
We should mention the following:
The already existing sections on functions as first-class citizens and immutability could be simplified and moved to this introduction.
I propose that we remove the Maps Functions and Tuples Functions sections in the elixir-introduction
and add links to the documentation for these functions in the Maps / Tuples sections. This is so that we save space and help the reader focus on the key points.
We will also need to add links to documentation for:
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.