21,913 reputation
24698
bio website
location
age
visits member for 3 years
seen 9 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.


2d
comment Does RegularExpression support “(?R)”?
@2012rcampion Yes, good idea. I have updated my answer to give an example. I suppose this post has outgrown its original billing as just an extended comment... :)
Jan
27
comment How to filter a dataset using Select and a parameter
@GordonCoale Done.
Jan
22
comment Get the wrong result using the StringCase function and Shortest option
@Kuba Not the Mathematica docs, certainly. One needs to dig into the PCRE docs -- and it would probably help to put on the language-lawyer hat. :)
Jan
22
comment Unexpected pattern matching behaviour: PatternSequence vs. Optional
I reported this issue to WRI some years ago, but never received a diagnosis.
Jan
22
comment What is the correct way to use specific rule for specific pattern match when parsing an expression?
@Mr.Wizard I added Unexpected pattern matching behaviour: PatternSequence vs. Optional.
Jan
22
comment Can't comment strings with '*)' inside it
+1 Clever. It exploits the fact that Mathematica is unusual among languages in that it supports nested matchfix comments (unlike, say, C).
Jan
19
comment Select From List of Nested Associations
@alancalvitti Yes, one would be. But I added it for its explanatory value in this discussion, not to enforce a restriction (and the same for _String in the second argument). We could just as well have where_String, or simply where_ if that is preferable. The core solution is insensitive to that choice.
Jan
19
comment Possible bug involving Dataset/Query and RightComposition
@Mr.Wizard Done. I'm always reticent to accept my own answers.
Jan
19
comment Select From List of Nested Associations
I expanded the How It Works section to discuss the details of how MemberQ affects the query.
Jan
19
comment Select From List of Nested Associations
"That position" for MemberQ is the level that represents the list of links. MemberQ converts the each list into a boolean. I used // purely out of personal preference. You can write Query[...] @ association as in the question if you prefer.
Jan
19
comment How to display grids in separate cells?
If my answer reflects what you are trying to do, please change the title of your question to something more meaningful. For example: How to display grids in separate cells?
Jan
18
comment Define column types in a Dataset - Failure on append and Typesystem
See Dataset with no members for ways to create an empty yet typed dataset.
Jan
18
comment Define column types in a Dataset - Failure on append and Typesystem
Could you please make this a self-contained example by defining all of the symbols used (e.g. electrodeModule02 and volumeBounds). The type system uses heuristics heavily and its behaviour is very sensitive to the exact data. Also, please mention which version you are using -- the heuristics have changed radically between 10.0.0, 10.0.1 and 10.0.2.
Jan
17
comment Can Trace[] output during evaluation (and not only after)?
Function[Null, ...] specifies that the arguments to the function are anonymous and must be referenced using slot notation (#, #2, etc). This full-form expression is necessary to specify the HoldAllComplete attribute for the pure function.
Jan
17
comment Can Trace[] output during evaluation (and not only after)?
The documentation for TraceScan refers to the two functions as f and fp. It tells us that fp takes two arguments, namely the form before and after evaluation. We are interested in the "after" value, which is the second argument (#2). The documented statement that both arguments are wrapped in HoldForm is incorrect (only the first is wrapped). In our case, a notional call to fp would look something like fp[HoldForm[sum], 1234].
Jan
13
comment How to automatically make the maximum of each row in a table(grid) bold?
related: nicely print out a matrix in mathematica
Jan
11
comment Transform a table (list of associations) to a flat association
+1. For the second question... if we are given ds = Dataset @ as, then we can use ds[Merge[Identity]].
Jan
9
comment SQL-like computation on Dataset: Aggregate function
@GordonCoale Well spotted. Technically you are correct, but a bug in 10.0.1 causes the query to fail unless Key is explicitly present. The bug is fixed in 10.0.2. I left Key in place just in case. I'll add a note to that effect to the response.
Jan
8
comment Evaluate specific cells in Mathematica
+1. When I tried it in V10.0.2 (Win 7/64) it worked perfectly, evaluating all (and only) tagged cells. NotebookEvaluate is defined to return only the value from the last evaluation, so it is hard to see the failure from just the screenshot since none of the cells have visible side-effects. Does it fail if the evaluated cells contain Print expressions, or the InsertResults -> True option is included?
Jan
8
comment Evaluate specific cells in Mathematica
I can reproduce the problem in V9.0.1 on Win7/64. It evaluates all elements in the notebook, ignoring the EvaluationElements. If the NotebookEvaluate expression is in the target notebook, it loops indefinitely. In V10.0.2 it works properly, even from within the same notebook.