I'm trying out a square
and a cube
function. Why does square
work while cube
blows up?
square = &1 * &1 square.(5)
Works fine while
cube = &1 * &1 * &1 cube.(5)
Throws
** (ArithmeticError) bad argument in arithmetic expression :erlang.*(#Function<erl_eval.6.82930912>, 5) erl_eval.erl:572: :erl_eval.do_apply/6 src/elixir.erl:133: :elixir.eval_forms/3 /private/tmp/elixir-OVih/elixir-0.8.2/lib/iex/lib/iex/server.ex:19: IEx.Server.do_loop/1
Erratic/inconsistent behavior is behavior that is unpredictable, or may be considered irregular or illogical for the situation, or not keeping with the standards of behavior for a given set of circumstances.
Displaying or marked by a lack of consistency, especially: a. Not regular or predictable; erratic: inconsistent behavior.
Inconsistent traits were defined as ones that differed in evaluation from the overall evaluation of the target (e.g., an undesirable trait for a liked target). Such inconsistencies were expressed by using narrow traits, that is, ones that refer to a more circumscribed set of behaviors (Hampson, John, & Goldberg, 1986).
Since 0.10.3 you need to put the partial application between parentheses preceded by the &
operator.
You won't have any trouble with this version:
iex> square = &(&1 * &1) iex> square.(5) 25 iex> cube = &(&1 * &1 * &1) iex> cube.(5) 125
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With