4
$\begingroup$

I am learning pattern matching. An example that confuse me is as follows.

Foo[x__?EvenQ] := x^2;
Foo[2, 4]

which is equal to Sequence[2,4]^2 which in turns equal to 65536.

What does it mean? Why is it 65536? I really don't understand what kind of algorithm is applied here.

$\endgroup$

1 Answer 1

8
$\begingroup$

Switching away from infix notation might make things more clear:

Sequence[2, 4]^2 === Power[Sequence[2, 4], 2] === Power[2, 4, 2]

According to the documentation of Power:

and so we have

Power[2, 4, 2] == 2^(4^2) == 65536
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.