6
$\begingroup$

enter image description here

In[1] and In[3] are identical but the output is different.

$\endgroup$
2
  • $\begingroup$ I note that after these steps, VariationalMethods has not been loaded according to $Packages, and the attributes of VariationalD is an empty list (in particular, doesn't contain Stub). It has no Down, Up, Sub or OwnValues. As far as I can tell, Messages is the only thing that has been changed. $\endgroup$ Aug 9, 2015 at 15:45
  • 1
    $\begingroup$ The symbol creation is being hooked somehow. In[1] is equivalent to Information["VariationalMethods`VariationalD"] (note the symbol given as a string), and not the same as In[2], which actually creates the symbol during parse. But I am not sure how this mechanism actually works. $\endgroup$ Aug 9, 2015 at 18:35

2 Answers 2

3
$\begingroup$

? name is a special input form with nonstandard parsing behavior, just like >>> as explained here.

When you write a line starting with ? the item following it is not a Symbol, contrary to appearances. Instead it is a String with implicit delimiters. This is not simply a matter of a hold attribute. For example HoldComplete[a^] is incomplete syntax and cannot be entered, yet:

?a^

Information::nomatch: No symbol matching a^ found. >>

Using the same method as for the linked question we can take a look at parsing itself:

parseString[s_String, prep : (True | False) : True] := 
  FrontEndExecute[FrontEnd`UndocumentedTestFEParserPacket[s, prep]]

parseString["?a^"]

parseString["HoldComplete[a^]"]
{BoxData[RowBox[{"?", "a^"}]], StandardForm}

{BoxData[RowBox[{"HoldComplete", "[", RowBox[{"a", "^"}], "]"}]], StandardForm}

Observe that in the first case "a^" remains an undivided String whereas in the section it is parsed into a RowBox.

We can look at the next step in evaluation by using MakeBoxes:

MakeExpression @ "?name"
HoldComplete[Information["name", LongForm -> False]]

Note that the first argument of Information is the String "name" and not the Symbol name.

So know you know that your ? name input form actually becomes:

 Information["VariationalMethods`VariationalD", LongForm -> False]

And indeed this behaves just the same. But why does this say "No symbol matching" in a fresh kernel while this does not?:

Information[VariationalMethods`VariationalD, LongForm -> False]

Consider the way that DeclarePackage works:

You can use DeclarePackage to tell Mathematica automatically to load a particular package when any of the symbols defined in it are used.

DeclarePackage["ErrorBarPlots`", "ErrorListPlot"]

The String "ErrorListPlot" does not count as the use of the Symbol ErrorListPlot as explained in the documentation for Stub:

  • Symbols with the Stub attribute are created by DeclarePackage.

  • A symbol is considered "used" if its name appears explicitly, not in the form of a string.

  • Names["nameform"] and Attributes["nameform"] do not constitute "uses" of a symbol.

Therefore the implicit string form of ?name does not constitute a use of name and the package is not loaded, resulting in the nomatch message.

$\endgroup$
8
  • $\begingroup$ Well, except that the usage message is actually from Usage.m and not VariationalMethods.m (check them; they are different). Also: Remove["test`*"]; DeclarePackage["test`", "sym"]; Print[{#, Attributes[#]}] & /@ Names["test`*"];. The symbol does exist in the symbol table after DeclarePackage (as it must, to have an attribute). $\endgroup$ Aug 10, 2015 at 18:10
  • $\begingroup$ Is this behaviour of ? documented anywhere? I can't find it, and it's really really counterintuitive… $\endgroup$ Aug 11, 2015 at 15:06
  • $\begingroup$ @Oleksandr Pardon me, but I'm feeling a bit obtuse and I don't understand the point you are making. Would you mind bluntly stating the significance of your observations? $\endgroup$
    – Mr.Wizard
    Aug 12, 2015 at 1:47
  • $\begingroup$ @Patrick I don't believe this is documented as such other than what I quoted here but the parsing difference follows from the nonstandard input when ? starts a "line." Which aspect do you find most counter-intuitive? $\endgroup$
    – Mr.Wizard
    Aug 12, 2015 at 1:49
  • 1
    $\begingroup$ To put it bluntly, then: while your observations are completely correct and accurate, they don't apply to this situation, because the package is not being autoloaded. Only the usage message is, and not even from the package itself, but from a different file (Usage.m). To assign attribute (Stub) does create the symbol, but VariationalMethods`VariationalD does not exist in the symbol table at all here. I don't know what the mechanism is (I did not go through the whole trace), but it doesn't seem to be the one you describe. $\endgroup$ Aug 12, 2015 at 10:42
2
$\begingroup$

I do not think this a bug, but more of a peculiarity of paclet manager. This sort of thing happens when a package isn't loaded and a function it defines is mentioned. This what I think happened.

At the time you evaluated In[1], VariationalD was an undefined symbol, because the VariationalMethods package wasn't loaded. Which is what the message you got told you.

Evaluating Information didn't load the package, but it triggered the packet manager to get the paclets it needs. So the next time you evaluated Information, you got what you expected.

$\endgroup$
4
  • $\begingroup$ Can you give more detail about this mechanism? Autoloaded definitions are usually dealt with by assigning the Stub attribute or by giving them some definition that loads the package when they are first referenced, which requires the symbol at least to exist. But here there is no pre-existing definition at all and the symbol does not exist in the symbol table. So how does the paclet manager hook the creation of this symbol to load the package? $\endgroup$ Aug 9, 2015 at 18:33
  • $\begingroup$ @OleksandrR. Stub causes the symbol not to be found too, but Attributes["symbolName"] will still show Stub. This appears to behave in a very similar way except Stub is not explicitly shown. $\endgroup$
    – Szabolcs
    Aug 9, 2015 at 20:26
  • $\begingroup$ @OleksandrR. I don't really have any insight in the mechanism. However, VariationalMethods is not an auto-loaded package. So not sure why you are bringing autoload into the discussion. $\endgroup$
    – m_goldberg
    Aug 9, 2015 at 21:06
  • $\begingroup$ @Szabolcs to have attributes, a symbol has to at least exist in the symbol table. VariationalMethods`VariationalD doesn't, although at least the FE seems to know enough to offer autocomplete/highlighting for it. @m_goldberg although the whole package is not autoloaded, at the very least the messages are. $\endgroup$ Aug 9, 2015 at 21:53

Your Answer

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

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