61,367 reputation
6185278
bio website mathprogramming-intro.org
location St. Petersburg, Russia
age 38
visits member for 2 years, 11 months
seen 8 hours ago

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


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 :)
Nov
6
comment What is the shortest way to switch between heads of nested functions
As you wish, posted an answer.
Nov
6
answered What is the shortest way to switch between heads of nested functions
Nov
5
comment What is the shortest way to switch between heads of nested functions
The problem is that the OP didn't formulate his general needs. There are many ways to solve this problem, which would all give the same result for his example, but will generally behave differently. Re: Thread - one good place to read on it is Wagner's book.
Nov
5
comment What is the shortest way to switch between heads of nested functions
In your approach, you don't need an extra step with /.. You can simply use switch[f_[g_[x__]]]:=g[f[x]]. I was thinking about this method too, but there are many ways to generalize from here, and the OP didn't provide a general example / request.
Nov
5
comment What is the shortest way to switch between heads of nested functions
Thread[f[g[x]], g]
Nov
5
comment What are the applications of using functions whose heads are also functions?
In V10 new operator forms have been introduced. One can use SubValues to get similar functionality. It can be quite useful.
Nov
5
comment A smarter nested With?
@TeakeNutma Yes, sure, that wasn't hard at all, see my edit. Thanks for the accept. This was a nice exercise, and this stuff can be actually useful too.
Nov
5
revised A smarter nested With?
Added intermediate variable for threading over symbols, per OP's request
Nov
5
comment Finding duplicates in a list
In V10 there is DuplicateFreeQ.
Nov
5
comment Mathematica taking too long to calculate recursive function
@DanielLichtblau I did mention this, but was wrong to think of this as of a secondary reason, and to blame memoization. Changed my post now, apparently this is indeed the main and only reason for the slowness.
Nov
5
revised Mathematica taking too long to calculate recursive function
Changed the post as memoization apparently wasn't really an issue.
Nov
5
comment Mathematica taking too long to calculate recursive function
@MichaelE2 Looks like my reasoning was partly wrong. Memoization seems to work also in the OP's case. Will change my answer.
Nov
5
revised Mathematica taking too long to calculate recursive function
added 220 characters in body
Nov
5
comment Mathematica taking too long to calculate recursive function
@MichaelE2 Will do, thanks. But have a look at my edit, I also fixed the recursive code.
Nov
5
revised Mathematica taking too long to calculate recursive function
added 220 characters in body
Nov
5
revised Mathematica taking too long to calculate recursive function
added 220 characters in body