Reputation
65,433
Next tag badge:
207/100 score
19/20 answers
Badges
6 194 285
Newest
 Nice Answer
Impact
~407k people reached

Feb
6
comment FoldWhile and FoldWhileList
@Ajasja ... enclosed in pure functions, so as soon as the main function (the one using that closure) executes, the garbage collector comes to those variables.
Feb
6
comment FoldWhile and FoldWhileList
@Ajasja It is a closure.The fact that in principle one can access variables like ctr$nnn from the top-level is due to the imperfect emulation of lexical scoping by Mathematica's symbol renaming mechanism. Normally, one would not use such variable names, so for all practical purposes this should be ok. Also, if you consider other languages (e.g. javascript), the variables from enclosing environment remain accessible / modifyable from within a returned function (closure) - they are just not available at the top-level. As for Names - yes, Temporary works, because the variables are ...
Feb
6
comment How can I remove matching sublists from my list?
@QuantumDot Thanks, good that it works. Re: # /@ & #2 - no, what I had there was just rule application {h, c, s} /. #2, where #2 is a second argument which, in the context of last optional argument of Reap, gives a list of collected results for a given tag.
Feb
6
comment Why does this pattern with Plus not work for numbers?
I think that this is a rather important detail, and perhaps having this question around would be nice, since people come back to this every now and then. Just a day ago there was a similar question on Mathgroup. It is just this kind of detail where pretty much all one can say is "you do want to know about the mere fact of it, but you don't want to know anything deeper than that".
Feb
6
comment Why does this pattern with Plus not work for numbers?
IMO, this internal mechanics of Plus should not be relevant to the user. To me, this seems one of those internal details which can not serve you well even if you know them. Plus, Times and perhaps a few more fundamental functions have deviations from the standard evaluation semantics, so that certain buit-in rules like the one you illustrated apply before the user-defined rules. The whole fact that this was done in this way shows that those rules were considered very fundamental by developers, which brings the question again: how would the knowledge of exact semantics here be helpful?
Feb
6
comment Why does this pattern with Plus not work for numbers?
And here is a very simple answer: don't do it.
Feb
5
comment How can I remove matching sublists from my list?
@Szabolcs Sure. Our solutions are similar. No idea why yours received less votes (I voted for it, of course). Normally GatherBy comes to my mind first, before Reap-Sow, but for some reason here it didn't. GatherBy is actually several times faster, but here it is not seen, since the bottleneck in your code is elsewhere (mapping, rule application).
Feb
5
revised FoldWhile and FoldWhileList
Fixed a few typos
Feb
5
comment FoldWhile and FoldWhileList
@Rojo That's a cool idea! It won't be as efficient alas, due to assignments to last (main part) and extra function invocation. So, while I like this from the design perspective, I would probably still keep my version unchanged, for efficiency. Of course, for computationally-intensive functions this should not matter much.
Feb
5
comment FoldWhile and FoldWhileList
@Rojo Welcome :-). Re: as efficient: memory-wise, no, since Sow will have to store those intermediate results internally. This, plus the fact that I can make the code simpler, was my motivation to implement it separately. As for run-time efficiency, a bit less efficient too, but probably not much so.
Feb
5
revised FoldWhile and FoldWhileList
Added code for version fifth-arg versions, restructured
Feb
5
awarded  Nice Answer
Feb
5
comment How can I remove matching sublists from my list?
@Murta Thanks for the upvote :-)
Feb
5
answered How can I remove matching sublists from my list?
Feb
5
comment Apply UpValues before Listability
I think this is one of these things which are really hard to make different generally and consistently, since one would have to explicitly go against the standard evaluation sequence. I would reconsider the design of whatever you try to achieve with this. While I will be the first to suggest workarounds which change system's behavior in many cases, I also think that admitting and accepting certain limitations of the system can sometimes be more productive.
Feb
5
revised FoldWhile and FoldWhileList
Fixed a bug in initialization
Feb
5
comment FoldWhile and FoldWhileList
@ssch Agree. This second argument business is explained very well in this excellent answer by Rojo. That answer deserves many more upvotes IMO.
Feb
5
revised FoldWhile and FoldWhileList
Improved reap-sow by tagging
Feb
5
answered FoldWhile and FoldWhileList
Feb
5
comment Performance: Collapsing repeated contiguous rows & cols from a matrix
@halmir I would rather take the code as a spec and make the description less ambiguous in this respect - presumably the OP looked at the results of his code and was satisfied with it, just not its speed.