Leonid Shifrin
Reputation
74,178
279/100 score
 Oct 4 comment Using Java log4j in Mathematica Well, the code in RLink pretty much shows how this can be used. The only missing piece is the logger instance, which is referred there as RLinkInitrlogger, and for which instead you can use LoggergetLogger["YourApp"]. And you will have to first LoadJavaClass["org.apache.log4j.Logger"], and add the log4j.jar to the classpath. Sep 29 comment Element-wise test on List elements @dario [2/2] ... makes it Listable - that is, wraps it in a pure function that has a Listable attribute. Due to the way evaluation sequence works in Mathematica, this leads to threading of the function over lists, before it gets applied to the individual elements. As a result, the construct l[Greater] would automatically work on lists of any dimensionality, compared to a single number - as well as for e.g. comparison of two lists with the same dimensions - like say {1,3,5} ~ l[Greater] ~ {6,4,2}. Thanks for the accept. Sep 29 comment Element-wise test on List elements @dario [1/2] The syntax a ~ f ~ b is called infix notation, and is equivalent to f[a,b], but sometimes looks more natural. Like in this case, where it allows to somewhat make up for the notational convenience of comparison operator symbols. The expression a > b can be equivalently rewritten as Greater[a,b] in Mathematica, and similarly for other operators. So, we could also write a ~ Greater ~ b, which doesn't look bad. Now, from this form, my suggestion is only one step further. The function l I proposed is similar in spirit to Python decorator. It takes another function and ... Sep 29 awarded Enlightened Sep 29 awarded Nice Answer Sep 29 comment Why does Part return empty list for non-existing elements in ;; specification? The semantics of Part is that Part[lst, {positions}] always returns a list, which is a special case of a general spec that Part extracting a list of positions always keeps the head of the original expression. The case with Span is similar, because Span can be viewed as a more efficient and succinct shortcut for specific lists of positions with some regular structure. Thus, empty list. The case of single element is different, though. Arguably, Part could also return Missing in that case, but the behavior with an error message is much older and probably can't be safely deprecated. Sep 29 comment Why is the first argument of the SetDelayed evaluated? @Szabolcs This is one of them. Another one, which is IMO no less important, is that keeping l.h.s. entirely unevaluated would often lead to discrepancy between l.h.s. in definition and actual l.h.s. of a typical function call involving a given symbol, in case if such l.h.s. evaluates non-trivially - because otherwise in one case, it would evaluate, and in the other, it wouldn't. In other words, the current policy tries to make evaluation during function calls be maximally consistent with evaluation during assignments. Sep 28 answered Element-wise test on List elements Sep 27 comment In a list of points, how to efficiently delete points which are close to other points? @belisarius I have no idea. But it can't be right. Without a deep analysis (which is very unlikely to be happening inside Union), it is impossible to optimize and move away from pairwise comparisons. In fact, the norm-based sameness function is not even transitive. So, even though the result looks right, I suspect that Union is doing something wrong here. Unless, of course, it can analyze the sameness function way deeper than I can imagine. Sep 27 awarded Enlightened Sep 27 comment Finding Local Minima / Maxima in Noisy Data @AntonAntonov It is very interesting. I read through your blog post, and the results are impressive, as well as the idea to use two regressions with different quantile numbers. Will set some time to study the code behind that in detail. Thanks for posting it! Sep 26 comment Why is the first argument of the SetDelayed evaluated? I have a rather detailed discussion of evaluation during assignments here. Basically, HoldAll simply means that arguments are passed to the function in unevaluated form, but does not restrict what functions decide to do with them. And Set and SetDelayed do evaluate their first arguments, albeit in a special way. An example very similar to yours I also considered in this answer, in the section named "Evaluation: OwnValues". Sep 26 comment Name rewriting for Function fails in closure @WReach I fully agree (also voted for this answer), but sometimes I just can't avoid named arguments in Function, particularly with nested closures (well, may be one can do that technically, using With etc, but it's really ugly). I am afraid that this poses a real threat to the correctness of my code where I use them, though. In particular, I heavily use them in Streaming  module. It may be worthwhile for me to inspect it and perhaps see if I can get rid of named arguments there. Of course, in my particular case, another option is to use the framework I described in my answer. Sep 25 comment Finding Local Minima / Maxima in Noisy Data @AntonAntonov That's great to know! Perhaps, you could post it as an answer, or edit mine? Or post it somewhere else, and link to that? I am curious to see it, sounds interesting. Particularly for me, since I've been doing mostly pure programming stuff in recent years, while I certainly have interests in other areas with more math and algorithms involved, as well. Sep 25 revised Name rewriting for Function fails in closure Added a section on global environment Sep 25 comment Best practices with HDF5 and Datasets In this answer I have a section on HDF5, which is based on Import / Export. This may not be entirely what you are after, but might still be useful. The code I gave there converts between HDF and a tabular list structure, but I also provided functions tableToDataset and datasetToTable which you can use to convert between Dataset and HDF5, so you will have to use tableToDataset @* hdf5ToTable and datasetToTable @* tableToHDF5. Sep 25 answered Name rewriting for Function fails in closure Sep 25 comment Recognizing text and Mathematica special characters when copying expressions from a PDF I am afraid that this question is off-topic here, at least if it only concerns specifically my book. The result of copy-paste really depends on pdf browser, but I agree that in many it is unsatisfactory. At the time I was creating the pdf, I was on Windows and checked there, where situation seemed better. I will try to find a moment to look for the code of the book in .nb form, and make it public. The particular function in question has modern, much better and more succinct successors, such as timeit` function of Mr.Wizard, etc. You may search for the latter on this site. Sep 25 awarded Nice Answer Sep 24 revised Efficient conversion between two partition representations Corrected the name of the predicate variable