Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documentation for defrecord needs updating #2510

Closed
jdeisenberg opened this issue Jul 9, 2014 · 3 comments
Closed

Documentation for defrecord needs updating #2510

jdeisenberg opened this issue Jul 9, 2014 · 3 comments
Milestone

Comments

@jdeisenberg
Copy link
Contributor

File http://elixir-lang.org/docs/master/elixir/Record.html

This does not compile:

defmodule User do
  Record.defrecord :user, [name: "José", age: "25"]
end

produces this (some output removed to save space)

iex(1)> c("user.ex")
== Compilation error on file user.ex ==
** (CompileError) user.ex:2: you must require Record before invoking the macro Record.defrecord/2
    (elixir) src/elixir_dispatch.erl:107: :elixir_dispatch.dispatch_require/6
    (elixir) src/elixir.erl:196: :elixir.quoted_to_erl/3
    (stdlib) erl_eval.erl:657: :erl_eval.do_apply/6
    (elixir) src/elixir.erl:165: :elixir.erl_eval/2
    (elixir) src/elixir.erl:165: :elixir.erl_eval/2

Once you add the require User, it compiles, but the example does not work:

# To create records
user()        #=> {:user, "José", 25}
user(age: 26) #=> {:user, "José", 26}

as shown here:

iex(2)> require User
nil
iex(3)> user()
** (RuntimeError) undefined function: user/0
iex(4)> user(age: 26)
** (RuntimeError) undefined function: user/1
@ericmj
Copy link
Member

ericmj commented Jul 9, 2014

The docs are correct imo. It is fair to assume that the functions that we are describing will be imported or required.

@josevalim
Copy link
Member

It doesn't hurt to make the docs clearer. I will push a fix soon.

@josevalim josevalim added this to the v1.0 milestone Jul 10, 2014
@masato25
Copy link

HI, I think the doc should also update this:
record = User.user()
-> {:user, "meg", "25"}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

4 participants