Leonid Shifrin
Reputation
80,218
288/100 score
 Mar 18 revised Immutability, Association and typing Added example for mutable objects Mar 18 comment Select with test function that depends on # @BlacKow Reap - Sow is a conceptually simpler solution, and also with much better complexity, if you look for a categorization problem (which you do, de facto). OTOH, if all you need is a couple of selections, then I don't see why asking this question at all. As I said, your problem is really not a pure selection problem as soon as you start combining elements into groups. If Map and Select work for you - fine. Mar 18 comment Select with test function that depends on # I retracted the close vote. However, note that as soon as you start categorizing things, your operation is no longer a simple select, so there is no reason to expect that Select without additional steps can handle it - categorization is semantically different from selection. You can use Reap and Sow with specific tags: Reap[Sow[#, #] & /@ l, 1 | 8, #2 &][[2]], which maps mor directly to your needs, it seems. Mar 17 answered Immutability, Association and typing Mar 17 comment Performance tuning in Mathematica? @TomZinger Actually, there is also a section in this answer, called "Memoization for functions of more than one parameter, and using patterns in memoized definitions", which contains a somewhat more accessible explanation of the same thing. See if you find it more clear. Mar 17 comment Performance tuning in Mathematica? @TomZinger You can always ask a question on your specific problem on the main site. There is a good chance that you will get a decent and clear answer for your particular problem. Mar 17 comment Finding all elements within a certain range in a sorted list @RunnyKine Indeed. Tested on WVM target, M10.2. I have only one possible explanation: the compiled function copies the list internally, while the top-level version does not. Since the time it takes to do a single lookup is logarithmic in the size of the list, it is negligible w.r.t. internal array copy. Why array is copied, I don't know - it should've reused / shared the original array passed to it. Mar 17 comment Finding all elements within a certain range in a sorted list @RunnyKine I don't have 10.4 on this machine, and neither do I have C compiler here currently installed, so I can't test. Do you include the compilation time in the measurements? If so, it might explain it. If not, I am really not sure - compiled version should be faster. Mar 16 comment General strategies to write big code in Mathematica? Thanks a bunch! Looking forward! Mar 16 comment General strategies to write big code in Mathematica? @Mr.Wizard Indeed. This is strange, since I do remember testing Delete, and that was on the same M version I used now. Mar 16 comment Granular versus terse coding @Mr.Wizard I actually incorporated my reply-in-comments into my answer, and restructured it, so thanks for writing your 2 replies and prompting me to do so - I think I was able to express myself better as a result. Mar 16 revised Granular versus terse coding Added some of the things from my comments, restructured Mar 16 comment What are the use cases for different scoping constructs? @unlikely Was glad to help. Mar 16 comment General strategies to write big code in Mathematica? Sounds very interesting! I wonder what would be the best learning path for someone like me (I only know a little about general principles behind this stuff), to get into this topic, in your opinion. Can you recommend some set of sources (may be books, blog posts, may be some open code / projects, whatever), which one could use to at least get some introductory-level understanding of this (I mean, besides your excellent posts - or do you think your posts could be enough to learn the basics about this)? B.t.w., if that is not something you feel comfortable sharing, I will perfectly understand. Mar 16 comment General strategies to write big code in Mathematica? Thanks a lot, this is just great! I've had it on my todo list to read about parser combinators, but I never had the time, since I'd need to first learn Haskell or ML. And, actually, I've been interested in conversational engines for at least a couple of years, particularly in the context of Mathematica - they seem to have almost endless area of business applications. But I didn't have enough time and didn't know where to start. I had no idea that you published so much great material on the subject! I will certainly find the time to study this. Thanks again! Mar 16 comment What are the use cases for different scoping constructs? @unlikely In the simple case you considered, garbage collection works all right. The problem happens only when the local symbol (f in your case) with DownValues (or SubValues, UpValues) is referenced by something more global, at the time when such definition is made. In the example from that link, it was referenced by a variable local by the enclosing scope. Note that even though that variable was later garbage-collected, this didn't help the inner variable. Mar 16 revised General strategies to write big code in Mathematica? Replaced deleteFirst with Rest, per Mr.Wizard's comment Mar 16 comment General strategies to write big code in Mathematica? @Mr.Wizard Thanks for this observation! For reasons beyond me, I did not try Rest, but only tried Drop and Delete, both of which were slow. I will edit this in. Mar 16 comment Performance tuning in Mathematica? @TomZinger Glad you found it useful. Re: 10.2: I meant memoizing entire patterns. Have a look at this answer for an example of that, and also this great answer. And also this one - in there, I list the generated definitions, so it is rather explicit in what you get memoized. Mar 16 revised What is the distinction between DownValues, UpValues, SubValues, and OwnValues? Fixed a type, per Matrin's comment