Permalink
Browse files

If we are connected to a remote node, print "rem" in iex

This makes it easy to check if we are on a remote node or not.
  • Loading branch information...
1 parent 10cf226 commit 6c87df4c7ade604b1717e1e88f7cb08ab4d12754 @josevalim josevalim committed Aug 9, 2012
@@ -11,22 +11,25 @@ defmodule IEx.UnicodeIO do
return a list with the new characters inserted.
"""
def get(config) do
- prefix = case config.cache do
- [] -> "iex"
- _ -> "..."
- end
- prompt = case node do
- :nonode@nohost ->
- "#{prefix}(#{config.counter})> "
- n ->
- "#{prefix}(#{n})#{config.counter}> "
- end
+ prefix = if config.cache != [], do: "..."
+
+ prompt =
+ if is_alive do
+ "#{prefix || remote_prefix}(#{node})#{config.counter}> "
+ else
+ "#{prefix || "iex"}(#{config.counter})> "
+ end
+
case IO.gets(prompt) do
{ :error, _ } -> ''
data -> :unicode.characters_to_list(data)
end
end
+ defp remote_prefix do
+ if node == node(:erlang.group_leader), do: "iex", else: "rem"
+ end
+
@doc """
Implements the put IO API used by IEx. It receives the
result and prints it.
View
@@ -614,15 +614,22 @@ defmodule Kernel do
defmacro iolist_to_binary(item)
@doc """
- Returns `true` if `term` is an atom; otherwise returns `false`.
+ Returns true if the local node is alive; that is,
+ if the node can be part of a distributed system.
+ """
+ @spec is_alive, do: boolean
+ defmacro is_alive
+
+ @doc """
+ Returns true if `term` is an atom; otherwise returns false.
Allowed in guard tests.
"""
@spec is_atom(term), do: boolean
defmacro is_atom(term)
@doc """
- Returns `true` if `term` is a binary; otherwise returns `false`.
+ Returns true if `term` is a binary; otherwise returns false.
A binary always contains a complete number of bytes.
@@ -632,98 +639,98 @@ defmodule Kernel do
defmacro is_binary(term)
@doc """
- Returns `true` if `term` is a bitstring (including a binary); otherwise returns `false`.
+ Returns true if `term` is a bitstring (including a binary); otherwise returns false.
Allowed in guard tests.
"""
@spec is_bitstring(term), do: boolean
defmacro is_bitstring(term)
@doc """
- Returns `true` if `term` is either the atom `true` or the atom `false` (i.e. a boolean);
- otherwise returns `false`.
+ Returns true if `term` is either the atom `true` or the atom `false` (i.e. a boolean);
+ otherwise returns false.
Allowed in guard tests.
"""
@spec is_boolean(term), do: boolean
defmacro is_boolean(term)
@doc """
- Returns `true` if `term` is a floating point number; otherwise returns `false`.
+ Returns true if `term` is a floating point number; otherwise returns false.
Allowed in guard tests.
"""
@spec is_float(term), do: boolean
defmacro is_float(term)
@doc """
- Returns `true` if `term` is a function; otherwise returns `false`.
+ Returns true if `term` is a function; otherwise returns false.
Allowed in guard tests.
"""
@spec is_function(term), do: boolean
defmacro is_function(term)
@doc """
- Returns `true` if `term` is a function that can be applied with `arity` number of arguments;
- otherwise returns `false`.
+ Returns true if `term` is a function that can be applied with `arity` number of arguments;
+ otherwise returns false.
Allowed in guard tests.
"""
@spec is_function(term, non_neg_integer), do: boolean
defmacro is_function(term, arity)
@doc """
- Returns `true` if `term` is an integer; otherwise returns `false`.
+ Returns true if `term` is an integer; otherwise returns false.
Allowed in guard tests.
"""
@spec is_integer(term), do: boolean
defmacro is_integer(term)
@doc """
- Returns `true` if `term` is a list with zero or more elements; otherwise returns `false`.
+ Returns true if `term` is a list with zero or more elements; otherwise returns false.
Allowed in guard tests.
"""
@spec is_list(term), do: boolean
defmacro is_list(term)
@doc """
- Returns `true` if `term` is either an integer or a floating point number;
- otherwise returns `false`.
+ Returns true if `term` is either an integer or a floating point number;
+ otherwise returns false.
Allowed in guard tests.
"""
@spec is_number(term), do: boolean
defmacro is_number(term)
@doc """
- Returns `true` if `term` is a pid (process identifier); otherwise returns `false`.
+ Returns true if `term` is a pid (process identifier); otherwise returns false.
Allowed in guard tests.
"""
@spec is_pid(term), do: boolean
defmacro is_pid(term)
@doc """
- Returns `true` if `term` is a port identifier; otherwise returns `false`.
+ Returns true if `term` is a port identifier; otherwise returns false.
Allowed in guard tests.
"""
@spec is_port(term), do: boolean
defmacro is_port(term)
@doc """
- Returns `true` if `term` is a reference; otherwise returns `false`.
+ Returns true if `term` is a reference; otherwise returns false.
Allowed in guard tests.
"""
@spec is_reference(term), do: boolean
defmacro is_reference(term)
@doc """
- Returns `true` if `term` is a tuple; otherwise returns `false`.
+ Returns true if `term` is a tuple; otherwise returns false.
Allowed in guard tests.
"""
@@ -220,6 +220,7 @@ defmodule Kernel.Typespec do
end
defp _defspec(type, caller, {name, line, args},[{:do,return}]) do
+ if is_atom(args), do: args = []
spec = { :type, line, :fun, fn_args(line, args, return, [], caller) }
code = Macro.escape { {type, { name, length(args) }}, [spec] }
table = spec_table_for(caller.module)
@@ -276,6 +276,7 @@ in_erlang_functions() ->
{ integer_to_list, 2 },
{ iolist_size, 1 },
{ iolist_to_binary, 1 },
+ { is_alive, 0 },
{ is_atom, 1 },
{ is_binary, 1 },
{ is_bitstring, 1 },

0 comments on commit 6c87df4

Please sign in to comment.