<alexashka2>
from type signatures. I can see that String clone returns iso^ and array returns Array[this->A!]^. I'm assuming this means array returns a ref^, and hence it can't get converted to a val? If that's the case, how does one have a mutable array and then turn it into a val later on?
endformationage has quit [Ping timeout: 245 seconds]
<SeanTAllen>
what does the error say?
<alexashka2>
can't call method on non-sendable object inside of a recover expression let dd = recover val cc.clone() end
<alexashka2>
if you run the playground it'll tell you :)
<SeanTAllen>
i know
<SeanTAllen>
1. you dont need recover there.
<SeanTAllen>
you can pass a ref to recover.
<SeanTAllen>
its not allowed.
<SeanTAllen>
the return types for string and array are different
<SeanTAllen>
if we could specialize on type then you could do what you want
<alexashka2>
ok well help me work thorugh this scenario - I make a network request - I get back a chunk of json. I am assuming there could be multiple chunks, so I append them to a ByteSeq, so it's a ref. Then at some point I want to convert the ByteSeq ref to val, so that I can convert it to a String, to then convert it to Json. How do I do that?
<alexashka2>
this seems like a rather common scenario. The ref to val business would go away if I can be sure that I am only ever getting a single chunk, then I don't need to play the conversion game, but it seems like a reasonable enough scenario
<SeanTAllen>
have you looked at the Buffered reader?
<alexashka2>
hm, no?
<SeanTAllen>
thats one option
pzel has quit [Ping timeout: 252 seconds]
<SeanTAllen>
ByteSeq is either String or Array[U8]
<SeanTAllen>
i take it you are using Array[U8] ?
<alexashka2>
well I don't know - I do a match to see which one I am getting from hte network. I am using the HTTPClient library and making a request
<SeanTAllen>
you could have a mutable string and keep appending to it then clone that string when you want
<alexashka2>
the url I provided, the pattern match tells me it's an Array [U8]
<SeanTAllen>
and you can append an Array[U8] onto a String
<SeanTAllen>
so let me understand, you have code that gets a ByteSeq and you are matching on Array[U8] and String to do something with it?
<SeanTAllen>
if yes, there's no reason to do that
<alexashka2>
SeanTAllen: right, I hadn't realized I can append an Array to a String
<alexashka2>
that'd solve my ref to val troubles
<alexashka2>
SeanTAllen: I was going the other way, of appending to Array[U8] and then converting to String later
<SeanTAllen>
so you are collecting up some bytes that represent json and when you have the full amount, you use that to create a json object?
<alexashka2>
it seems like either option shouldn't be hard to do, but in reality it seems the String option is possible, while Array is not at all
<alexashka2>
SeanTAllen: yes exactly
<SeanTAllen>
ok
<SeanTAllen>
so this mutable ref of the data, you are then zeroing it out after you clone it?
<alexashka2>
I hadnt' gotten that far, I was stuck on the data -> json bit
<SeanTAllen>
ok well
<SeanTAllen>
if that was your plan, there's a better way
<alexashka2>
I'm all ears
<SeanTAllen>
did you read the "destructive read" part of the tutorial?
<alexashka2>
I've been through the entire tutorial. Ya I'm aware of iso
<SeanTAllen>
hmmm actually...
<SeanTAllen>
that might not work for you
<SeanTAllen>
depends
<SeanTAllen>
how do you know that you reached the end of your json?
<alexashka2>
SeanTAllen: the finished() method gets called. This is an implementation of the HTTPHandler, I am filling in the methods
<SeanTAllen>
ah ok so then
<SeanTAllen>
yes destructive read would work
<SeanTAllen>
you have an iso field for your data you are reading
<SeanTAllen>
then in your finished something like
<SeanTAllen>
my_json = _building_json = String
<SeanTAllen>
and you can consume your my_jason to parse and get your json
<SeanTAllen>
that's going to lower the number of allocations you are doing
<SeanTAllen>
but you dont have to
<alexashka2>
ya, i asked for an example of json parsing earlier in the day - I'm sure you have some in code you've written, does anythign coem to mind that I can take a look at?
<SeanTAllen>
its just a small optimization
<alexashka2>
parsing combined with a network request I should say :)
<SeanTAllen>
i dont have any code that ive written that does json parsing
<SeanTAllen>
i tend to deal in binary protocols
<alexashka2>
ah, makes sense
<SeanTAllen>
can you post a playground of your notifier and i can fill in with code as best as i can?
<SeanTAllen>
or i can create a bs one
<alexashka2>
let me try and clean up the one I have so that it's comprehensible one minute
<SeanTAllen>
also for web-dev, you might want to see if you can get theodus to bring jennet up to date or get someone interested in bringing it up to date: https://github.com/Theodus/jennet
<alexashka2>
if I comment out this line, it's fine, so what gives? let promise = Promise[String].>next[None](obj)
<jemc>
a Promise can't have an `iso` type as the value type, because you can attach multiple fulfill handlers to a Promise, and each one will receive the value
<jemc>
that is, there can only be one `iso` reference to an object at a time, so it can't be passed to multiple different functions at the same time
<alexashka2>
jemc: ya, I thought someone would say that... So that makes promises less powerful than passing a tag ref to an actor
<alexashka2>
because let's say I make a network request, get me some json, I'd like to inspect it, modify a couple of fields and send it somewhere else. If promises can only pass immutable data around, I'd be making copies to convert to a mutable data structure?
<jemc>
there's an unfinished RFC to add an iso-compatible promise to the promises package
<alexashka2>
right, looks like I'm reinventing the wheel. *Shakes fist at undocmented limitations of the Promise library*
jemc has quit [Ping timeout: 245 seconds]
vaninwagen has joined #ponylang
gokr has joined #ponylang
gokr has quit [Quit: Leaving.]
gokr has joined #ponylang
_andre has joined #ponylang
acarrico has joined #ponylang
acarrico has quit [Max SendQ exceeded]
acarrico has joined #ponylang
acarrico has quit [Ping timeout: 256 seconds]
SenasOzys has joined #ponylang
acarrico has joined #ponylang
vaninwagen has quit [Ping timeout: 240 seconds]
vaninwagen has joined #ponylang
vaninwagen has quit [Ping timeout: 245 seconds]
jemc has joined #ponylang
vaninwagen has joined #ponylang
SenasOzys has quit [Ping timeout: 245 seconds]
SenasOzys has joined #ponylang
endformationage has joined #ponylang
vaninwagen has quit [Ping timeout: 240 seconds]
gokr has quit [Ping timeout: 248 seconds]
vaninwagen has joined #ponylang
vaninwagen has quit [Ping timeout: 252 seconds]
vaninwagen has joined #ponylang
acarrico has quit [Ping timeout: 256 seconds]
acarrico has joined #ponylang
vaninwagen has quit [Ping timeout: 248 seconds]
vaninwagen has joined #ponylang
jaro has joined #ponylang
vaninwagen has quit [Ping timeout: 245 seconds]
SenasOzys has quit [Read error: Connection reset by peer]
SenasOzys__ has joined #ponylang
<dave24>
what does the v stand for in writev? values?
<SeanTAllen>
the name is taken from the corresponding c standard library functions write and writev
<SeanTAllen>
writev in the c call takes an iovec (io vector) instead of a buffer.
pzel has joined #ponylang
<dave24>
ah, thanks.
jemc has quit [Read error: Connection reset by peer]
<SeanTAllen>
you're welcome
pzel has quit [Ping timeout: 252 seconds]
<dave24>
If I get a `char *` from an ffi call that I am responsible for `free`ing, can I still use it in pony as a `String` without copying somehow?
<SeanTAllen>
you can use the "from_cpointer" constructor on String. but to use that, you need to have given the ffi function the char * buffer and used @pony_alloc to allocate the memory.
<SeanTAllen>
otherwise, yes you are responsible for freeing it and you can't use with String without copying.
<dave24>
Alright, thanks again.
gokr has joined #ponylang
<SeanTAllen>
you are welcome
<SeanTAllen>
if you search for usages of from_cpointer in the standard library, you can see how it is used.
pzel has joined #ponylang
<dave24>
Yeah, unfortunately the c library returns a pointer it allocated.
<dave24>
Is dispose` called when an object is garbage collected? Or only at the end of a `with`
pzel has quit [Ping timeout: 260 seconds]
<SeanTAllen>
so you can do what we do in wallaroo
<SeanTAllen>
create a pony object that owns the pointer
<SeanTAllen>
and when the pony object is freed, free the pointer
<SeanTAllen>
see how PyData works in Wallaroo
<dave24>
Hah, I was already doing almost the same thing. I will use `_final`. Thanks!
<aturley>
dave24 yeah sean and i can answer all your questions about horrifying things that happen when you try to manage memory across languages
<dave24>
monkaS
<SeanTAllen>
hehe
<SeanTAllen>
o god
pzel has joined #ponylang
pzel has quit [Ping timeout: 260 seconds]
pzel has joined #ponylang
jemc has joined #ponylang
<SeanTAllen>
We certainly can aturley
pzel has quit [Ping timeout: 268 seconds]
SenasOzys has joined #ponylang
SenasOzys__ has quit [Read error: Connection reset by peer]