19,858 reputation
14387
bio website
location
age
visits member for 2 years, 11 months
seen 2 hours ago

Frequently Asked Questions

WReach? Is that connected to WRI somehow?

The "WR" in my name has nothing to do with the company that develops Mathematica. It is just a coincidence.

Why do you start all your global variable names with $?

I use dollar signs for ad hoc global variables because I have been bitten too many times by accidentally assigning an own-value to a symbol that I happen to use, for example, in a symbolic equation. So I am in the habit of writing $x instead of x. I stick to that convention even for longer symbols like $initialUrl. Just like the regular symbol convention, Mathematica's predefined global symbols all start with a capital letter after the $. My ad hoc symbols always start with a lower case letter, so there is no conflict.

Why do you put semicolons and commas at the beginning of the line instead of at the end like a normal person?

I don't think of it that way. Rather, I switch from horizontal to vertical layout when a single expression is too long to fit on one line. This has the interesting side-effect of making the important delimiters stand out and line up. I first ran into this practice in the SQL community. SQL "programs" have the unpleasant property that they must be written as a single statement -- even if that statement is a hundred lines long (or more!). Sometimes Mathematica expressions share that property.


Dec
10
comment Error when implementing StartProcess[] in loops (Do, While, Table)
The problem with swapped stream names has been fixed in version 10.0.2.
Dec
8
comment Converting hierarchies of rules to associations
To see this all in action, constrast foo[2, foo[1], 3] /. e:foo[x__] /; (Print[e];True) :> fff[x] to Replace[foo[2, foo[1], 3], e:foo[x__] /; (Print[e]; True) :> fff[x], {0, Infinity}]
Dec
8
comment Converting hierarchies of rules to associations
We know that matching works from the outermost level inward from the documentation statement that after a match no further rules are tried on that part, or on any of its subparts. Example 1 matches foo heads only. As they have no subparts to skip, the inner foo is visited and replaced. Example 2 matches foo[x__] which does have subparts that are skipped, and we can see the inner foo subpart is left unchanged. Examples 3 and 4 give the same results as examples 1 and 2 respectively. Sow/reap tells us nothing here since the values are all being sown before replacement occurs.
Dec
7
comment Unexpected result from StringReplace
The Details section of StringExpression explicitly, if cryptically, states that Except can be used to match either a single character or a string position. It also implicitly suggests that the only valid arguments are those patterns listed within the sections detailing classes of characters or positions in strings. Experimentation supports this interpretation. All of this requires a pretty close reading -- I would prefer more direct statements of these points within the documentation.
Dec
4
comment Dataset Query with condition on two subsequent rows
+1 You could also replace 7 with SelectFirst[Length@# >= 2 &] to address it structurally.
Dec
4
comment Select last occurence of key in dataset
@alancalvitti To resolve name collisions, I usually choose one of two strategies. If the number of uses of a colliding name is small, then I just use the fully qualified name. If there are a large number of references, then I define a short alias instead. While I can think a few instances where I have had to deal with a function name collision, I can't think of a case where I have had to deal with colliding global variables. Global variable names tend to be very specialized.
Nov
24
comment Injecting list of controls into manipulate
V10.0.2? :( I'm afraid I am not aware of a reliable fix. See the chat for another variation of your answer (but it is also flakey on V10).
Nov
24
comment Injecting list of controls into manipulate
+1 This works well on V9... but for me under V10.0.1 on Win7 64 bit it issues many error messages, apparently due to this bug.
Nov
24
comment How to build this grid with less code?
@MikeHoneychurch I abandoned my first solution because your post got there first. Now I see that my second solution is much like your edit. Oh well, them's the MSE breaks. :)
Nov
24
comment TreePlot remove an arrow
For rotating the tree, see Can TreeForm be displayed “sideways”?.
Nov
23
comment TreePlot remove an arrow
You have some extra braces in your replacement rules. Try this instead: {"p2a" | "p2b" | "p2c" -> "p2", "p3a" | "p3b" -> "p3"}
Nov
23
comment TreePlot remove an arrow
In the desired plot mock-up, the upper "p2" node is terminal while the lower "p2" node has an edge to "Sp21". There is not enough information from the edge list alone to infer this output. In order to produce the output automatically, we will either need access to the required additional information, or we must adjust the desired output so that the edge between "p2" and "Sp21` is repeated in both locations.
Nov
21
comment Camel hump string split
@alancalvitti See the new section concerning digit characters. I'm afraid that the Mathematica symbolic string pattern syntax does not yet fully support all of the functionality in PCRE regular expressions. I agree that they are so cryptic as to be "write only".
Nov
20
comment Camel hump string split
Alas, the two dots are not quite enough for the abbreviations. Notice how "AASTriangle" is not split up. It doesn't detract from a good answer, though.
Nov
19
comment Installing LinkSnooper on Windows
@FredSimons You say that you are on 32-bit Windows, but the LinkSnooper command you show references the 64-bit Java directory Windows-x86-64. Does it work if you change that to the 32-bit directory Windows instead?
Nov
17
comment String pattern defined by number of characters
I have added the section about recursive patterns.
Nov
17
comment String pattern defined by number of characters
@Aisamu There is no direct equivalent in Mathematica's native string pattern syntax. It is probably possible to achieve a similar result using StringCases[s, $patt] where $patt is self-referential. The following pattern comes close, but it fails to preserve proper backtracking: $patt = "b" | "c" | ("a" ~~ (s___ /; StringMatchQ[s, $patt]) ~~ "d"). Even if it worked, it entails an evaluator callback from the PCRE engine for every potential match -- probably more trouble than it is worth.
Nov
11
comment Pattern matching: Times[a_] vs Times[a__]
@ShutaoTang The Internal package is undocumented, and we use its features at our own risk since it carries no guarantees and could be withdrawn at any time. As the name implies, it is used internally by the Mathematica implementation. There is no official documentation on this package, but this forum is rapidly becoming the repository for the collective findings of the community -- whether about Internal or many of the other undocumented features. And even the documented ones too :)
Nov
11
comment Select last occurence of key in dataset
@Lea As to the dollar sign in $dataset, see the second FAQ in my profile.
Nov
8
comment Using 0 to create new columns in a list with Part
@AlexeyPopkov Okay, okay... A New Kind of Map/Apply = A New Kind of Maple ;D