Hi,
I’m just working my way into Elixir and loving it… it’s crazy how you can get complicated stuff to work first time that would NEVER come our right first time in a procedural.
So … no global variables.
I’m working on a Bridge hand dealer as my exploration path, so I need a deck of cards to start with. Normally I’d create a data structure and assign it to a global variable and use that throughout the application … but … no global variables.
So here’s what I came up with
def deck do
[
{0, 0}, {0, 1}, {0, 2}, {0, 3}, {0, 4}, {0, 5}, {0, 6}, {0, 7}, {0, 8}, {0, 9}, {0, 10}, {0, 11}, {0, 12},
{1, 0}, {1, 1}, {1, 2}, {1, 3}, {1, 4}, {1, 5}, {1, 6}, {1, 7}, {1, 8}, {1, 9}, {1, 10}, {1, 11}, {1, 12},
{2, 0}, {2, 1}, {2, 2}, {2, 3}, {2, 4}, {2, 5}, {2, 6}, {2, 7}, {2, 8}, {2, 9}, {2, 10}, {2, 11}, {2, 12},
{3, 0}, {3, 1}, {3, 2}, {3, 3}, {3, 4}, {3, 5}, {3, 6}, {3, 7}, {3, 8}, {3, 9}, {3, 10}, {3, 11}, {3, 12}
]
end
then to deal a hand I have
def deal do
dealing(Enum.shuffle(deck()))
end
where dealing splits the list into four hands.
I’m hoping I don’t get something … as this makes my procedural brain go nuts … I’m getting a new copy of the deck every time?
Jonathan.