5
$\begingroup$

When a pure function accesses the first element of itself, 0 is output. What is the logic behind this, or is there any?

$\endgroup$
11
$\begingroup$

The FullForm of #0[[1]] & is

Function[Part[Slot[0], 1]]

So when this function is called with no arguments, I believe what happens is that Slot[0] does not evaluate, and then you take the first part of Slot, which is 0. Here it seems that Slot behaves as any other head.

$\endgroup$
  • 6
    $\begingroup$ No need to believe, you can check :) #0[[1]] &[] // Trace $\endgroup$ – Kuba Nov 16 '15 at 14:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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