Skip to content

Instantly share code, notes, and snippets.

@ryo33
Last active May 29, 2021 17:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryo33/7660534418edfa7daf4afaa3288f7c83 to your computer and use it in GitHub Desktop.
Save ryo33/7660534418edfa7daf4afaa3288f7c83 to your computer and use it in GitHub Desktop.
Primality Testing in Elixir using Cizen
# This is a comment.
# Allows you to use SomeModule with the long path.
alias Too.Long.Path.To.SomeModule
# This is needed for using macros in SomeModule.
require SomeModule
# Spawns a new process that prints a result of 1 + 1.
spawn(fn ->
IO.puts(1 + 1)
end)
# Gets a message from the mailbox and prints it (each process has its own mailbox).
spawn(fn ->
receive do
x -> IO.puts(x)
end
end)
# Sends a message to a process.
pid = spawn(fn ->
receive do
x -> IO.puts(x)
end
end)
send pid, "Hi"
# Here is also a process, and you can get the pid of "Here" by `self()`.
pid = self()
send pid, "Hi here"
receive do
x -> IO.puts(x)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment