4 ms·
I assume you mean persistent, not immutable. a[x] = 1 b = a a[y] = 2 <---- mutates a a[x] = 3 <-- is this legal? b[x] <--- persistent-
by gohrt 12y ago
I assume you mean persistent, not immutable.
a[x] = 1
b = a
a[y] = 2 <---- mutates a
a[x] = 3 <-- is this legal?
b[x] <--- persistent- uh, what is Mathematica's semantics here?
- programnature 12y agoNo, I meant lists of rules like {a->1,b->2}, which capture the same kind of patterns as in the previous example but in an immutable (and copy-on-write) way.
- taliesinb 12y agoYes, Associations use the same basic algorithm as Scala and Clojure's hashmaps, and are indeed persistent. And b[x] there gives 1 as you would expect.
- davorak 12y agoDo you know when that change was put into place? I have been using Mathematica sense version 5 and my intuition was that `b[x] == 3`. Testing in mathematica 8 which I have on hand confirms this.
- taliesinb 12y agoMathematica 8 doesn't have associations, so you must be testing symbol assignments. Write a = <||> before running the above code to test this on associations; associations are persistent, the symbol table is not.