# Insert!, cross-module struct mutation and symbol reference

**URL:** <https://discourse.julialang.org/t/insert-cross-module-struct-mutation-and-symbol-reference/58707>\
**Category:** General Usage\
**Created:** [April 6, 2021, 6:23pm UTC](https://discourse.julialang.org/t/insert-cross-module-struct-mutation-and-symbol-reference/58707 "2021-04-06T18:23:40Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![rdeits](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rdeits/32/286_2.png) [@rdeits](https://discourse.julialang.org/u/rdeits)\
**Post date:** [April 6, 2021, 6:34pm UTC](https://discourse.julialang.org/t/insert-cross-module-struct-mutation-and-symbol-reference/58707/2 "2021-04-06T18:34:34Z")

</div>

> [@Mark\_Nahabedian](#):
>
> As a lisp programmer I’ve learned that “modify in place” operations might need to relocate the object (in this case insert! aND THE Notebook’S vector of Cells), so one should assign the modified result back where it came from.

That’s not necessary in Julia, at lest not in any circumstance I’ve come across.

> [@Mark\_Nahabedian](#):
>
> I remember reading someplace that Julia didn’t allow cross-module struct mutations.

Mm, no, that’s not a thing. There are no issues or restrictions on modifying `mutable structs`, regardless of what module your code or the definition is in.

> [@Mark\_Nahabedian](#):
>
> I don’t know how to refer to :cell from the Pluto module rather than my own.

Likewise, this is a red herring. The particular module in which the code lives is of no consequence.

> [@Mark\_Nahabedian](#):
>
> I get the error " type Notebook has no field cells" which is somewhat misdirecting in that I was able to read the cells field without error, just bot set it.

This is because the `.cells` accessor is actually provided by this `getproperty` definition:

> <https://github.com/fonsp/Pluto.jl/blob/2ebdaaf615c9491ba0b04271a9214665b5a3d5b5/src/notebook/Notebook.jl#L59-L71>

There’s no `setproperty!` implementation, presumably because Pluto.jl intentionally doesn’t support that particular way of modifying the cells.

That function also reveals why mutating `notebook.cells` doesn’t work. The `getproperty` method means that `notebook.cells` returns a _brand new_ vector (the output of `map`). You can mutate that all you want, but it has no effect on the notebook itself.

It looks like Pluto.jl doesn’t support what you’re trying to do, but it doesn’t look like it would be too hard to add it. As far as I can tell, it would require modifying both `notebook.cells_dict` and `notebook.cell_order`. That would probably best be done by adding a new `insert_cell!` function in Pluto.jl itself, but there’s no reason you can’t prototype that function in your own code (as you’re doing now).

---

_[View the full topic](https://discourse.julialang.org/t/insert-cross-module-struct-mutation-and-symbol-reference/58707)._
