Compiling elixir code

What happens

Hi!, recently I start to solve challenges with elixir language and I’ve been using this line as my execution command

cat DATA.lst | elixir -r ludsrill.exs -e solution.main

I was asked to change it to a simpler one like:

cat DATA.lst | elixir ludsrill.exs

I want to share the solution and problems that I meet

What do you understand or find about that problem

Solution for this it’s simple, elixir language has this estructure

defmodule Solution do
  def main do
    # This is the main function to my code

If I want to execute this code with this line cat DATA.lst | elixir ludsrill.exs I only need to add the following line to the finish of my code

# This will call my module then the main function

So far there’s no problem, however, with this changes it’s not possible pass pipeline for elixir, specific the compilation for this pipeline.

You make any workaround? What did you do?

First of all the problem that I got in pipeline was this:

To try reproduce this error I look at on file and use exactly this command to compile my code.

In my first try I use the line and I get this error and compilation never happen

Then I decided change a little adding my stdin

As you see there’s no problem with compilation, then I think that DATA.lst file it’s necessary to compile code for elixir, to prove this I delete my DATA.lst of my project and compile the code again and I got the same error than then pipeline.

As you see it’s necessary and after all that I realized that the same problem was discussed here :sweat_smile:

The solution was to use this line to execute, which is the line that I’ve been using

cat DATA.lst | elixir -r ludsrill.exs -e solution.main


image of error:

I need help with

Now I know that the command that I use is allowed, however, since I was ask to do it, I want to know if this is fine or it’s necessary wait for some changes in builders file. thanks!

Hi, for that specific case, I was investigating ways to avoid this kind of problem, seems like the commands like elixir and elixirc are the same with only one difference, the second one have an output of a BEAM file, for that the compilation with elixirc makes a run at the same time.

How on the compilation the data is needed to make the execution, we can make a workaround and is easy to implement it, you should handle the case when the data that you will send is eof or nil, this is easy with conditionals.

with this little handle, you can pass the compilation without problems.

BTW, this isn’t the first time that someone makes handles for unexpected inputs on challenges:


On that challenge, you can found a handle to input different from a number.

For that this isn’t an error from the builder, is an error that you already didn’t expect that you could receive any different data or no data at all, and that is not a bad thing, only an unexpected behavior on an ambient that is supposed to work in the ways that we build it.

For now, you can make the handle or use the weird command since we can discuss if we should ask for the use of handles for unexpected values on the stdin because if the received data is expected that should means the rest of the code works well too.

1 Like

I’m going to start using that error handling, thanks for your answer and clarification!

Hi, I was discussing it and the conclusion was that we are going to expect the use of the handle because the code should not fail no matter the scenario.

1 Like