Last active
May 29, 2021 17:51
-
-
Save ryo33/7660534418edfa7daf4afaa3288f7c83 to your computer and use it in GitHub Desktop.
Primality Testing in Elixir using Cizen
This file contains hidden or 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
# 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