The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

370214 (3) [Avatar] Offline
#1
Page 117 in the PDF

When working on todo_crud.ex (TodoList module) and trying to use it in iex (following the example "iex todo_crud.ex) I keep getting the error

(CompileError) todo_crud.ex:4: TodoList.__struct__/0 is undefined, cannot expand struct TodoList
    (elixir) src/elixir_map.erl:55: :elixir_map.translate_struct/4
    (elixir) src/elixir_clauses.erl:36: :elixir_clauses.clause/7
    (elixir) src/elixir_def.erl:178: :elixir_def.translate_clause/7
    (elixir) src/elixir_def.erl:167: :elixir_def.translate_definition/8
    (elixir) src/elixir_def.erl:82: :elixir_def.store_definition/9
    todo_crud.ex:4: (module)


I looked for errors in my code and couldn't find any as well as copying verbatim the code from the Elixir in Action repo on github. Is this occuring because the complete module has not been compiled yet and the struct is being called?
sjuric (109) [Avatar] Offline
#2
I just verified and the code works fine.
This is most likely happening because you have compiled some previous version of the TodoList module with elixirc. Could you please check that same folder for *.beam files, delete them if they exist, and try again?

370214 wrote:Page 117 in the PDF

When working on todo_crud.ex (TodoList module) and trying to use it in iex (following the example "iex todo_crud.ex) I keep getting the error

(CompileError) todo_crud.ex:4: TodoList.__struct__/0 is undefined, cannot expand struct TodoList
    (elixir) src/elixir_map.erl:55: :elixir_map.translate_struct/4
    (elixir) src/elixir_clauses.erl:36: :elixir_clauses.clause/7
    (elixir) src/elixir_def.erl:178: :elixir_def.translate_clause/7
    (elixir) src/elixir_def.erl:167: :elixir_def.translate_definition/8
    (elixir) src/elixir_def.erl:82: :elixir_def.store_definition/9
    todo_crud.ex:4: (module)


I looked for errors in my code and couldn't find any as well as copying verbatim the code from the Elixir in Action repo on github. Is this occuring because the complete module has not been compiled yet and the struct is being called?
370214 (3) [Avatar] Offline
#3
Ahh I see. Stupid mistake on my part. Thank you.
sjuric (109) [Avatar] Offline
#4
It's just a consequence of the fact that simple scripts are used at this early stage in the book.
In chapter 7, the "mix" tool is introduced and used throughout the rest of the book to properly build Elixir projects. With this tool such errors shouldn't happen smilie

370214 wrote:Ahh I see. Stupid mistake on my part. Thank you.
scott hamilton (1) [Avatar] Offline
#5
That one got me too