didier1

didier1

So, I am using elixir for the advent of code daily challenges. Initially I just had a simple .exs file and I would just invoke it with elixir <file-name> (or with #!/usr/bin/env elixir as the first line). That worked fine.

Ok, fast forward to more complex scripts and now I need to use some external packages (say, the Heap package).

I naturally switched to mix so I can cleanly define my dependencies in my mix.exs file. I created a simple app without supervisor (mix new day17)

I am running into some issues running my script.

Now imagine my script is a simple IO.puts(:hello) (in the default lib/p.exs, outside of a defmodule).

If I leave it as is, mix will execute this during its compile phase, so calling mix run will indeed execute that IO.puts. Unfortunately calling mix run a second won’t (because it’s already compiled).

So if I want mix run to always run my code, I guess I have to define a proper app in my mix.exs. Easy. I defined a start/2 function in the P module file (and moved my IO.puts in there) and added mod: {P, []} to the def application section in mix.exs.

This works (and it will properly execute my IO.puts whenever I invoke mix run), except that it fails at the end because it expect my start function to return the pid of a forked process, etc… the whole supervisor tree thing, which is definitely not what I want for my simple script.

Am I missing something obvious here ? (yes, I could also use iex -S mix and then invoke something like P.start manually, and then c("lib/p.ex") whenever I change anything in my file, but that seems quite tedious)

Showing Posts 1 to 6

al2o3cr

al2o3cr

Not a response to your ultimate question, but if this is all you need then Mix.install solves that problem without needing any other changes to your script.

didier1

didier1 OP

Right, I actually did try that (should have specified this in my post). And you are right. It does work (the script executes properly)

The problem there is that the editors I tried (vscode, nvim) don’t give me intellisense for the dynamically imported packages (say the Heap package), which sucks. This indeed would have been the simplest solution…

Thanks

D4no0

D4no0

Have you tried livebook?

IloSophiep

IloSophiep

My solution for this was to define a test that runs my “entry point function” and use mix test to execute it whenever I wanted. There is also a section about running mix test with a filesystem watcher if you want to have even less manual work to do. You can also only run stale tests so you can use your one mix project for all the days and just run the test case(/-s) related to your current day.

Not exactly an answer to your question, sorry, but might be helpful either way… :sweat_smile:

didier1

didier1 OP

actually, this is pretty good. It might not be perfect, but it does the job for sure.

thanks a lot IloSophiep

didier1

didier1 OP

D4no0: I haven’t had a chance to try lovebook yet. Although I keep hearing about it. I was trying to see if a simpler local solution would work or try to figure if I was completely misusing mix. Thx.

— All posts loaded —

Where Next? Top

Trending in Questions Top

stjefim
Hello! Suppose you are building workflow (order / task / payment) processing system with the following requirements: Each workflow con...
New
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
roeland
Kia ora, We have been using elixir-google-api to connect to Google Drive. However, with the updates to Tesla due to CVEs this is now bro...
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
Onor.io
I have what I’ve heard referred to as a “lookup table” in my database. This is a way of assigning codes to common values. One common lo...
New
jaybe78
Hello, I’m developing a online persistent chat system (what’s app) like using elixir/dynamodb/aws for a mobile app(flutter). The diffic...
New
Trolleger
What approach to take when sending live updates to “random” users Hi! I have a question, I have a little chat app, and when I create a DM...
New

Other Trending Topics Top

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
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
wintermeyer
There are three potential reasons for members of this forum to have a look at https://vutuv.de You are tired or annoyed of LinkedIn. Yo...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews