7stud
I’m trying to use a require statement:
my_lib.exs:
defmodule MyLib do
require MyMath
def go(), do: MyMath.calc(1, 2)
end
Here’s the MyMath module:
my_math.exs:
defmodule MyMath do
def calc(x, y), do: x+y
end
Both files are in the same directory. Here is what I get:
~/elixir_programs$ iex my_lib.exs
Erlang/OTP 20 [erts-9.3] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:10] [hipe] [kernel-poll:false]
** (CompileError) my_lib.exs:2: module MyMath is not loaded and could not be found
Trending in Questions
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
Hello,
I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
Documentation
While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
So my question is quite simple and i have found no conclusive answer on forum, google or AI.
Should we use :erlang.float for Integer to ...
New
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
Other Trending Topics
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hi there! We created Gust: A task orchestrator inspired by Airflow.
For those who have never heard about Aiflow, it’s a Python-based wor...
New
Hi everyone!
The first release candidate for the Expert language server project is now available!
We’ve published a press release detai...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixirconf-us
- #ai
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #hex
- #security











Most Liked- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
michalmuskala
Because macros can change semantics of the core language constructs, you have to explicitly opt-in into using them. This was a very early design decision.
mgwidmann
requiredoes not look for files at all, the module has to be already loaded in order for it to work in the way you are trying. If you add to the top of your fileCode.require_file("my_math.exs"), you should see it start working. If you do$ mix new my_projectand put these files inlib(as.exfiles not.exs) you won’t need to do anything and the compiler will find the right file automatically; this is the typical way to do things. After that, run$ iex -S mixand your code will be available for execution (type into the promptMyLib.go()).As for the code you’ve written, you don’t need a
requirestatement at all. Requires are for loading macros before they’re used, which your function is not (its just a plain function). You can remove therequire MyMathand everything will still work fine.You can read more about
alias,require,importandusehere: https://elixir-lang.org/getting-started/alias-require-and-import.htmlmgwidmann
Without a doubt you are causing yourself more headache than its worth. Create a new mix project and put the files in
liband call it a day. Mix makes this easy for this very reason.