Reputation
69,183
Next tag badge:
211/100 score
19/20 answers
Badges
6 204 295
Newest
 Nice Answer
Impact
~447k people reached

Jul
7
comment Is there a built-in equivalent to Python's enumerate?
@RunnyKine Sure, np. At some point I will write up a much more detail tutorial on this stuff, but right now both I don't have the time and the functionality itself has not stabilized. B.t.w., keep in mind that chunk size may affect the performance quite seriously. For large lists, it generally is preferable for best performance to keep chunks large enough, like several thousands elements and more (of course, that also depends on how large the elements are, on the average).
Jul
7
comment Is there a built-in equivalent to Python's enumerate?
If you have some normal list of data, you can use LazyListCreate[lst, size-of-the-chunk], to create a LazyList out of it, with the specified size of teh chunk (length, number of elements, not ByteCount). There are other ways too (also using LazyListCreate), but they are somewhat more involved.
Jul
7
comment Is there a built-in equivalent to Python's enumerate?
@RunnyKine I don't have much time right now to add significant examples, but LazyFold works indeed a little differently from Fold. The function to be folded takes 2 arguments: the previous result (#1), and the next chunk (note: a list of elements, not a single element) (#2). So, for example, to compute a total of a LazyList, you can use Fold[#1+Total[#2]&, 0, lazylist], where for usual lists and usual Fold, you'd use Fold[#1+#2&, 0, list]. Let me know if this makes thing work for you.
Jul
6
comment Is there a practical way to define a default value for missing keys in an Association?
@Mr.Wizard Re - default value: indeed, you are right, it doesn't change. So, I take that critique back. In fact, one constructive suggestion that comes out of this is to be able to specify a default value, or generally, default function, when association is constructed. In fact, at some point during development such thing was discussed internally, but then for some reason it has been discarded. When I get a chance, I will ask, what was the rationale behind not having it.
Jul
6
comment Is there a practical way to define a default value for missing keys in an Association?
@Mr.Wizard ... that new data type into the language. Quite possible, but a lot of work. I might post some version of such solution later, if I have the time. This brings us to an important topic of the lack of subtyping mechanism for core data structures in Mathematica - which would allow one to e.g. subtype an assoc and add some state to it (like one can do in e.g. Python).
Jul
6
comment Is there a practical way to define a default value for missing keys in an Association?
@Mr.Wizard Re: (2): No, it doesn't, but Lookup is the only built-in function providing the default mechanism. One can surely implement one's own handling, but that would be more work, again (3).*"Do all of the benefits of associations cease to exist for some reason? Easy copying and manipulation of values, nested associations, etc. still apply do they not"* - yes, they do not apply any more as long as you want your assoc to be mutable and carry a state. That's precisely the point. You have to then define a new data type that would carry that state together with the assoc, and integrate ...
Jul
6
comment Is there a practical way to define a default value for missing keys in an Association?
@Mr.Wizard ... most other functions working with assocs will not have the information about where a given assoc is stored (in which variable or variables), and will operate on assoc directly, producing new assoc or whatever. So, every time when you need to add mutability, you have to do some special tricks, like you did with Missing. There is simply no way for Lookup, for example, to do some in-place modifications related to the default value. So, my point has been that what you ask for would go into directions with very weak support from the core language, and would need more work then.
Jul
6
comment Is there a practical way to define a default value for missing keys in an Association?
@Mr.Wizard Re: 1 - I largely answered this here, but to summarize, the main advantage of associations with respect to DownValues or System`Utilities`HashTable is that associations are immutable, but cheap to copy and modify. In the linked post I described why immutability is valuable (statelessness, garbage collection, etc). The ability to mutate assocs in place does exist (like with lists), but its support in the language is limited to very simple things like part assignments. Since there are no true references in Mathematica, ...
Jul
6
comment Is there a practical way to define a default value for missing keys in an Association?
Also the title seems to be a bit misleading currently: what you ask for is not just default, but mutable default - which makes quite a difference.
Jul
6
comment Is there a practical way to define a default value for missing keys in an Association?
I think that by nature of associations (immutability, in the first place), mutating them in-place isn't by far as natural as mutating DownValues. And the fact that what you request is problematic in this approach is simply another facet of that: the ability to use defaults has been transferred from association itself to the Lookup function, but then Lookup can not be used to mutate things, bacause it knows nothing about where a given assoc is stored (and doesn't care about it). If you need mutation, why use associations? You can keep using DownValues in such cases.
Jul
5
comment Dataset vs an association of associations
A great answer (I already voted)! One small addition is that even when the keys are all strings, the association will be interpreted as Assoc in cases when the number of keys is larger than a certain limit (16 currently), or when the values are all themselves associations.
Jul
3
awarded  Enlightened
Jul
3
awarded  Nice Answer
Jul
3
comment Exporting Dataset to WDX format fails
@OleksandrR. I don't know about other architectures, my guess would be that that isn't the case - so only the former, Windows/Mac/Linux on x86. But I may be wrong.
Jul
2
comment Count the sequences in an array
@Algohi Yes, and this is what it should return in this case, if I understood the question correctly.
Jul
2
answered Count the sequences in an array
Jul
1
comment How to define a recursive pattern?
AFAIK, no new answers have been added to that question, but that seems the right place to put this stuff. I might do that as well, or we can collaborate on it. But I think this can wait.
Jul
1
comment How to define a recursive pattern?
@Mr.Wizard You are right, strictly speaking (although the form of the construct is similar). I removed that link, and added some other, including some of those you mentioned.
Jul
1
revised How to define a recursive pattern?
Added / modified links
Jul
1
comment How to define a recursive pattern?
I agree, your form is superior in a number of ways. I think I picked the one with MatchQ simply because it was the first thing that came to my mind, I wasn't revisiting older discussions (including my own answers). Shows once again that one should always check what was done before. Interestingly, while I did remember the SO question on deep pattern matching, I forgot about the more recent one you linked, already on SE. It might be a good idea to have some post eventually that would summarize recursive patterns, perhaps in the design patterns question.