Last active
February 2, 2018 16:35
-
-
Save sharno/dad4d4780f54c285508513bf5157fdc1 to your computer and use it in GitHub Desktop.
As Elixir doesn't have a way to create an anonymous recursive function yet, we have to do a little trick and pass the function to itself when calling it to get recursion
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
print = fn f -> | |
receive do | |
name -> IO.puts(name) | |
f.(f) | |
end | |
end | |
server = spawn(fn -> print.(print) end) | |
send(server, "Sharno") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
concat = fn message -> | |
print = fn f -> | |
receive do | |
name -> IO.puts(message <> name) | |
f.(f) | |
end | |
end | |
print.(print) | |
end | |
greet = spawn(fn -> concat.("Hello ") end) | |
send(greet, "Sharno") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment