Note that there are some explanatory texts on larger screens.

plurals
  1. POPurely functional data structures with copy-on-write?
    primarykey
    data
    text
    <p>I want to have the advantage of functional data structures (multiple versions of data that can share structure) but be able to modify it in an imperative style. </p> <p>What I'm thinking about (and a possible use): a RPG game in which whole game history is stored (for example, to allow for travelling back in time). Using copy-on-write, I could simply clone the structure holding game state and modify it by introducing a new turn - but have access to the earlier turns (not necessarily all of them, maybe just selected snapshots of game state), without the penalty of having to copy everything every time.</p> <hr> <p>Let's say <code>foo</code> is a map.</p> <pre><code>bar = foo.clone() </code></pre> <p>Nothing of <code>foo</code>'s structure (for example, tree) gets copied yet. However, from now on <code>bar</code> is treated as a copy and no changes are allowed to propagate back to `foo'.</p> <pre><code>baz = bar[someKey] baz.modifyInSomeWay() </code></pre> <p>Now</p> <ul> <li>a new object gets created, that is a modified copy of <code>baz</code>.</li> <li><code>bar</code> is replaced with a new map, holding new <code>baz</code> (possibly retaining some of <code>foo</code>'s structure).</li> <li><code>foo</code> is unaffected.</li> </ul> <p>But if we then do...</p> <pre><code>baz.modifyAgain() </code></pre> <p>...<code>baz</code> can be just modified, because we have a recent version of it. <code>bar</code> doesn't need to be changed.</p> <p>All this requires holding some version information about <code>foo</code> and <code>bar</code>, increasing it on <code>foo.clone()</code>, and passing it to <code>baz</code> somehow (by making it a proxy object?). </p> <p>Also, any part of structure that has been cloned becomes a 'part of history' and can't be changed anymore, which could be enforced at run-time.</p> <hr> <p>This resembles JavaScript's prototypes a bit, but I it's more as it allows for changes to propagate upwards. I think it would be something like a version control system.</p> <ul> <li>Has this been done, and to what extent?</li> <li>Is this a good idea? If not, is there a way to save it?</li> <li>How could it be implemented? I was thinking about building it on top of some high-level GC-ed language, like Python.</li> </ul>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload