<_andre>
why does the array append() works in a trn variable in the first method, but not in the second (requiring the extra 'consume ref' shown in the third one)?
<SeanTAllen>
im not sure why the "consume ref" compiles
<SeanTAllen>
That said
<SeanTAllen>
_andre:
<SeanTAllen>
what are you trying to accomplish?
<SeanTAllen>
your ref types don't make a lot of sense, so i think starting over from what you are trying to accomplish would make sense
<_andre>
i have this map of array values which i need to populate, and i want to have methods that return array vals
<_andre>
which is why i went with 'trn'
<SeanTAllen>
so you have a map that is String for key and an array of Strings as the value correct?
<SeanTAllen>
when you say "i need to populate", do you mean, "i need to be able to mutate the arrays of strings"
<_andre>
yes. foo3() is like a "save" method, so if the key isn't present, i initialize it with the empty array using insert_if_absent, then append a given value (in the real program the "bar" string would be a parameter)
<SeanTAllen>
ok so, trn isnt for that.
<SeanTAllen>
trn is "i want a thing that is temporarily mutatable but i can make it not mutable by giving up my reference to it"
<SeanTAllen>
let me make sure i understand a bit more...
<SeanTAllen>
you have an array of strings that is mutable and you want an immutable copy so you can send it to another actor?
<SeanTAllen>
playgrounds can be nice because others can often run the code and see the error you get (with less work than copying a pastebin somewhere and running)
<_andre>
yes, i'm trying to make it work as an in-memory key-value store
<_andre>
where a key can hold multiple values
<_andre>
i'd like the read function to return the array corresponding to the given key, but as a val
<SeanTAllen>
I take it you are thinking that trn would create a copy when you get a val from it, yes?
<_andre>
i thought it would, yes
<SeanTAllen>
yeah it doesnt do that
<SeanTAllen>
so what you want is a `ref` array
<_andre>
so i have to make the copy manually?
<SeanTAllen>
and then you make a copy when you want to send a copy elsewhere
<SeanTAllen>
yes
<SeanTAllen>
you could use either iso or trn to make the copy mutable while builing it then you'd consume that so that it would be a `val` when sending
<SeanTAllen>
the strings in the array are immutable yes?
<_andre>
yes
<SeanTAllen>
right, so then its a loop and copy. that is pretty straight forward.
<SeanTAllen>
1. create an iso array of String
<SeanTAllen>
2. loop over your ref array
<SeanTAllen>
3. add each element from ref array to the iso array
<SeanTAllen>
4. consume iso array and return as val
<SeanTAllen>
you can't use Array.clone because right now, there's no way to get back something other than a ref when you clone a ref from it
<_andre>
i think a clone_as_val() function would be useful in the stdlib :)
<SeanTAllen>
as iso would be more useful, if its iso it can become anything
<SeanTAllen>
including val
<SeanTAllen>
do you feel like you have enough info to make progress _andre ?
<_andre>
yes, thanks!
<SeanTAllen>
awesome
<_andre>
btw, in my attempts to understand capabilities, i generated a lot of nonsense code, including something that triggered an assertion failure in ponyc
<_andre>
should i report this on github?
<_andre>
i managed to create something small that reproduces it