Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

In version 9, with a newly started Mathematica session, try the following code:

plotAttributes = Attributes[Plot]

Plot[Sin[x], {x, 0, 1}];

Attributes[Plot]

% == plotAttributes

{Protected, ReadProtected}

{HoldAll, Protected, ReadProtected}

False

Is there any explanation why Plot doesn't have HoldAll as one of its attributes when a fresh Mathematica session is started, and acquires this attribute only after I call Plot once?

share|improve this question
add comment

1 Answer

up vote 12 down vote accepted

It is because, in version 9, the implementation of Plot is loaded from a dump file on its first usage, rather than loading when the kernel starts. One can see this by clearing the ReadProtected attribute:

ClearAttributes[Plot, ReadProtected]
Information[Plot]

(* -> Plot := System`Dump`AutoLoad[
        Hold[Plot], Hold[syms], Visualization`Proto`
       ] /; System`Dump`TestLoad *)

where syms is a large sequence of symbols (including Plot itself) whose usage will cause the dump file containing the Plot implementation to be loaded, if it has not been already. The file in question is (as Visualization`Proto` suggests):

FileNameJoin[{
 $InstallationDirectory, "SystemFiles", "Kernel", "SystemResources", $SystemID,
 "Visualization", "Proto.mx"
}]

Since the definition of Plot needed for the autoloading functionality constitutes a single ownvalue, it does not matter whether Attributes[Plot] contains HoldAll or not, because there are no downvalues defined at this stage. After the full implementation is loaded, the attribute becomes necessary and therefore is set, but because heads are always evaluated before bodies, HoldAll is effectively present from the start. We can observe the same behavior in this example:

f := Function[Null, Null, HoldAll];
f@Print["evaluation leak!"] (* does not print anything *)
share|improve this answer
1  
@Brett if not to make the kernel start up more quickly, could you perhaps add an answer outlining the reason for this change, assuming it's not too complicated to admit a brief explanation? –  Oleksandr R. Jan 4 '13 at 15:19
    
@Brett and Oleksandr thanks for the explanation. This comes up whenever we try to explain why tables of functions have to be plotted with Plot[Evaluate[...]...], and now the explanation has just become a little more complicated. At least there is one. –  Jens Jan 4 '13 at 17:00
    
@OleksandrR. It's just an implementation detail. –  Brett Champion Jan 4 '13 at 17:31
3  
@BrettChampion Except that I can't tell people: "look at the attributes of Plot before using it, to understand that it will hold its arguments and therefore won't recognize a Table of functions as separate functions". I now have to say: "Use Evaluate, trust me. You can find the explanation after you make the plot." –  Jens Jan 4 '13 at 18:23
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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