3 ms·
> how to reference functions in the same module sometimes requiring to still write the name of the module Not sure what you mean here. If the function is in th
by arrowsmith 3y ago
> how to reference functions in the same module sometimes requiring to still write the name of the module
Not sure what you mean here. If the function is in the same module then you should be able to refer to it without including the module name.
Can you give some example code to show what you mean?
- zelphirkalt 3y agoI don't know exactly where it happened, but here [1] is a typical AoC code using Elixir. At some point I got so annoyed by Elixir telling me it does not find the functions of the very same module, that I simply defaulted to always writing the module name. [1]: https://codeberg.org/ZelphirKaltstahl/advent-of-code-2023/src/branch/main/elixir/day_04/lib/part-01.ex https://codeberg.org/ZelphirKaltstahl/advent-of-code-2023/sr... Edit: Ah yes, I remember it happening in |> pipes a lot.
- arrowsmith 3y agoI still don't get it. I downloaded your code and stripped `Part01.` from all the function calls and it worked fine with no warnings. What's the problem? By the way, these two lines are redundant: alias FileHandling, as: FileHandling alias ListUtils The first line is redundant because `alias X, as: Y` makes module X available with the name Y - so if X and Y are the same then it doesn't achieve anything. And the second line is redundant because `alias X.Y.Z` with no `as` makes module `X.Y.Z` available with the abbreviated name `Z`. But if the original module name contains no dots then then there's nothing to abbreviate.
- conradfr 3y agoNot a function but when a module has a struct that you want to use inside the module you need to use the full module name or alias itself.
- arrowsmith 3y agoYou can write __MODULE__ to reference the current module. Or if the current module is a struct you can write %__MODULE__{}
- conradfr 3y agoThat's not very pretty though ;) IIRC you can also write: alias __MODULE__