summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorConnor Rigby <connorr@hey.com>2022-01-03 14:03:49 -0700
committerGitHub <noreply@github.com>2022-01-03 22:03:49 +0100
commit06a02ac7f64b33daaa8ba7bf86951f464fa867f0 (patch)
tree7476978ed2e6b11073ded52e3f7d1c05c7e91b46
parentf19b7e2d5d2c29855c9183a1c9b2e5053aa06cd4 (diff)
downloadelixir-06a02ac7f64b33daaa8ba7bf86951f464fa867f0.tar.gz
Add name lookup to pid/1 helper (#11536)
-rw-r--r--lib/iex/lib/iex/helpers.ex9
-rw-r--r--lib/iex/test/iex/helpers_test.exs1
2 files changed, 9 insertions, 1 deletions
diff --git a/lib/iex/lib/iex/helpers.ex b/lib/iex/lib/iex/helpers.ex
index 548c7e9b6..1a46ddc02 100644
--- a/lib/iex/lib/iex/helpers.ex
+++ b/lib/iex/lib/iex/helpers.ex
@@ -1178,18 +1178,25 @@ defmodule IEx.Helpers do
defp history, do: Process.get(:iex_history)
@doc """
- Creates a PID from `string`.
+ Creates a PID from `string` or `atom`.
## Examples
iex> pid("0.21.32")
#PID<0.21.32>
+ iex> pid(:init)
+ #PID<0.0.0>
+
"""
def pid(string) when is_binary(string) do
:erlang.list_to_pid('<#{string}>')
end
+ def pid(name) when is_atom(name) do
+ Process.whereis(name)
+ end
+
@doc """
Creates a PID with 3 non-negative integers passed as arguments
to the function.
diff --git a/lib/iex/test/iex/helpers_test.exs b/lib/iex/test/iex/helpers_test.exs
index f189be972..3a68de6a5 100644
--- a/lib/iex/test/iex/helpers_test.exs
+++ b/lib/iex/test/iex/helpers_test.exs
@@ -1347,6 +1347,7 @@ defmodule IEx.HelpersTest do
test "builds a PID from string" do
assert inspect(pid("0.32767.3276")) == "#PID<0.32767.3276>"
assert inspect(pid("0.5.6")) == "#PID<0.5.6>"
+ assert inspect(pid(:init) == "#PID<0.0.0>")
assert_raise ArgumentError, fn ->
pid("0.6.-6")