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
Dyserna__ has quit [Remote host closed the connection]
runehog has quit [Ping timeout: 250 seconds]
c355e3b has quit [Quit: Connection closed for inactivity]
runehog has joined #ponylang
njbartlett has joined #ponylang
njbartlett has quit [Quit: njbartlett]
njbartlett has joined #ponylang
njbartlett has quit [Client Quit]
mcguire1 has quit [Ping timeout: 250 seconds]
njbartlett has joined #ponylang
njbartlett has quit [Quit: njbartlett]
mankyKitty has quit [Ping timeout: 258 seconds]
TheMue has quit [Ping timeout: 258 seconds]
TheRealMue has joined #ponylang
njbartlett has joined #ponylang
mankyKitty has joined #ponylang
njbartlett has quit [Quit: njbartlett]
njbartlett has joined #ponylang
montanonic has quit [Remote host closed the connection]
graaff has joined #ponylang
njbartlett has quit [Quit: njbartlett]
montanonic has joined #ponylang
<emilbayes> How do I allocated a 32 byte sequence and fill bytes from a string at a given offset?
<emilbayes> I tried something like Array[U8].create(32).insert("Hello World!") which I guess is a bit weird of me
<doublec> emilbayes: at a given offset of the string, or a given offset of the array?
<emilbayes> Well, I'm not entirely sure how to express myself. I want something like a 32 byte buffer and I want to write a sequence of bytes at an offset in the most concise / elegant way possible
<doublec> emilbayes: note that 'create(32)' creates an array of length zero, but space for 32 bytes preallocated
<emilbayes> Arr ok
<doublec> emilbayes: you might want '.init(0, 32)' which creates a length 32 array filled with 0.
<emilbayes> doublec: Nice thanks! Is there a handy way to write the sequence of bytes?
<doublec> emilbayes: you probably want 'copy_to'
<doublec> emilbayes: source_array.copy_to(dst_array, source_index, dst_index, length)
<emilbayes> doublec: Thanks will try that
<doublec> emilbayes: you can get an Array[U8] from a String with the 'array' method.
<doublec> emilbayes: so maybe, "foo".array().copy_to(...)
<emilbayes> Hmm, yeah. Am I going about this the right way? I need something that is a ReadSeq[U8] of length 32 bytes, and I was looking for the easiest way to do that
<doublec> emilbayes: what are you trying to do? ie. what's the high level overview of the problem.
<emilbayes> I'm having a go at my first pony PR
<emilbayes> sodium expects a 32 byte seed
<emilbayes> I want to just write some of the bytes and the easiest way I thought would be to use a string but maybe not
<emilbayes> I keep using the word buffer, but I'm not sure that even makes sense
<doublec> emilbayes: I'd use an Array[U8]
<emilbayes> doublec: How would you fill it? put it in a variable and use copy_to?
<emilbayes> like you said above?
<doublec> emilbayes: What are you filling it with? Where does that data come from?
<emilbayes> doublec: arbitrary data. Just a string in this case
<doublec> emilbayes: yes, I'd use copy_to as above
<emilbayes> doublec: Alright, thank you!
<doublec> emilbayes: np. You can get a C pointer to the array easily to pass to sodium too
<emilbayes> doublec: the cstring method?
<doublec> emilbayes: yes
<emilbayes> doublec: Thanks for the help!
<doublec> np
<emilbayes> doublec: Hmm I get this error: Array[U8 val] ref is not a subtype of ReadSeq[U8 val]
<emilbayes> I thought Array was a ReadSeq
<doublec> emilbayes: what's the code giving the error?
<doublec> emilbayes: there's probably some viewtype adaption happening that prevents an Array[U8] val from having the interface a 'ReadSeq[U8 val] box' expects.
<doublec> s/Array[U8 val] ref/
<doublec> emilbayes: this is the type of thing I'm thinking would work http://pastebin.com/F2iC9b5x
<emilbayes> Hmm, it's because the function taking `a` is expecting `val` but `a` is `ref`. I guess I should go back to the tutorial and study again
<emilbayes> Did exactly what you did above :)
<doublec> emilbayes: the paste compiles and runs though
<emilbayes> doublec: Yes, but it's the function that is using `a` that's causing the issue
<emilbayes> I'm passing `a` to `new val create(buf: (ReadSeq[U8] iso | ReadSeq[U8] val)) =>`
<doublec> ah ok
<doublec> emilbayes: any reason why you need that particular interface?
<emilbayes> ReadSeq[U8]?
<doublec> emilbayes: the union type
<emilbayes> doublec: Is it wrong?
<doublec> emilbayes: I guess I'm confused what your actual code that is failing is doing
<doublec> emilbayes: since that create receives the source string
<doublec> emilbayes: whereas I though your code was receiving the destination array
<doublec> emilbayes: which can't be a ReadSeq - since the array needs to be written too
<emilbayes> doublec: Yeah, sorry if I'm expressing things completely wrong. This is a (non working) snippet of the test case I'm trying to write: http://pastebin.com/RfxiawKC
<doublec> emilbayes: which line of that fails?
<doublec> Oh, I see
<emilbayes> doublec: 12, 17, 22
<doublec> I get you now
<emilbayes> :D
<doublec> emilbayes: a cut down version gives this: Array[U8 val] ref is not a subtype of ReadSeq[U8 val] val: ref is not a subtype of val
<emilbayes> doublec: Yes exactly!
<doublec> emilbayes: which makes sense - you have a 'ref' Array and you're passing it to something that wants a 'val' or 'iso'
<doublec> emilbayes: so you should make your array an iso in the first place:
<emilbayes> Yes! I just don't know how to "recover" the capability
<doublec> emilbayes: let a: Array[U8 val] iso = recover iso Array[U8 val].init(0, 32) end
<emilbayes> Oh no
<emilbayes> argument not a subtype of parameter
<emilbayes> "Hello seeds!".array().copy_to(seed, 0, 0, 12)
<doublec> Actually it's more complex, let me quickly do an example
<emilbayes> doublec: Thank you
<doublec> emilbayes: http://pastebin.com/wpY9Mdnn
<doublec> emilbayes: inside the recover we create the array as a ref so we can copy_to into it. And we return it as an oiso.
<doublec> actually you don't need "consume a'" in the recover, you can just use "a'" as the return.
<emilbayes> Hmm, is that really the best way to go about this? Seems like a lot of work just to write some bytes to a buffer. Maybe it would be easier to just do something like in c `const char a[32] = {0x00, 0x32, ...}`
<emilbayes> Learning a lot about capabilities non the less!
<doublec> emilbayes: this is even simpler http://pastebin.com/HfRE2JKi
<doublec> emilbayes: since we can also use a 'val' we can just recover to val.
<doublec> emilbayes: which can be a one liner foo(recover val "foo".array().copy_to(Array[U8 val].init(0, 32), 0, 0, 2) end)
<doublec> 'copy_to' returns the destination array which is why that works
<emilbayes> Still quite a long one liner :p
<doublec> mostly due to the verbosity of recover
<doublec> foo".array().copy_to(Array[U8 val].init(0, 32), 0, 0, 2) is pretty understandable
<doublec> Copy the first two butes of "foo" into a new array of size 32 and return the array
<emilbayes> Yeah, I guess that's alright
<doublec> hah, the recover isn't needed
<doublec> foo("foo".array().copy_to(Array[U8 val].init(0, 32), 0, 0, 2))
<doublec> because copy_to returns the destination array using viewtype adaption - it returns it as a val already.
<emilbayes> viewtype adaption? O.o
<doublec> emilbayes: 'copy_to' is copy_to(dst: Array[this->A!], src_idx: USize, dst_idx: USize, len: USize): this->Array[A]^
<doublec> emilbayes: the "this->Array[A]" part a the end is viewpoint adaption.
<emilbayes> Oh, I haven't gotten to understand the this-> operator yet
<emilbayes> I'll have to look at that now
<doublec> emilbayes: it's mostly a generics thing
<emilbayes> Thanks for the help doublc
<emilbayes> arr
<doublec> emilbayes: I tried to explain it a bit here https://bluishcoder.co.nz/2016/05/04/bang-hat-and-arrow-in-pony.html
<emilbayes> cool, will read that!
<doublec> emilbayes: oops, I'm wrong. copy_to returns the source
<doublec> emilbayes: in this case the "foo"
<emilbayes> doublec: I was just going to say that I didn't get a 32 byte array :P
<doublec> What a pain
<doublec> Too used to array.copy_info("foo", 0, 0) type things
<doublec> Back to the long winded recover version
<emilbayes> This is getting really painful
<doublec> emilbayes: http://pastebin.com/ebSr2kqQ
<emilbayes> Really, I think I might just go with "Hello world! " which is 32 bytes
<emilbayes> doublec: I learnt a lot from this! But it definitely feels clunky
<doublec> Pity there's no Sting.pad function
montanonic has quit [Ping timeout: 244 seconds]
njbartlett has joined #ponylang
njbartlett has quit [Quit: njbartlett]
njbartlett has joined #ponylang
njbartlett has quit [Quit: njbartlett]
njbartlett has joined #ponylang
njbartlett has quit [Quit: njbartlett]
njbartlett has joined #ponylang
<SeanTAllen> Perhaps someone will PR or RFC a String.pad soon.
<SeanTAllen> runehog: that's an excellent question. you can do any of the following: bring it up on pony dev mailing list, join the sync call wednesday and bring it up, open an RFC moving it to its own package. realisticall, a RFC is overkill, either of the other two would suffice.
<SeanTAllen> emilbayes: sorry for your pain. String is one of the classes that most needs a rewrite. It can be a pain to use which is unfortunate as it is one of the first that most people encounter. Anything you find that could be an improvement, you can bring up on the dev mailing list or via RFC to get more discussion going. We welcome thoughts on improving the
<SeanTAllen> String class (we have many ideas but they aren't moving forward yet). Also, if you need help and there's no one here in the future, drop a note on the user mailing list and I'll be happy to help. I tend to do drivebys on the IRC. Fortunately, doublec was around to help you.
<SeanTAllen> On a slightly related note, we are getting an awesome Vector class one Luke's simple value dependent types work is merged to master. You can learn more about those from his VUG presentation: https://vimeo.com/175746403
<emilbayes> That's exactly the video I saw!
<emilbayes> Looking forward to that
njbartlett has quit [Quit: njbartlett]
njbartlett has joined #ponylang
njbartlett has quit [Quit: njbartlett]
njbartlett has joined #ponylang
_whitelogger has joined #ponylang
njbartlett has quit [Quit: njbartlett]
njbartlett has joined #ponylang
c355e3b has joined #ponylang
<SeanTAllen> Me too. I love a good vector
mytrile has joined #ponylang
<mytrile> Damn it
<mytrile> Just updated pony to 0.3.0 via homebrew but still getting this "couldn't locate this path" error
<mytrile> did a clean up, now its good
montanonic has joined #ponylang
mcguire1 has joined #ponylang
mytrile has quit [Quit: Connection closed for inactivity]
graaff has quit [Quit: Leaving]
montanonic has quit [Ping timeout: 244 seconds]
unbalanced has joined #ponylang
unbalanced has quit [Client Quit]
montanonic has joined #ponylang
dynarr has quit [Quit: A merry Christmas to all, and to all a good night!]
dynarr has joined #ponylang
montanonic has quit [Ping timeout: 244 seconds]
johnnydoe has joined #ponylang
montanonic has joined #ponylang
montanonic has quit [Ping timeout: 250 seconds]
montanonic has joined #ponylang
johnnydoe has quit [Ping timeout: 264 seconds]
NhanH has quit [Ping timeout: 264 seconds]
jonrh_ has joined #ponylang
jonrh has quit [Ping timeout: 264 seconds]
emilbayes has quit [Ping timeout: 264 seconds]
jonrh_ is now known as jonrh
NhanH has joined #ponylang
emilbayes has joined #ponylang
darach has quit [Ping timeout: 250 seconds]
darach has joined #ponylang
<doublec> nice job on the release! Good to have a more recent pony available for people.
bbhoss has quit [Ping timeout: 250 seconds]
NhanH has quit [Ping timeout: 260 seconds]
ericbmerritt has quit [Read error: Connection reset by peer]
adamkittelson has quit [Ping timeout: 244 seconds]
NhanH has joined #ponylang
adamkittelson has joined #ponylang
sigipa has quit [Ping timeout: 264 seconds]
ericbmerritt has joined #ponylang
bbhoss has joined #ponylang