What is MFA in Elixir?

I’m posting this to force myself to remember what it means.

M : Module

F : Function

A : Arguments

Module, Function, Arguments.

pid = spawn(MyModule, :myfunc, [])


iex(1)> pid = spawn(Explorate, :loop, [])

Can then send that pid a message.

defmodule Explorate do

  def loop do
    receive do
      { :hello } -> IO.puts "ahoy, shipmate!"
      _ -> IO.puts "Yous no ma shipmayte"


Interactive Elixir (1.5.2) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)> pid = spawn(Explorate, :loop, [])
iex(2)> send(pid, "ddd")
Yous no ma shipmayte
iex(3)> send(pid, {:hello})
ahoy, shipmate!

Useful link

Note also to call loop  again to recurse, otherwise you only get to call the pid  once.

Published by

Code Review

CodeReviewVideos is a video training site helping software developers learn Symfony faster and easier.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.