7

In the normal Mathematica language, where no built-in symbols are redefined and no evil things happen, is it a valid assumptions, that no function symbol (Plot, Print, Attributes) is also an option name (like PlotRange, ColorSpace, ImageSize). Furthermore, is it save to assume that symbols carrying an OwnValue ($MaxNumber, Pi, $Failed) are in neither of the other two groups?

To say it straight out: Does someone find a function, which is used as an option too?

m_goldberg
  • 107,779
  • 16
  • 103
  • 257
halirutan
  • 112,764
  • 7
  • 263
  • 474

2 Answers2

5

This question can be answered programmatically, at least to some extent. If we restrict ourselves to System` context only, then:

names = Names["System`*"];

optnames = 
  Quiet@Union@
     Cases[
       ToExpression[
          #, 
          StandardForm, 
          Function[name, Options[Unevaluated[name]], HoldAll]
       ] & /@  names, 
       (name_Symbol -> _) :> Hold[name], 
       Infinity];

symbols = 
    ToExpression[
        #, 
        StandardForm, 
        Function[name, 
           If[SyntaxInformation[Unevaluated@name] =!= {}, Hold@name, {}], 
           HoldAll]
        ] & /@ names;

Intersection[optnames,symbols]

(*  {Hold[Eliminate],Hold[NotebookFileName],Hold[Sort],Hold[TimeZone],Hold[Tooltip]} *)

where I assumed that a function is a symbol with a non-trivial value of SyntaxInformation. This is likely not the best criteria, but I think it is good enough, given that many system functions have their internal ...Values not reflected by the ...Values top-level functions.

My understanding has been that such symbols are rare and the parctice to have a symbol as both a function and a name of the option is generally discouraged. But such symbols do exist, and I have no doubts that there are many more instances than those found here, both because the criteria I used here may be too strict (for example, uses of symbols lile PlotRange as a function aren't documented and don't have non-trivial SyntaxInformation attached to them), and so I may have missed some, and also because they may exist in other contexts not considered here.

Your second question could be answered in a similar fashion: here are the symbols which have values (but not necessarily top-level OwnValues):

ownsymbols = 
   Cases[ 
      ToExpression[#, StandardForm, Hold] & /@ names, 
      Hold[s_] /; Hold[s] =!= Hold[Evaluate[s]]
   ];

we can now see if there is any overlap with the other two groups:

Intersection[ownsymbols,symbols]

(* {Hold[NotebookInformation]} *)

Intersection[ownsymbols,optnames]

(* {} *)

so, some symbols having a value apparently may be functions (although probably the dominant set of such use cases would be aliases, like in the case of NotebookInformation), while, at least among the System` functions, symbols standing for option names appear to not have values. We can probably expect this last conclusion to be true in general, since Options isn't HoldAll, and therefore the option names having (Own)values don't make much sense since they will evaluate to their values before being seen by Options and other option-related functions.

Finally, a number of functions which are implemented using the auto-loading mechanism, initiallu have OwnValues attached to their symbols, which then later get removed and replaced by DownValues and / or SubValues, once the function has been loaded. They never have both at the same time though.

Leonid Shifrin
  • 114,335
  • 15
  • 329
  • 420
  • Thanks Leonid. It's what I would have guessed. I think I will not care about the exceptions. I'm currently thinking about how to provide a smart completion. One part is to provide a nice way of inserting options when the parent AST-node is a function. Another part is that the smart completion add brackets when the symbol is known to be a function while only providing a normal expansion for things like $Failed. – halirutan Apr 07 '13 at 17:23
  • @halirutan I did guess the origin of your question :) – Leonid Shifrin Apr 07 '13 at 19:05
  • Funny,It's seem I crash your answer. :) – yode Dec 13 '16 at 11:30
  • @yode Your answer seems to give an alternative way to compute all symbols used as options. I don't have the time now to compare its result to mine, it could very well be that your method is more precise. But in the above post, I was concerned not just with options, but with symbols that are at the same time used for normal functions, as well as for options. – Leonid Shifrin Dec 13 '16 at 12:01
  • @LeonidShifrin Have you seen this? :) – yode Dec 16 '16 at 19:47
  • @yode No, I have not. But I don't know a robust question to that answer, that would be better than the one suggested there. – Leonid Shifrin Dec 16 '16 at 20:40
  • @LeonidShifrin what do you know about the autoload mechanism? This question involves the autoload functionality, so maybe you can provide a better answer than the pieces I've cobbled together. – b3m2a1 Dec 20 '16 at 20:28
  • @MB1965 There are at least 2 different routes for autoloads, used by the system. One is used by the kernel and is based on System`Dump`Autoload. The other one is used by the paclets / paclet manager, and is based on Package`ActivateLoad, as explored in the answer you linked. I don't have the time at the moment for a longer answer, but the idea behind the autoloading mechanism is rather straightforward in both cases - you create an OwnValue for the symbol that would load its definition, along with possible other related ones, upon the first call, prior to returning it. – Leonid Shifrin Dec 20 '16 at 21:07
1

Maybe this is unnecessary think,but I have thought it many times,too.Of course,I feel confusion about the J.M.'s comment.(Mr. J.M. is wonderful man who always break up my concept that have shape long time. :)).So I sure some built-in function is classified as option by WR.In an certain time,you can get this class of function by:

EntityClassList["WolframLanguageSymbol"]

But I cannot reproduce it now(I'm in version 11.0.1),I don't sure the low version MMA can reproduce it or not.There is two screenshot I keep:

  • First

http://o8aucf9ny.bkt.clouddn.com/2016-12-13-18-47-26.png

As we can see,there are $757$ function is classified as option names.After some thinking,I think this method can get all of option names:

Select[ToExpression[
  DeleteCases[
   CanonicalName[
    Complement[EntityList["WolframLanguageSymbol"], 
     EntityList[
      EntityClass["WolframLanguageSymbol", 
       "Autoevaluating"]]]], _?(StringStartsQ["$"])]], 
 SyntaxInformation[#] == {} &]

{Above,AccuracyGoal,ActiveStyle,AdjustmentBoxOptions,After,Algebraics,Alignment,AlignmentPoint,All,AllowedDimensions,AllowGroupClose,AllowInlineCells,AllowLooseGrammar,AllowReverseGroupClose,AlternateImage,AlternativeHypothesis,AltitudeMethod,AmbiguityFunction,AnchoredSearch,AnimationDirection,AnimationRate,AnimationRepetitions,AnimationRunning,AnimationRunTime,AnimationTimeIndex,Anonymous,Antialiasing,Appearance,AppearanceElements,...}

It's not $757$(Actually the number is $909$),but it's very colsely.

yode
  • 26,686
  • 4
  • 62
  • 167