4 ms·
This is a more just WRT you fighting with Elixir: > Simple things like loops and encapsulation seem incredibly complicated. Something as simple as setting a va
by RobertKerans 10y ago
This is a more just WRT you fighting with Elixir:
> Simple things like loops and encapsulation seem incredibly complicated. Something as simple as setting a value in a two-dimensional array...
- Elixir doesn't have loops. You use recursion.
- Elixir only has modules for organisation, and modules are just functions. It's just functions functions functions all the way down. You can nest modules in modules and so on, that's how you would achieve encapsulation.
> defmodule Foo do
.. defmodule Bar do
.. def add(a,b), do: a + b
.. end
.. end
> Foo.Bar.add(1,2)
- Further to that, you'd generally use processes for holding state, but those processes are also just functions, nothing special or different. See http://ferd.ca/the-zen-of-erlang.html http://ferd.ca/the-zen-of-erlang.html
- Use maps, not lists, to emulate a 2d array. Lists are not designed to do what you're trying to do there. As you've found out, it becomes incredibly ungainly. Daniel Berkompas wrote a post on this exact thing recently: http://blog.danielberkompas.com/2016/04/23/multidimensional-arrays-in-elixir.html http://blog.danielberkompas.com/2016/04/23/multidimensional-...
I would stay stick with it. If you shifted across to Scala and tried to do things in the way I think you're doing them atm, you might as well be writing Java: changing to Scala won't make it any easier to adapt to a functional style.