stevensonmt

stevensonmt

Using __MODULE__ in nested modules

If I have nested modules is it possible to use the syntax __MODULE__ in the submodule? I’m getting an error that says “cannot access struct RootModule …” when I have something like this:

defmodule RootModule do 
  defmodule SubModule do 
    defstruct [:foo, :bar]
    
    @spec new() :: %__MODULE__{}
    def new() do 
      %__MODULE__{}
    end 
  end
end

Marked As Solved

stevensonmt

stevensonmt

ah criminy. different typo. I had inserted a wayward end somewhere above the function definition so the submodule was “closed” and the function was being defined in the root module. derp.

Also Liked

ityonemo

ityonemo

defstruct, not struct. =D

ityonemo

ityonemo

works for me, with defstruct.

Last Post!

stevensonmt

stevensonmt

sorry see above re: typo. Thanks for helping.

Where Next?

Popular in Questions Top

Qqwy
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
lessless
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New

Other popular topics Top

grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 54092 488
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New
sergio
Kind of like when jquery came out, it was super necessary. Existing drag and drop libraries have a bunch of baggage to support old browse...
New

We're in Beta

About us Mission Statement