Permalink
Browse files

Fix deprecation warnings for Elixir 0.12.2

  • Loading branch information...
1 parent b06948c commit 75b1fa47c735de62a3f05dbce348a823682dec97 @seven1m committed Jan 15, 2014
Showing with 21 additions and 21 deletions.
  1. +4 −4 08-process-ring.exs
  2. +1 −1 09-ping.exs
  3. +13 −13 14-spades.exs
  4. +3 −3 17-dining-philosophers.exs
View
@@ -14,16 +14,16 @@ defmodule Pinger do
{[next | rest], msg, count} when count <= limit ->
IO.puts "Received: #{inspect msg} (count #{count})"
:timer.sleep(1000)
- next <- {rest ++ [next], echo, count+1}
+ send next, {rest ++ [next], echo, count+1}
ping(echo, limit)
# over our limit of messages, send :ok around the ring
{[next | rest], _, _} ->
- next <- {rest, :ok}
+ send next, {rest, :ok}
# someone told us to stop, so pass along the message
{[next | rest], :ok} ->
- next <- {rest, :ok}
+ send next, {rest, :ok}
# done!
{[], :ok} -> :ok
@@ -37,7 +37,7 @@ defmodule Spawner do
{foo, _foo_monitor} = Process.spawn_monitor(Pinger, :ping, ["ping", limit])
{bar, _bar_monitor} = Process.spawn_monitor(Pinger, :ping, ["pong", limit])
{baz, _baz_monitor} = Process.spawn_monitor(Pinger, :ping, ["pung", limit])
- foo <- {[bar, baz, foo], "start", 0}
+ send foo, {[bar, baz, foo], "start", 0}
wait [foo, bar, baz]
end
View
@@ -10,7 +10,7 @@ defmodule Ping do
Ping an IP asynchronously and send the {ip, exists} tuple to the parent
"""
def ping_async(ip, parent) do
- parent <- {ip, ping(ip)}
+ send parent, {ip, ping(ip)}
end
@doc """
View
@@ -71,13 +71,13 @@ defmodule Dealer do
end
defp deal([player | rest_players], [card | rest_cards]) do
- player <- {:deal, card}
+ send player, {:deal, card}
deal(rest_players ++ [player], rest_cards)
end
defp deal(_, []), do: :ok
defp signal_start(players) do
- Enum.each players, fn p -> p <- :start end
+ Enum.each players, fn p -> send(p, :start) end
end
defp wait_for_plays(players, cards_played // [], tricks_played // 0) when tricks_played < 13 do
@@ -89,11 +89,11 @@ defmodule Dealer do
if length(cards_played) == 4 do
{winner, _} = trick_winner(cards_played)
broadcast(players, {:trick, winner})
- winner <- :your_turn
+ send winner, :your_turn
wait_for_plays(players, [], tricks_played + 1)
else
players = reorder_players(players, player)
- Enum.first(players) <- :your_turn
+ send List.first(players), :your_turn
wait_for_plays(players, cards_played, tricks_played)
end
end
@@ -108,11 +108,11 @@ defmodule Dealer do
if Enum.any?(cards_played, fn {_, {s, _}} -> s == "Spades" end) do
sort_cards(cards_played)
|> Enum.filter(fn {_, {s, _}} -> s == "Spades" end)
- |> Enum.first
+ |> List.first
else
sort_cards(cards_played)
|> Enum.filter(fn {_, {s, _}} -> s == suit end)
- |> Enum.first
+ |> List.first
end
end
@@ -123,7 +123,7 @@ defmodule Dealer do
end
defp broadcast(players, action) do
- Enum.each players, fn p -> p <- action end
+ Enum.each players, fn p -> send(p, action) end
end
defp reorder_players(players = [first | rest], player) do
@@ -147,7 +147,7 @@ defmodule Player do
"""
def start_game do
dealer = spawn_link(Dealer, :start_game, [])
- dealer <- {:join, self}
+ send dealer, {:join, self}
IO.puts "I am #{inspect self}"
wait_to_start(dealer)
end
@@ -157,7 +157,7 @@ defmodule Player do
"""
def join do
dealer = :global.whereis_name(:dealer)
- dealer <- {:join, self}
+ send dealer, {:join, self}
IO.puts "I am #{inspect self}"
wait_to_start(dealer)
end
@@ -173,7 +173,7 @@ defmodule Player do
end
defp play(dealer, hand, card) do
- dealer <- {:play, card, self}
+ send dealer, {:play, card, self}
List.delete hand, card
end
@@ -202,8 +202,8 @@ defmodule Player do
defp select_and_play_card(dealer, hand) do
show_hand(hand)
- if Enum.first(System.argv) == "--test" do # TODO how to set debug mode based on args?
- card = Enum.shuffle(hand) |> Enum.first
+ if List.first(System.argv) == "--test" do # TODO how to set debug mode based on args?
+ card = Enum.shuffle(hand) |> List.first
else
card = select_card(hand)
end
@@ -232,7 +232,7 @@ defmodule Player do
end
end
-if Enum.first(System.argv) == "--test" do
+if List.first(System.argv) == "--test" do
ExUnit.start
defmodule SpadesTest do
@@ -61,7 +61,7 @@ defmodule Table do
if length(forks) >= 2 do
[{pid, _} | waiting] = waiting
[fork1, fork2 | forks] = forks
- pid <- {:eat, [fork1, fork2]}
+ send pid, {:eat, [fork1, fork2]}
end
end
receive do
@@ -79,7 +79,7 @@ end
defmodule Dine do
def dine(phil, table) do
- table <- {:sit_down, self, phil}
+ send table, {:sit_down, self, phil}
receive do
{:eat, forks} ->
phil = eat(phil, forks, table)
@@ -93,7 +93,7 @@ defmodule Dine do
IO.puts "#{phil.name} is eating (count: #{phil.ate})"
:timer.sleep(:random.uniform(1000))
IO.puts "#{phil.name} is done eating"
- table <- {:give_up_seat, forks, phil}
+ send table, {:give_up_seat, forks, phil}
phil
end

0 comments on commit 75b1fa4

Please sign in to comment.