From 46d840f1e1b380cfdce63d213a1e0ed617e59232 Mon Sep 17 00:00:00 2001 From: Mario Frasca Date: Tue, 4 Jun 2019 09:37:30 -0500 Subject: [PATCH] explain `defp` --- getting-started/processes.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/getting-started/processes.markdown b/getting-started/processes.markdown index 65e5b9445..81b7aee58 100644 --- a/getting-started/processes.markdown +++ b/getting-started/processes.markdown @@ -186,7 +186,7 @@ defmodule KV do end ``` -Note that the `start_link` function starts a new process that runs the `loop/1` function, starting with an empty map. The `loop/1` function then waits for messages and performs the appropriate action for each message. In the case of a `:get` message, it sends a message back to the caller and calls `loop/1` again, to wait for a new message. While the `:put` message actually invokes `loop/1` with a new version of the map, with the given `key` and `value` stored. +Note that the `start_link` function starts a new process that runs the `loop/1` function, starting with an empty map. The `loop/1` (private) function then waits for messages and performs the appropriate action for each message. We made `loop/1` a private by using `defp` instead of `def`. In the case of a `:get` message, it sends a message back to the caller and calls `loop/1` again, to wait for a new message. While the `:put` message actually invokes `loop/1` with a new version of the map, with the given `key` and `value` stored. Let's give it a try by running `iex kv.exs`: