jemc changed the topic of #ponylang to: Welcome! Please check out our Code of Conduct => https://github.com/ponylang/ponyc/blob/master/CODE_OF_CONDUCT.md | Public IRC logs are available => http://irclog.whitequark.org/ponylang | Please consider participating in our mailing lists => https://pony.groups.io/g/pony
pzel has joined #ponylang
<alexashka2> hi, another 4 liner I can't get to compile. This time converting an array from ref to val. What's wrong? Works for string, doesn't work for array: https://playground.ponylang.org/?gist=4a5a3adf0d9af011a8a94de780de0982
<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
<SeanTAllen> but
<SeanTAllen> note the "the elements themselves are cloned"
<SeanTAllen> because of that, that return type means its going to return something that cant be turned into a val
<SeanTAllen> with Array[U8] what you want to do is safe but we can't specialize methods on a generic by the type at this point
<SeanTAllen> string.clone returns:
<SeanTAllen> i'm not sure why the compiler is letting you do this:
<SeanTAllen> that should be a compilation error as `c` is a ref.
<SeanTAllen> it could be related to auto-recovery work that jemc did but i need to check with him
<SeanTAllen> for the string you really 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> btw, all that http stuff is probably going to get a new home soon alexashka2. see: https://github.com/ponylang/rfcs/pull/117
<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> SeanTAllen: ok this is where I left off - I haven't implemented the promise bit, I was just getting to it: https://playground.ponylang.org/?gist=a8a2d5afb8a3ac29b147c24a976dee7a
<alexashka2> regarding web frameworks - oh one step at a time. I have my hands full with the basics, haha :)
<SeanTAllen> you'd want something like this:
<SeanTAllen> i only tweaked the bits related to the _data
<alexashka2> SeanTAllen: right, and then the promise would consume it?
<SeanTAllen> o wait
<SeanTAllen> sorry one problem
<alexashka2> wait I'm talking nonsense, I'm parsing the string into json, THEN giving it to the promise :)
<SeanTAllen> needed to be `var _data` not `let _data`
<SeanTAllen> im not familiar with the API so i dont know why you need the promise but i trust that you did
<SeanTAllen> s/did/do/
<SeanTAllen> does the _data change make sense to you?
pzel has joined #ponylang
<alexashka2> SeanTAllen: I think so, it may not be necessary I think, because I'm only using it within the class instance
<alexashka2> so a ref will do I believe?
<SeanTAllen> no
<alexashka2> but for the sake of not cloning, iso is better?
<SeanTAllen> yes
<alexashka2> ya, let me ask you one last thing: isnt' that what trn is for? But the compiler told me I cant' have a field of type trn
<SeanTAllen> iso and trn will let you have a mutable copy of a thing that can be turned into an immutable thing without copying
<SeanTAllen> trn is like iso but only for locals, you can use iso in the same way as trn but trn indicates that you intended it to be transitional
<alexashka2> or rather, when I try to consume the trn field, it complains, let me do a playground
<SeanTAllen> you cant consume a field
<SeanTAllen> you have to do a destructive read
<alexashka2> SeanTAllen: right, so if I can't consume a field, what good is allowinga field to have trn type at all?
<alexashka2> SeanTAllen: this is what I'm thinking - can destructive read help this scenario? https://playground.ponylang.org/?gist=79bcd01cf48cbf572f649780cb60fbf4
<SeanTAllen> ive written a lot of pony and almost never use `trn`
<SeanTAllen> in your example, i'd use `iso`
<alexashka2> SeanTAllen: right, the example you have, it's almost as if we're doing cleverness for it's own sake, without any apparent benefit :)
<SeanTAllen> well
<SeanTAllen> that basic pattern
<alexashka2> ugh, except with iso, we're stuck using the same strange pattern to be able to pass it to the other actor it seems!
<SeanTAllen> i do that a lot
<SeanTAllen> but with iso
<SeanTAllen> because again
<alexashka2> we're creating an extra variable just to be able to pass an iso through!
<SeanTAllen> lots of network programming
<alexashka2> that can't be right... this is how you pass iso's between actors all the time? by creating old_field = destructive read every time?
<SeanTAllen> too much context missing
<SeanTAllen> is the iso a field? if yes, then yes.
<SeanTAllen> if no, then no
pzel has quit [Ping timeout: 260 seconds]
<alexashka2> you're right regarding context, haha that's the general theme for all my questions :)
jemc has quit [Ping timeout: 260 seconds]
<SeanTAllen> there's that pattern in TCPConnection
<alexashka2> SeanTAllen: right, it's because fields can't be 'empty', so this is necessary
<SeanTAllen> yes
jaro has quit [Ping timeout: 252 seconds]
jemc has joined #ponylang
pzel has joined #ponylang
pzel has quit [Ping timeout: 245 seconds]
pzel has joined #ponylang
acarrico has quit [Ping timeout: 248 seconds]
SenasOzys has quit [Ping timeout: 252 seconds]
pzel has quit [Ping timeout: 245 seconds]
m6w6 has quit [Quit: ZNC - http://znc.in]
m6w6 has joined #ponylang
<alexashka2> hi folks, how do I get a Promise that expects a String iso going? I can't get the poor thing to compile: https://playground.ponylang.org/?gist=4b2425370945d0cbea3515fa27de7971
<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]
SenasOzys has quit [Ping timeout: 240 seconds]
SenasOzys has joined #ponylang
Sargun_ is now known as Sargun
vaninwagen has joined #ponylang
acarrico has quit [Ping timeout: 245 seconds]
gokr has quit [Ping timeout: 256 seconds]
user10032 has joined #ponylang
_andre has quit [Quit: leaving]
acarrico has joined #ponylang
user10032 has quit [Quit: Leaving]
vaninwagen has quit [Quit: WeeChat 2.1]
acarrico has quit [Ping timeout: 245 seconds]
jemc has quit [Ping timeout: 240 seconds]
pzel has joined #ponylang