dmitriid

dmitriid

It’s one of those “if you try it, you can figure it out” questions. I’m just hoping someone has already done this before and has some quick tips or a link to look at :slight_smile:

The meat of the question is: I have something in a file (data, or a custom DSL, or anything, really). Using this something, I want to create and compile an Elixir module and load it into the running application. When that something changes (let’s say, a file watcher tells me that contents have changed), I want to re-create/re-compile that module and reload it.

I know that I should start looking at Module.create/3. Perhaps there are other things I can/should look at and consider?

Showing Posts 1 to 5

kokolegorille

kokolegorille

You might use @external_resource attribute on a module…

If the external resource file change, the module will recompile.

03juan

03juan

You could try Code.eval_string/3 if you want to parse the changed “something” file from within Elixir to produce a string representation of the module def.

Alternatively Code.eval_file/2 if you dynamically write/update an .ex file from your “something” file.

mudasobwa

mudasobwa

Creator of Cure

This is compilation-time dependency, which helps to mark a module as “recompilation needed” for the regular elixir compiler when say mix compile is to be invoked next time. It has zero value here, unfortunately.

Yes, kinda. There is a pitfall one should be aware of: the module recompilation is not instant.

I would spawn the process as gateway access to the module to be recompiled that both recompiles whatever is needed and its mailbox acts as a queue for both subsequent recompilations and all the interactions with this module. That way one can be sure that the module gets accessed if and only it’s available.

Please note, that Module.create/3 accepts an AST. If you want to load a regular .ex[s] file, use Code.eval_file/2 as suggested by @03juan.

kokolegorille

kokolegorille

Oops, my bad… I did not catch it should be for runtime.

dmitriid

dmitriid OP

Good point/catch about the queue. Especially if I want this to be based on a custom DSL or custom data, compilation will definitely not be instant.

— All posts loaded —

Where Next? Top

Trending in Questions Top

Blokh
Hey guys, I’ve got a huge CSV ( around 10 GB ) that needs to be processed hourly Do you guys have any suggestions what is the best prac...
New
kszambelanczyk
Hello! Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app. I creat...
New
RemyXRenard
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
matt-savvy
Anyone here using Honeybadger? My Honeybadger account is being overwhelmed with noise from some bots. Seeing a lot of Bandit.HTTPError...
New
velrest
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
samoloth
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
FlyingNoodle
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New

Other Trending Topics Top

CodeSync
Testing Concurrency and Fault Tolerance in Elixir/Nerves - Marta Habdas | ElixirConf EU 2026 Comments welcome! View the <...
New
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge &amp; Solve. They are GUI (Emerge) and State management (S...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews