0
$\begingroup$

I apologize beforehand for the muddleheadedness of this question. It reflects the fact that I'm trying to interpret outward "behaviors" of Mathematica expressions without having any understanding of the scheme underlying these behaviors.


Among symbols that are "defined" (whatever this means), those that have head Function seem to be fundamentally different from most others in that they "respond" to a trailing square-bracket-delimited subexpression:

{Function[{}, 5], Function[{}, 5][]}
{Function[{}, 5], 5}
{3, 3[]}
{3, 3[]}

(I'm using the verb "respond" as the opposite of what happens when Mathematica's evaluation, as in the case of 3[], produces no visible change at all, not even a warning or error message.)

What is the difference in the ways that Mathematica evaluates Function[{}, 5][] and 3[] that accounts for the fact that the former returns something different from itself, but not the latter?

Is there a way to display a breakdown Mathematica's evaluation that clearly shows the basis of this difference?

One other head I know of that marks items that "respond" to a trailing [...] is Association (the "response" is either the value associated with the "key" in the [...], if such exists, or an item with head Missing). Are there any others?


Unfortunately, this question is muddled by this sort of thing:

ClearAll[foo];

{foo, foo[5]}

foo[5] = 4; {foo, foo[5]}

{foo, foo[7]}

Head[foo]
{foo, foo[5]}

{foo, 4}

{foo, foo[7]}

Symbol

IOW, under some circumstances, an item with head Symbol will "respond" to some trailing [...] expressions. Hmph...

$\endgroup$
  • 2
    $\begingroup$ In your place, I'd read Chapter 7 on evaluation process in David Wagner's book "Power programming in Mathematica" - available for free here on the site for download - this should clarify a lot of issues. The Function construct is special, and has a special evaluation semantics, which is why you see the difference. Also, read this. $\endgroup$ – Leonid Shifrin May 8 '15 at 13:17
  • $\begingroup$ You should also realize, that, say, Function[{}, 5][] is equivalent to 5&[], not 5[]. I don't claim very deep knowledge, but one of the lessons to learn from Leonid's link, is that a function is a bit different from a replacement rule that's created when you give a symbol a DownValue. I hope, however, that if I'm grossly inaccurate, the more knowledgeable folks will correct me here. $\endgroup$ – LLlAMnYP May 8 '15 at 13:34

Your Answer

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

Browse other questions tagged or ask your own question.