Insert!, cross-module struct mutation and symbol reference

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

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.

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

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

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).

3 Likes