These are various tidbits found that might come in useful at some point. :)
git clone git@github.com:ferd/erlang-history.gitcd erlang-historysudo make install
def my_func("prefix" <> rest = value) do
IO.puts "#{value} starts with \"prefix\""
endFrom the Elixir slack:
Hey guys :simple_smile: I'm learning how you're supposed to keep state in processes by recursion. But I was wondering...doesn't this eventually end in a stack too deep? If the process keeps spawning itself after receiving and handling a message, with the new state, can it keep doing that infinitely? How?
gerred [5:45 AM] @xtagon look up tail call optimization, the BEAM VM does it. :simple_smile:
cpjk [5:54 AM] Along with what @gerred said, OTP also provides nice behaviours for spawning processes to maintain state, so that you don't have to think about it. This SO answer might help.
quote returns the AST of some code
iex(1)> quote do
...(1)> 1 + 2
...(1)> end
{:+, [context: Elixir, import: Kernel], [1, 2]}
If you capture the output of a defined module you can see that the third item is a binary representation of the module which apparently means that you can pass the definition around from node to node and have it execute even though there is no local version of the definition.
iex(1)> my_module = defmodule MyModule do
...(1)> def test(message) do
...(1)> message
...(1)> end
...(1)> end
{:module, MyModule,
<<70, 79, 82, 49, 0, 0, 4, 148, 66, 69, 65, 77, 69, 120, 68, 99, 0, 0, 0, 117, 131, 104, 2, 100, 0, 14, 101, 108, 105, 120, 105, 114, 95, 100, 111, 99, 115, 95, 118, 49, 108, 0, 0, 0, 2, 104, 2, ...>>,
{:test, 1}}