Timeline for Struct equivalent in Mathematica?
Current License: CC BY-SA 3.0
15 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Apr 12, 2019 at 16:32 | comment | added | Jyrki Lahtonen | Thanks for collecting these pieces. But I specifically need the structure to be mutable. That's the whole point. Then what? | |
| May 23, 2017 at 12:35 | history | edited | CommunityBot | replaced http://stackoverflow.com/ with https://stackoverflow.com/ | |
| Apr 13, 2017 at 12:55 | history | edited | CommunityBot | replaced http://mathematica.stackexchange.com/ with https://mathematica.stackexchange.com/ | |
| Jul 21, 2014 at 17:15 | comment | added | Leonid Shifrin | @Reb.Cabin All right, then I know whom to bombard with stupid questions when I finally get my hands on it :) | |
| Jul 21, 2014 at 16:25 | comment | added | Reb.Cabin | @Leonid -- I have done some at-scale, production-level systems in Clojure and highly recommend it :) | |
| Jul 21, 2014 at 9:26 | comment | added | Leonid Shifrin | @Reb.Cabin I am going to do that, in fact. Clojure stands high on my to do list. Thanks for the suggestion, anyway! | |
| Jul 20, 2014 at 23:21 | comment | added | Reb.Cabin | The careful handling of mutability, structure-sharing, and software transactional memory in Clojure might be the most sophisticated available in the world today (infoq.com/presentations/Value-Identity-State-Rich-Hickey). If I were to go whole-hog in Mathematica with a data-structure library, I would learn from Clojure. | |
| Jan 30, 2012 at 15:53 | comment | added | Leonid Shifrin | @Rojo my point is that even Part is not enough, because elements of an expression are expressions, not pointers. When you extract them, their copy is made. When you assign these parts to variables and modify those, that assigned copy is modified, not the original part within a larger expression. As for ReplacePart, it sure does make a copy, as most other functions returning expressions. | |
| Jan 30, 2012 at 15:46 | comment | added | Rojo | My guess is that Part on the lhs is the only way to change only part of an expression without making a copy. Also, that MMA only makes a copy of the data whe it has no other choice in its built-in functions that modify an expression. But how to know if, e.g, h=ReplacePart[h, 2->8] does a full copy or if its smart enough? (h being unpacked array) | |
| Jan 30, 2012 at 15:36 | comment | added | Leonid Shifrin | @Rojo What I mean is that if I have, say in C, a struct like typedef struct{ int x, int y} mystruct;, then, if s is of this type, I can say s.x = 10. If I have an expression like node[left, data, right], and it is stored in some variable (say expr), then I also can say expr[[1]] = 10, but I can not nest this deeper. For example, if left is also a node, I can not say left = expr[[1]]; left[[1]] = 10 and expect this change to also affect the original left node inside expr - it only affects a copy. Basically, it boils down to the fact that we lack here pointer semantics. | |
| Jan 30, 2012 at 15:24 | history | edited | Leonid Shifrin | CC BY-SA 3.0 | Added a link to file-backed lists post |
| Jan 30, 2012 at 15:23 | comment | added | Rojo | I guess it's all about knowing when MMA does an internal copy of the expressions, which I don't know, nor know how to check... This reminds me that I've been confused with this issue also in the context of reading that Bags were so special because they could emulate a pointer, and a few things about linked lists (these I understand a little bit more than half of the way) | |
| Jan 30, 2012 at 15:22 | comment | added | Rojo | I've read about mutable and immutable several times on your posts and I get it only half of the way. I didn't study computer science, but googling tells me that mutable is when it can be changed after its creation, which Part can do it seems. On the other hand, you can change a downvalue without changing the others if you consider the pack of that symbols' definitoins as your structure. Also, wouldn't something like a tree built with node[left, data, right] with HoldAll be mutable? | |
| Jan 30, 2012 at 15:17 | history | edited | Leonid Shifrin | CC BY-SA 3.0 | added 751 characters in body |
| Jan 30, 2012 at 15:10 | history | answered | Leonid Shifrin | CC BY-SA 3.0 |