Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inconsistent Functions behavior

Tags:

elixir

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 
like image 239
Benjamin Tan Wei Hao Avatar asked Jun 08 '13 07:06

Benjamin Tan Wei Hao


People also ask

What are inconsistent behaviors?

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.

What does inconsistent mean in psychology?

Displaying or marked by a lack of consistency, especially: a. Not regular or predictable; erratic: inconsistent behavior.

Can traits be inconsistent?

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).


1 Answers

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 
like image 90
irio Avatar answered Oct 29 '22 20:10

irio