elixir-lang / elixir-lang.github.com Goto Github PK
View Code? Open in Web Editor NEWWebsite for Elixir
Home Page: elixir-lang.org
Website for Elixir
Home Page: elixir-lang.org
I'm on Ubuntu 14.10 and just tried to follow the install instructions with no joy. It seems elixir isn't a package for utopic.
For those unfamiliar with functional languages, recursion can be a heavy topic that's very hard to grasp the first time around. In "getting_started/9.markdown", after an explanation of not only recursion but also tail call optimization, the following is thrown in:
iex> Enum.reduce([1, 2, 3], 0, fn(x, acc) -> x + acc end)
I think even without the preview of reduce this chapter is very intimidating for newcomers. We should consider removing the preview of Enum (leaving perhaps the sentence saying that recursion isn't often used for list manipulation). I would also perhaps consider doing an even simpler recursion example before the sum
example. Perhaps the following (extremely contrived) example would be helpful:
defmodule Recursion do
def print_multiple_times(msg, n) when n <= 1 do
IO.puts msg
end
def print_multiple_times(msg, n) do
IO.puts msg
print_multiple_times(msg, n - 1)
end
end
Recursion.print_multiple_times("Hello!", 3)
# "Hello!"
# "Hello!"
# "Hello!"
So, I spent some time trying to figure out how to solve this, but my Elixir-fu isn't yet strong enough.
For a portion of the walkthrough in OTP chapter 6, we're told that the tests should pass while using this setup block:
setup do
{:ok, sup} = KV.Bucket.Supervisor.start_link
{:ok, manager} = GenEvent.start_link
{:ok, registry} = KV.Registry.start_link(:registry_table, manager, sup)
GenEvent.add_handler(manager, Forwarder, self(), link: true)
{:ok, registry: registry, ets: :registry_table}
end
The problem is that the :registry_table name is taken after the first call to the registry's init function, which gives an ArgumentError on subsequent calls. I attempted to solve this with a teardown block but was having no luck.
As it turns out, the solution we move on toward further in the chapter means this is partially irrelevant, but I still lost a couple of hours chasing it down, thinking I had typed something wrong or done something goofy.
Could we make the links more distinguishable from normal text, probably underlined?
I find the Getting Started helpful in general, but I missed info on how to compile my first program.
That is IMO crucial information to "getting started" and settle the technical aspects around getting your first programs to run, so that one can thereafter spend time on studying and trying out the language itself.
I asked about it on stackoverflow, and got a very comprehensive and informative answer. It thus struck me that this information should optimally be a part of the getting started guide, e.g. as section no. 1.7 "Building your first program" or similar.
The author has already given his implicit agreement, in the comments below.
..and related neat tricks, like the following ones:
Enum.find [{1,:a},2,3], match?({_, :a}, &1)
# => {1,:a}
Enum.find [1,2,3], &1 == 1
# => 1
# etc.
gregors$ brew tap homebrew/versions
Cloning into '/usr/local/Library/Taps/homebrew-versions'...
remote: Counting objects: 1225, done.
remote: Compressing objects: 100% (750/750), done.
remote: Total 1225 (delta 667), reused 993 (delta 475)
Receiving objects: 100% (1225/1225), 321.16 KiB | 524.00 KiB/s, done.
Resolving deltas: 100% (667/667), done.
Tapped 113 formula
Gregorys-MacBook-Air:coursera Error: No available formula for erlang-r16
looks like erlang-r16 recipe was removed
This paragraph:
Since the registry process needs to monitor besides keeping the dictionary state, agents are not a good fit for modelling the registry. Instead, we will use a GenServer which is the go-to abstraction for building generic servers in both Elixir and OTP.
That first sentence before the comma is missing something or is unclear, but I'm not sure what. Maybe something like this:
Since the registry process needs to both monitor and keep the dictionary state, ...
Even in that sentence, the word "both" might be considered redundant, but I think it helps as you read along. Am I interpreting the meaning correctly?
Elixir 0.14.1
Doing the tutorial and reached the section on tuples:
http://elixir-lang.org/getting_started/2.html#toc_7
Tutorial says to use set_elem
set_elem reports : ** (RuntimeError) undefined function: set_elem/3
Changelog says it has been deprecated, please update tutorial.
Thanks.
This block of code mentions to update a test, but it includes the Forwarder
module in the code block. I'm assuming that doesn't belong there.
defmodule Forwarder do
use GenEvent
def handle_event(event, parent) do
send parent, event
{:ok, parent}
end
end
setup do
{:ok, manager} = GenEvent.start_link
{:ok, registry} = KV.Registry.start_link(manager)
GenEvent.add_mon_handler(manager, Forwarder, self())
{:ok, registry: registry}
end
test "sends events on create and crash", %{registry: registry} do
KV.Registry.create(registry, "shopping")
{:ok, bucket} = KV.Registry.lookup(registry, "shopping")
assert_receive {:create, "shopping", ^bucket}
Agent.stop(bucket)
assert_receive {:exit, "shopping", ^bucket}
end
http://elixir-lang.org/getting_started/mix_otp/5.html#5.2.1-starting-applications
When we run iex -S mix --no-start
and call Application.start(:kv)
, we get back {:error, {:not_started, :logger}}
instead of :ok
. I imagine this is because :logger
is included in mix.exs by default.
If the intent of the Getting Started guide is to be complete than chapters 10 and 11 are completely necessary. However, I've written entire non-trivial programs in Elixir that do not (explicitly) use any of the concepts introduced in these two chapters. Concepts introduced in later chapters on the other hand (e.g. enumerables and processes) are absolutely essential for any non-trivial program written in Elixir.
By having these chapters in the middle of the guide, we risk losing the interest and/or patience of the beginner before they get to the really exciting aspects of Elixir. I suggest moving these chapters further towards the end of the guide.
If I create a docs/
dir and rename docs.html
to docs/index.html
, going to this URL will no longer error out.
However, I don't know how the actual docs get uploaded to the site, i.e. how the docs/
dir is created.
erlang map is an ordered collection.
Some chapters in the guide are quite long and when giving a user a link you often want to link a specific section.
Hi,
In the documentation for Enum.traverse/2, the given code sample does not work in iex.
~> iex
Erlang/OTP 17 [erts-6.2.1] [source] [64-bit] [smp:4:4] [async-threads:10] [hipe] [kernel-poll:false] [dtrace]
Interactive Elixir (1.0.2) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)> Enum.traverse(%{a: 1, b: 2}, fn {k, v} -> {k, v * 2} end)
** (UndefinedFunctionError) undefined function: Enum.traverse/2
(elixir) Enum.traverse(%{a: 1, b: 2}, #Function<6.90072148/1 in :erl_eval.expr/5>)
iex(1)>
Elixir installed on OS Yosemite using Homebrew
https://github.com/elixir-lang/elixir-lang.github.com/blob/master/getting_started/4.markdown#422-using-protocols-with-records includes the following statement:
Note this only worked because, when we defined the protocol, we have added
Record
to the list of types supported by the protocol:@only [Atom, Record, Tuple, List, BitString, Any]
However, that is the first mention of @only
The last line in Section 4.1.1 (Pattern Matching) links to Kernel.html#defrecord/4 which doesn't exist. However Kernel.html#defrecord/3 does exist, I assume the guide meant to link to that instead?
The first paragraph in "2.6.3 Functions" states:
In Elixir, anonymous functions can accept many clauses and guards just the case mechanism we have just seen:
I'm guessing the highlighted just should be like instead.
In the first echo server example, it is a bit confusing that there are two recursive loops going on, when one will never exit the inner 'serve' loop to be able to recurse the 'loop_acceptor'. I would suggest making the loop_acceptor not recursive (and with a new name)
Hi
One of my favourite part of elixir is the pipe operator |>. However its behavior is anything but intuitive ! Indeed :
x |> function1 x1 |> function2 x2
is interpreted as
x |> function1(x1 |> function2 x2)
and not as
x |> (function1 x1) |> (function2 x2)
I find this choice weird, but i understand the reason (having just one kind of operator). My point being a small paragraph on pipe (with a big warning for the precedence rule) should be added on the section “Getting started/Other topics”.
Don't we need to announce 0.8.1 on the site?
As the amount of documentation grows and the amount of users reading it grows too (and hence also growing demand for more docs), our current setup with just the Getting Started guide and Library Reference is going to feel very limiting.
This is a proposal for a new layout of the docs. We'll have four different categories of documentation. The main three are going to be
The Language Guide will encompass many (but not all) Elixir features and concepts. It will be comprised of multiple sections including the current Getting Started guide and also more advanced topics on macros, protocols, OTP, etc.
Chapters in the Language Guide don't have to cover any given topic in its entirety. They will only provide as much detail as needed for basic understanding. They may, however, contain references to more in-depth articles in the Technical Guide.
The Technical Guide will contain select topics and will cover them in depth. So while Language Guide may have a chapter or two about macros and quoting, they will mostly be described in practical terms -- i.e. how to use them and what to use them for. But those chapters may point the readers to an article in the Technical Guide which will go over all there is to know about macros, quoting and all their options and implications.
Finally, the Language/Library Reference will be a concise reference of all of Elixir -- this is basically the current docs site. The former two guides are actually guides -- they describe technical details where appropriate, but are mostly aimed at guiding the reader. The Reference will merely provide low-level and implementation details on each module/function and not necessarily any guidance on how to best use them.
So the current Getting Started guide and Docs will map to the first section of the new Language Guide and the Language/Library Reference, respectively. It's not necessary to change the way the Getting Started guide is currently placed on the site -- it'll just have an additional link to the rest of the language guide somewhere.
When trying to use default values with multiple clauses you get an error telling you to define it in a separate clause. It would be helpful if this was covered in the getting started guide with a description of the syntax of a clause only for defaults.
It was also initially confusing for me how to refer to a named function as a default value, so adding that as an example would also be extremely helpful.
What exactly is an atom? What is their relationship with modules or Erlang's OTP? How an atom simply created by x = :foobar
differs from a module?
Which no longer exists.
Needs to reference String.to_atom instead since this big clean up: https://groups.google.com/forum/#!topic/elixir-lang-core/4nn24wr7AXQ
getting_started/mix_otp/5.markdown
is referencing GenEvent.add_handler/4
which appears to have been removed in elixir-lang/elixir@1d919f5
As seen here: http://library.elm-lang.org/DesignGuidelines.html
Install section says:
Fedora 17+ and Fedora Rawhide
Run: sudo yum -y install elixir
The problem is that for relases lower than 21 (20 is current stable), there is no Erlang 17.0 in repo. Also following command will install elixir 0.12.5 on Fedora 20.
And the prolbem is that section above mentions that elixir requires erlang 17, which is not true for 0.12.5.
What's even more problematic, erlang-solutions doesn't have Erlang 17 for Fedora (any version) and elixir for Fedora (any version).
So currently only way to have Elixir 1 on Fedora is compile OTP by hand and then binary elixir.
Would be cool if iex could assign form the last evaluated expression like irb's x = _
syntax (if Elixir does not have this functionality already).
I find it a bit unintuitive to have an ERROR 404 page when visiting: http://elixir-lang.org/docs/stable/ and http://elixir-lang.org/docs/master/
I think it should be helpful to list all the projects under that folder.
Hi,
I've been going through the Mix and OTP guide and ran into an error with the final code block in the chapter. It suggests suppressing the logger during the restart of the KV server. After adding the code to my project, I was getting the following error when running mix test
:
1) test server interaction (KVServerTest)
test/kv_server_test.exs:18
** (exit) exited in: GenEvent.call(Logger, Logger.Config, {:remove_backend, :console}, 5000)
** (EXIT) no process
stacktrace:
(elixir) lib/gen_event.ex:449: GenEvent.call/4
(logger) lib/logger.ex:354: Logger.remove_backend/2
test/kv_server_test.exs:5: KVServerTest.__ex_unit_setup_0/1
test/kv_server_test.exs:1: KVServerTest.__ex_unit__/2
I remembered removing :logger
from the mix.exs
applications earlier. :logger
is there by default from running mix new
, but it is not there in the code blocks in the guide, so I had removed it. The last time you see this section of the mix.exs
file is for adding the :pipes
application and it looks like this:
def application do
[applications: [:pipe, :kv],
mod: {KVServer, []}]
end
Once I added :logger
back in, the error went away.
Hi, I've been working through the Mix and OTP guide, and I think I've uncovered a problem. In part 6.1 of the Mix and OTP guide, ETS as a cache, we change KV.Registry.start_link/2 to take an extra parameter, the ets table name.
def start_link(table, event_manager, buckets, opts \\ []) do
#1. We now expect the table as argument and pass it to the server
GenServer.start_link(__MODULE__, {table, event_manager, buckets}, opts)
end
We see this text a few paragraphs down:
The changes we have performed above have definitely broken our tests. For starters, there is a new argument we need to pass to KV.Registry.start_link/3. Let's start amending our tests in test/kv/registry_test.exs by rewriting the setup callback:
But following the next set of instructions doesn't fix the tests, because we haven't updated KV.Supervisor to pass the new param. Instead, we continue to get this output every place we are supposed to see passing or failing tests, until we finally change the supervisor way down at the bottom of part 6.2.
➜ kv git:(master) ✗ mix test
Compiled lib/kv.ex
Compiled lib/kv/supervisor.ex
Generated kv.app
=INFO REPORT==== 12-Aug-2014::17:40:58 ===
application: kv
exited: {{shutdown,
{failed_to_start_child,'Elixir.KV.Registry',
{'EXIT',
{undef,
[{'Elixir.KV.Registry',start_link,
['Elixir.KV.EventManager',
[{name,'Elixir.KV.Registry'}]],
[]},
{supervisor,do_start_child,2,
[{file,"supervisor.erl"},{line,314}]},
{supervisor,start_children,3,
[{file,"supervisor.erl"},{line,297}]},
{supervisor,init_children,2,
[{file,"supervisor.erl"},{line,263}]},
{gen_server,init_it,6,
[{file,"gen_server.erl"},{line,306}]},
{proc_lib,init_p_do_apply,3,
[{file,"proc_lib.erl"},{line,239}]}]}}}},
{'Elixir.KV',start,[normal,[]]}}
type: temporary
** (Mix) Could not start application kv: KV.start(:normal, []) returned an error: shutdown: failed to start child: KV.Registry
** (EXIT) an exception was raised:
** (UndefinedFunctionError) undefined function: KV.Registry.start_link/2
(kv) KV.Registry.start_link(KV.EventManager, [name: KV.Registry])
(stdlib) supervisor.erl:314: :supervisor.do_start_child/2
(stdlib) supervisor.erl:297: :supervisor.start_children/3
(stdlib) supervisor.erl:263: :supervisor.init_children/2
(stdlib) gen_server.erl:306: :gen_server.init_it/6
(stdlib) proc_lib.erl:239: :proc_lib.init_p_do_apply/3
Of course, I'm still learning the basics and might have just missed something obvious. Don't come down on me too hard if that's the case :)
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.