I’m having a difficult time figuring out how to get started writing a program that does anything.
All the guides and tutorials that I have found either give examples using iex or partial code.
I know I’m being extremely ambitious here, but one day I would like to make two programs, one that sits idle and listens for a message with two numbers, a and b, then calculates a+1 and b+2 and returns the result of this operation to the console with IO.puts.
The other program would somehow get the PID of the first program to periodically send pairs of numbers to be processed.
I have no idea where to begin.
How am I supposed to learn how to start a listener and get its PID? This listener has to be a real program that runs independently, not a sandbox doodle in iex…
How am I supposed to learn how to take a and b and calculate them both? That’s two separate operations from one input. And I need to be able to access the result to include them in the IO.puts string with something like <> #{a}.
How am I supposed to learn how to make another real program, not iex, speak to this program?
I hope I don’t sound too demanding. I have read a lot already on how things work on elixir-lang.org and the hexdocs, but I can hardly find any glue that helps stick anything together.
For some context of my programming skill level, I only have a few months of experience with a scripting language that is distantly similar to C#.
What I have right now is this:
defmodule Listener do
{:ok, pid} = Task.Supervisor.start_link()
task =
Task.Supervisor.async(pid, fn →
IO.puts("My pid is ")
end)
Task.await(task)
end
which is almost completely stolen from Task — Elixir v1.11.3
I haven’t found anything yet that explains the {:ok convention, and if I try to add ("My pid is "<> “#{pid}”) the compiler doesn’t like it because apparently the ) isn’t there.
I hope someone can show me how to fish…