Not really an answer to my question, but a solution to my problem: I found a way to store mutable state. Using closures it’s possible to write “constructors” that return “objects” which have persistent mutable state, and calling “methods” of the “object” will change its state for all references to the object. Here’s an example of a stack constructor I’m using in my current project:
on new_stack do
state: ()
("stack","push","peek","pop") dict
(on _ do state end
,on _ x do state[count state]: x end
,on _ do (-1 take state)[0] end
,on _ do ans:-1 take state state:-1 drop state ans[0] end
)
end
This method is used in the example module in the documentation, although outside the function so it only creates a single global mutable state.
Edit: A universal minimal mutable variable:
on new_var state do
("get","set") dict
(on _ do state end
,on _ new do state:new end
)
end