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.

For some functions in Mathematica it is important to use RuleDelayed. One prominent example is the EvaluationMonitor for functions like NMinimize

NMinimize[x^4 - 3 x^2 - x, x, EvaluationMonitor :> Print[x]]

Here it is inevitable to use RuleDelayed because otherwise Print[x] would be evaluated too soon.

Question: Is there a comprehensive list of options which require RuleDelayed?

Btw, the reason why I need this list is to support this correctly in the IntelliJ Plugin for Mathematica:

enter image description here

share|improve this question
    
Oh, yes. It's the complement of the comprehensive list of all options with the comprehensive subset that requires a non-delayed rule. I'm still trying to find any of those too. –  belisarius May 23 '13 at 4:21
1  
maybe there is an enourmous corpus of mathematica code somewhere (like that wolfram website i've seen), where you could extract these kinds of things semi-exhaustively? Just throwing that out as an idea. –  amr May 23 '13 at 5:23
1  
I have a feeling there are also those options that can work with either of Rule[] or RuleDelayed[], depending on the circumstances. –  J. M. May 23 '13 at 5:25
    
@J.M. You can always trick Mathematica like here NMinimize[x^4 - 3 x^2 - x, x, EvaluationMonitor -> Hold[Print[x]]] but I think especially in the monitor options the user almost always wants :>. In many other cases it probably doesn't hurt to use :> in preference to ->. –  halirutan May 23 '13 at 5:41
1  
I tend to think that evaluation control is the user's responsibility. That said, it's a noble goal to offer hints where appropriate. I would just add that it's probably best for the resulting list to be subject to some human discretion before inclusion in the final product since there are quite a few scenarios where the "usual" or default choice is not applicable. –  Oleksandr R. May 23 '13 at 13:49
show 4 more comments

3 Answers

One possible way to get some candidates is to test all Options of all System` symbols

extractRuleDelayedOptions[symbol_String] := 
 With[{opts = Options @@ MakeExpression[symbol]},
  Cases[opts, (p_ :> _) :> p]
];

Union@Flatten[extractRuleDelayedOptions /@ Names["System`*"]]

This produces the following list

{"Compiler", "CompilerWarnings", "Device", "Graphics", "Obsolete", 
"Packing", "Spelling", "Symbolics", "UserName", 
BoxForm`ActionFunction, Assumptions, BackgroundAppearance, 
ButtonFunction, ByteOrdering, CachedValue, CellDynamicExpression, 
CharacterEncoding, CompilationTarget, CoordinatesToolOptions, 
CounterFunction, DefaultFont, Deinitialization, DisplayFunction, 
DistributedContexts, DOSTextFormat, DynamicModuleParent, 
DynamicModuleValues, FormatType, FrontEndDynamicExpression, 
Initialization, NotebookDynamicExpression, NumberMarks, Path, 
PerformanceGoal, TextStyle, TimeZone, UnsavedVariables, 
UntrackedVariables}

which is not satisfactory mainly because EvaluationMonitor and StepMonitor which require RuleDelayed are not included. Who knows what further options we missed.

The problem with this approach is as follows: It doesn't tell you what Options require :> when they are used inside a function call. Here :> acts to make the standard values work.

Example: Path for instance should always be just a string and not require :>. The reason why in the default setting :> was utilized is because the default settings is

Path :> $Path

Therefore, the value of $Path is not evaluated until the rule is used. If -> would have been used here, the default option would have the value of $Path at the moment of definition, and not at the moment of its usage.

share|improve this answer
    
Initialization and TrackedSymbols came to my mind immediately. The former is in your list, the latter isn't. –  Sjoerd C. de Vries May 23 '13 at 5:37
    
@SjoerdC.deVries Yes, I should have thought about this too since I used it quite often lately. –  halirutan May 23 '13 at 5:43
    
Monitor-like options (such as NMinimize) are warped by Rule (not RuleDelayed) and set to None as default. When monitoring something, we'll have to type RuleDelayed. In such cases, the auto-completion of Mathematica 's front-end is wrong.(v9.0.0 in Windows7) –  luyuwuli May 23 '13 at 9:54
    
I would like to do this: funcs = ToExpression /@ Flatten@(Names["System" <> # <> "*"] & /@ CharacterRange["A", "Z"]);Select[funcs, MemberQ[Options[#][[;; , 1]], Monitor | EvaluationMonitor | StepMonitor] &]` . But I only pick up the monitor one, possibly missing other RuleDelayed cases. –  luyuwuli May 23 '13 at 9:58
    
I also noticed that RuleDelayed is added when using the auto-completion of CompilationTarget in Compile. Although both of Rule and RuleDelayed will work, the default should be Rule I think. Is this a small bug? –  luyuwuli May 23 '13 at 10:05
add comment

According to @amr 's suggestion, I scanned every .nb files under the Mathematica\9.0\Documentation\English\ directory - which is fairly fast even on my outdated PC. This is what I got:

wsc = (WhitespaceCharacter ...);
prePtn = "RowBox[" ~~ wsc ~~ "{" ~~ wsc ~~ "\"";
inPtn = "\"" ~~ wsc ~~ "," ~~ wsc ~~ "\"";

rdOptExtractor = Function[testfile,
   Module[{fileStr},
    fileStr = Import[testfile, "String"];
    Function[ruleType,
        StringCases[fileStr, 
         Shortest[
           prePtn ~~ opt : Except[WhitespaceCharacter] .. ~~ inPtn ~~ 
            ruleOpr : ruleType ~~ "\""] :> opt]
        ] /@ {":>", "\[RuleDelayed]", "\\[RuleDelayed]"} // Flatten // Union
    ] ];

filelist = 
  FileNames["*.nb",{"D:\\Wolfram Research\\Mathematica\\9.0\\Documentation\\English\\"}, ∞];

Length[filelist]

10416

AbsoluteTiming[res = Union[Flatten[rdOptExtractor /@ filelist]];]

{504.27584,Null}

Cases[
 Union[Quiet[Check[
      ToExpression[#],
      StringReplace[#, "\\\"\\<" ~~ opt : __ ~~ "\\>\\\"" :> opt]
      ] & /@ res]],
 a_ /; MemberQ[{String, Symbol}, Head[a]]]
{"-", "+", "10!", "4!", "7!", "a", "b", "back", "c", "dialog1", 
"Drag", "\\<\\\"E1\\\"\\>", "\\<\\\"E2\\\"\\>", "E2", 
"\\<\\\"E3\\\"\\>", "end", "EvaluationMonitor", "Event", 
"EventAction", "halfway", "In", "Invariants", 
"\\<\\\"listHead\\\"\\>", "listHead", "MethodMonitor", 
"MouseClicked", "MouseDown", "MouseDragged", "MouseUp", "Off", "On", 
"one", "\\<\\\"opt2\\\"\\>", "Out", "Pinch", "PositionVariables", 
"print1", "Reset", "ReturnKeyDown", "start", "Subsubtitle", 
"Subtitle", "Title", "two", "WindowClose", Assumptions, b, 
bookmarkName, ButtonData, ButtonFunction, CellEpilog, CellProlog, 
CharacterEncoding, DateFunction, Deinitialization, DialogProlog, 
DialogSymbols, DisplayFunction, DistributedContexts, e, Epilog, 
EvaluationMonitor, EventAction, FontFamily, FontSize, FormatType, g1, 
g2, g3, g4, GeneratedParameters, Gradient, Initialization, 
InterpretationFunction, List, NotebookDynamicExpression, NumberMarks, 
ParameterVariables, PassEventsUp, Path, PerformanceGoal, PlotLabel, 
Polygon, Prolog, RegionFunction, StepMonitor, TextStyle, TimeZone, 
Tooltip, TrackedSymbols, UnsavedVariables, WordBoundary, x, y}

Of cause some elements in the above list are irrelevant, but unfortunately I can't figure out a good way to filter them out.

Remaining work:

I didn't scan .m files. Also there are still many corpus under Mathematica\9.0\AddOns\ and Mathematica\9.0\SystemFiles\, which are worth looking-into.

Hope this helps.

share|improve this answer
    
+1 This is what I tried first, although I just used fgrep and searched only in the ReferencePages sub-folder. Like you I wasn't able to figure out a good criterion for selecting the relevant ones. –  halirutan May 23 '13 at 9:56
    
@halirutan Thanks! btw if reading the file as Notebook expressions I think it would be possible/easier to get inheritance relationships between options and their sub-options. It's so sad pattern matching is much slower in that case.. –  Silvia May 23 '13 at 10:01
add comment
up vote 2 down vote accepted

Let us start a community wiki answer where we collect possible :>-options because I think this question got enough attention by many of the experienced users to tell there isn't an easy way to get such a list automatically.

The reason for that is that the choice of the rule type is not fixed. You can almost always use :> instead of -> and as I have shown in the comments even the other way around is possible

NMinimize[x^4 - 3 x^2 - x, x, EvaluationMonitor -> Hold[Print[x]]]

The question here is: If options would be inserted automatically like in the Mathematica front end, which ones should utilize :>?. Please append more options below

{
 EvaluationMonitor, EventAction, Initialization, 
 InterpretationFunction, NotebookDynamicExpression, 
 StepMonitor, TrackedSymbols, UnsavedVariables, UntrackedVariables,

 CellDynamicExpression,

 (*GestureHandler: *)
 "Drag", "Pinch",

 (*EventHandler: *)
 PassEventsUp, "MouseClicked", "MouseDown", "MouseDragged", "MouseMoved", "MouseUp",
 "KeyDown", "ReturnKeyDown", "EscapeKeyDown", "LeftArrowKeyDown", "RightArrowKeyDown",
 "UpArrowKeyDown", "DownArrowKeyDown", "MenuCommand", "WindowClose",

 CellEpilog, CellProlog, DateFunction(*?*), Deinitialization, DialogProlog, DialogSymbols,
 Gradient(*evaluates only with the specific numerical values of variables that are needed*)
}
share|improve this answer
    
For some reason, I seem to recall 9.0.0 inserting a lot more :> than -> even for options that normally don't need them (e.g. PlotRange) –  rm -rf May 27 '13 at 3:36
    
@rm-rf Not under OSX. I have an old installation here and this doesn't do it. –  halirutan May 27 '13 at 3:41
    
Also CellDynamicExpression. (but not FrontEndDynamicExpression?) And maybe all events under EventHandler. –  Silvia May 27 '13 at 17:36
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.