64,082 reputation
6189283
bio website mathprogramming-intro.org
location St. Petersburg, Russia
age 38
visits member for 3 years, 2 months
seen 37 mins ago

Ok, an obligatory note: opinions expressed here are mine and not those of my employer.


Mar
15
awarded  Nice Answer
Mar
15
comment Why do functions defined with SetDelayed and Function behave differently in callbacks?
Some more information on strong types in Mathematica is in this discussion. An interesting discussion of differences between Mathematica and traditional languages (the high-level view on them) is inside this answer.
Mar
15
comment Why do functions defined with SetDelayed and Function behave differently in callbacks?
@ibeatty [2/2] ... pass f[1,2] as a function. There may be other similar constructs. I seem to remember some discussions about checks for functions, but I can't find them now. The other way would be to use an inert wrapper, e.g. Fun[...], and then place inside this wrapper the function. So then, your definition would look like g[Fun[ff_],y_]:=..., and the caller is responsible for wrapping a function in Fun when passing arguments to g. This, of course, does not prevent the caller from passing a wrong thing inside Fun, but at least it will probably rule out accidental mistakes.
Mar
15
comment Why do functions defined with SetDelayed and Function behave differently in callbacks?
@ibeatty [1/2] I am not aware of a fully robust way to differentiate between functions and other things in Mathematica. Partly this is because for the core evaluator, what we consider functions are no different from other expressions. In other languages, calling a function which evaluator knows nothing about, is an error. In Mathematica, it is not, and the call (expression) is simply returned back. One way I was using before was to use the pattern _Symbol | _Function, but this isn't robust either. For example, people may define SubValues of the form f[a_,b_][x_,y_]:=a+b+x+y, and then ...
Mar
14
comment Why do functions defined with SetDelayed and Function behave differently in callbacks?
@Pickett Re: retracted close vote - thanks. Re: answer - done.
Mar
14
answered Why do functions defined with SetDelayed and Function behave differently in callbacks?
Mar
14
comment Why do functions defined with SetDelayed and Function behave differently in callbacks?
Why the close votes? This is a legitimate question, even if the answer is rather simple.
Mar
14
comment Why do functions defined with SetDelayed and Function behave differently in callbacks?
Well, you get what you ordered. By using the pattern _Function in your first argument in g, you only allow the first argument to be a Function - otherwise the definitiion does not apply. Use g[ff_, y_]:=..., and you get what you want in both cases.
Mar
13
comment What is the “Origin” rule for in a Dataset?
I think, part of the problem here is that Dataset, being a new functionality, should have the most general design to match the generality of the language. Later, it will likely grow to have more specialized implementations / backends. The other approach would be to start with more narrow / specialized functionality, but then there is a higher risk of the initial design to be too narrow, and that would result in deprecation / backwards incompatibility - which is what the developers / designers are trying to avoid, given that Dataset is a core component.
Mar
13
comment What is the “Origin” rule for in a Dataset?
It is for internal use. It shows the query that produced this given Dataset. Is there any reason you are interested in it? It is unlikely to be directly useful to the end users, in the majority of cases.
Mar
13
comment How to properly inject iterators into table?
@rasher Thanks for the accept :).
Mar
11
comment ParallelMap doesn't work with an Association. Is this a bug?
@MichaelE2 Yes, that's right, your second version is what I meant - your code is probably the best way to do this currently. If f is expensive, this may actually be quite a sensible thing to do.
Mar
11
comment ParallelMap doesn't work with an Association. Is this a bug?
I don't think this explanation is quite right. Map has a certain specific semantics on Associations, namely it maps a function on the values of an Association, and the fact that parallel functionality does not yet work in the same way is a current limitation of the parallel functionality. By the logic of your answer, Map also shouldn't work on Associations, but it does. Why Map has this semantics for an Association, is a separate question, but given this design decision, ParallelMap should in principle do the same.
Mar
11
comment ParallelMap doesn't work with an Association. Is this a bug?
@MichaelE2 I think your comment is right on target. OTOH, this can be viewed as a current limitation of the parallel functionality. The ParallelMap implements its own version of Map, which schedules the computations to individual kernels and then assembles the result. Your implementation can be viewed as one such possible implementation, although in general the code should be a little different, since mapping on Associations maps on values, while in your code mapping will be on rules key -> value.
Mar
11
comment What is more probable; one 50 percent chance, or ten 5 percent chances?
This is a wrong place to ask this. However, bet on the single one. The probability for the other one is 1-(1-0.05)^10, which is about 0.4.
Mar
10
comment How to convert a notebook to an association and back?
One obvious suggestion is to introduce unique Ids of some sort, and then store quotes in one Dataset, and the rest in the other, and refer to quotes by Id. This seems to be the only way to avoid duplicating quotes in all sub-sections. This is a general problem with hierarchical databases - you may get away with fewer data sets, than if you would use relational tables, but often for the price of data denormalization. Where to put the line here depends on the application. If your data set is generated and then is read-only, you may as well decide to denormilize the data and duplicate the quotes
Mar
10
comment How to properly inject iterators into table?
@MichaelE2 You are right, thanks for the remark. I have not seen this remark until now, exactly because I was editing the answer to incorporate a better version, in the spirit of your suggestion.
Mar
10
revised How to properly inject iterators into table?
Added a different version, fully lexical
Mar
10
answered How to properly inject iterators into table?
Mar
9
comment Is it possible to assign a value where the target is itself a variable
This is kind of hard in Mathematica. One way to do this would be Hold[x]/.OwnValues[x]/.Hold[var_]:>(var = 4) assuming that a is a symbol. If a is a string name, then: ToExpression[x, StandardForm, Function[var, var=4, HoldFirst]].