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 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 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>
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
<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!
<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