Arc Forumnew | comments | leaders | submitlogin
Mutability of complex structures read from file
5 points by rig 5563 days ago | 4 comments
There is a vexing feature in vanilla implementation of Arc, that components of any complex structure become immutable after reading back from file. If that is not what you want, here is a simple fix:

    (def mutable (x)
      (case (type x)
        cons (cons (mutable (car x)) (mutable (cdr x)))
        table (w/table h (each (k v) x (= (h k) (mutable v))))
        string (copy x)
        x))
As you can see, my solution is just to copy everything. Exemplary usage:

    (zap mutable hairy-structure)


1 point by fallintothis 5563 days ago | link

Also known by the more common name deepcopy. I had thought this was already in Arc, but apparently it isn't. Thanks!

-----

1 point by akkartik 5562 days ago | link

Ah, it's just copy. http://files.arcfn.com/doc/variables.html#copy

I'm tempted to use it everywhere in read and write, but nah, better to explicitly let us take on the overhead where we need it.

-----

1 point by akkartik 5563 days ago | link

I like this. I ran into this problem a while ago. My solution for just tables: http://arclanguage.org/item?id=10677

-----

1 point by shader 5563 days ago | link

This should be added to anarki, if there isn't already a fix for immutable structures.

-----