using element
for example
in Guards:
run(X) when element(1, X) == 1 -> a;
run(_) -> b.
call test(1)
will not raise any error
in fact it’s is_tuple(X) andalso element(1, X) == 1
?
but have a look this .S file
run(X) when element(1, X) == 1 -> a;
run(X) -> element(1, X).
{function, run, 1, 2}.
{label,1}.
{line,[{location,"test.erl",5}]}.
{func_info,{atom,test},{atom,run},1}.
{label,2}.
{bif,element,{f,3},[{integer,1},{x,0}],{x,1}}.
{test,is_eq,{f,3},[{x,1},{integer,1}]}.
{move,{atom,a},{x,0}}.
return.
{label,3}.
{line,[{location,"test.erl",6}]}.
{bif,element,{f,0},[{integer,1},{x,0}],{x,0}}.
return.
both element
call {bif,element,...}
, {f,0}
raise error?
in Expr
element(1, 1).
obvious, raise error
if it’s strange that it (maybe) has a hidden type check
in guard
as far as I know it’s undocumented
and I will write code like these in my work
run(Tuple) when is_tuple(Tuple), element(1, Tuple) > 0 -> ...