60,532 reputation
6181274
bio website mathprogramming-intro.org
location St. Petersburg, Russia
age 38
visits member for 2 years, 10 months
seen 1 hour ago

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


1d
comment How to abort silently?
@JacobAkkerboom You are probably right. I guess I just used the mental pattern I had for $Pre, automatically.
1d
comment How to abort silently?
Well, you can use something like this: $Post = Function[code,Unevaluated[code]/.$Aborted->Null, HoldAll].
Nov
18
comment $Epilog does not work when exit
It might be possible, but that would require the knowledge of the specific Front End hooks, which would need to be defined instead of $Epilog, provided that such hooks exist (if they exist, I am not aware of them).
Nov
18
comment $Epilog does not work when exit
My guess is that for both of the two methods you mentioned last, the $Epilog hook is not triggered, because they quit the kernel via a different route. Presumably because they both are initiated by the Front End. Let's wait for someone with a deeper knowledge of this mechanism to comment on this.
Nov
15
comment Efficiently reading CSV with ReadList
@Thijs The first link I gave is to code which de facto uses Import (via ImportString), so you can give the same spec there. If Import works for you in principle (but is just slow), then that code should also work for you (but be faster / more memory-efficient). If Import can't handle your format, then it is another story. You might need to write some custom parser.
Nov
15
comment Efficiently reading CSV with ReadList
In addition, you could use this solution to transfer your file into chunked form suggested there - which would allow you to load those chunks on demand. You could combine these two, to have a workable solution. You can also look at this question (of which your question seems to be a duplicate).
Nov
15
comment Efficiently reading CSV with ReadList
Unless you have huge amount of memory, you won't be able to import this file as a whole, in any case, because typically Mathematica uses 10-20 times more memory in RAM than the size of file on disk, due to its symbolic nature (unless packed arrays and other efficient structures are utilized, which won't happen automatically during import). Have a look here for a solution which effectively uses Import, but splits the data into chunks and might work for you.
Nov
13
comment Is it possible to have a function with non-global parameters?
@RahulNarain This happens when one does not use Private` sub-context for implementation code. Those symbols (local variables) are then generated in public context and exported as well, when the context is loaded.
Nov
10
comment matrix multiplication speed
@yashar That's the one. Search for a chapter on dynamic programming.
Nov
10
comment Pattern matching: Times[a_] vs Times[a__]
This has to do with the Flat attribute of Times.
Nov
10
comment matrix multiplication speed
@yashar Have a look at an example in David Wagner's book named "Matrix chain multiplication". He uses dynamic programming to optimize the multiplication strategy, and discusses this issue at length.
Nov
10
comment Select last occurence of key in dataset
You need something like ds[GroupBy[#ID &]][All, Last], where ds is your data set. Generally, it is better to provide explicit small sample in your question, to make it self-contained.
Nov
8
comment How are MemberQ and FreeQ so fast?
@QuantumDot Yes, _head is a good example of syntactic pattern. As to Alternatives, it is still syntactic pattern (as far as the alternative patterns are all syntactic), since it only involves pattern-matcher and not evaluator.
Nov
8
comment Once more on object orientation in Mathematica: does it have to be so hard?
Very interesting, +1. I always wanted to construct a prototype-based version too (particularly because, while I do use my own version a lot, I tend to use it in a prototype-style fashion, adding behavior to particular instances). Have no time for more than a quick look today, but will look closer tomorrow.
Nov
7
comment A smarter nested With?
@TeakeNutma Another comment on all this code is that one can make it way more robust, but slightly less cool, by introducing a helper head with, making it HoldAll, and then replacing with With at the end. I just didn't go this way, but then one can safely use all language constructs inside, and perhaps it is better in terms of being more robust. Just less cool :)
Nov
7
comment A smarter nested With?
@TeakeNutma I'd add that at this point, this stuff becomes a bit scary. My feeling has been that this is pretty close to the limits of what I can control :)
Nov
7
comment A smarter nested With?
@TeakeNutma This is rather crazy, the stuff going on there. The reason is that With is in fact broken inside SetDelayed (and inside Let/ let), so adding any more code you want to execute (rather than plain expansion) is dangerous, since that code can rely on With being unbroken. So, my original code was a walk on a thin ice, but still Ok, while the code with added message issuing was unlucky. Presumably, messages use With internally. Anyway, I fixed that, here, but for the expense of elegance, to some extent.
Nov
7
comment Compare 2 lists
The answer has been described here (functions seqPos and seqPosC in my answer there), and here.
Nov
7
comment A smarter nested With?
@TeakeNutma I can't reproduce this. With this definition:ClearAll[symbolOrListQ];SetAttributes[symbolOrListQ,HoldAll];symbolO‌​rListQ[_Symbol|_List]:=True;symbolOrListQ[_]=False;, everything works fine (I tried the same example f:=Let[...]. I'd need to know exactly all the changes you've made to say more. Re: HoldFirst - not so simple. This may lead to evaluation leaks. In particular, here: let[{}, body_, {}, _] := With[{}, body];. Generally, I think this is a bad idea, makes the code potentially fragile. In my method, I explicitly override HoldAll lexically, in specific places.
Nov
6
comment What is the shortest way to switch between heads of nested functions
@Algohi Thanks for the accept :)