Re: Buf to Str

2021-06-09 Thread ToddAndMargo via perl6-users
On 6/8/21 9:34 PM, Paul Procacci wrote: Hopefully a pretty quick question GIven the following: my Buf $b .= new([72, 105, 0, 32, 97, 103, 97, 105, 110, 0]); say $b.decode; I would expect this to print 'Hi'. Instead it prints 'Hi again'. https://docs.raku.org/type/Buf#(Blob)_method_decode

Re: Buf to Str

2021-06-09 Thread Matthew Stuckwisch
Another way to do this could be to just create your own method. my method decode-c(Blob:) { self.subbuf(^self.first(0,:kv)[0]).decode } my $string-with-zero = Buf.new: 72, 101, 108, 108, 111, 0, 32, 119, 111, 114, 108, 100, 33; say $string-with-zero.decode; say $string-with-zero. The output of

Re: Notes/Questions about Leon Timmermans's talk

2021-06-09 Thread Elizabeth Mattijsen
> On 9 Jun 2021, at 12:48, Marc Chantreux wrote: > > hello, > > I just saw this and it's very good > > https://www.youtube.com/watch?v=elalwvfmYgk > > The features he picked are indeed things i really like in raku > and i learned some interesting details. Other details are still > bugging me

Re: Buf to Str

2021-06-09 Thread Paul Procacci
>> That C null is an int pointer, longer than a single byte. Yep, no arguments there. ;) On Wed, Jun 9, 2021 at 11:06 AM yary wrote: > That C null is an int pointer, longer than a single byte. > > On Wed, Jun 9, 2021 at 11:04 AM Paul Procacci wrote: > >> Not sure about the 80's, my

Re: Buf to Str

2021-06-09 Thread Paul Procacci
That does help some Daniel. I do in fact need to work with C style null terminated strings because when passing a structure to an underlying OS via nativecall, you have no control over what the underlying libraries want. An Example: class myStruct is repr('CStruct') { HAS int8 @.Path[MAX_PATH]

Re: Buf to Str

2021-06-09 Thread yary
That C null is an int pointer, longer than a single byte. On Wed, Jun 9, 2021 at 11:04 AM Paul Procacci wrote: > Not sure about the 80's, my programming endeavors started in the 90's. > NUL doesn't exist in the C standard so I have no comment on it. > The C standard defines that 0 cast to the

Re: Buf to Str

2021-06-09 Thread Paul Procacci
Not sure about the 80's, my programming endeavors started in the 90's. NUL doesn't exist in the C standard so I have no comment on it. The C standard defines that 0 cast to the type void * is both a null pointer and a null pointer constant. I always have and most likely will continue using 0 over

Re: Buf to Str

2021-06-09 Thread Daniel Sockwell
Hi Paul, If you _do_ want/need to work with C-style null-terminated strings, you can use the (core) NativeCall library. So, given your example: > my Buf $b .= new([72, 105, 0, 32, 97, 103, 97, 105, 110, 0]); > say $b.decode; > I would expect this to print 'Hi'. > > Instead it prints 'Hi

Re: Buf to Str

2021-06-09 Thread yary
>From my early 1980s days learning programming, ASCII CHR 0 is not null, it is NUL (can type it as ctrl-@) it's a control character much like the others. Ctrl-G BEL, it was fun putting you in file names... On Wed, Jun 9, 2021, 9:56 AM Paul Procacci wrote: > >> But yeah, the Str class in Raku

Re: Buf to Str

2021-06-09 Thread Paul Procacci
>> But yeah, the Str class in Raku is much more than a C-string. Got it. Thanks Elizabeth. On Wed, Jun 9, 2021 at 6:45 AM Elizabeth Mattijsen wrote: > > On 9 Jun 2021, at 06:34, Paul Procacci wrote: > > > > Hopefully a pretty quick question > > > > GIven the following: > > > > my Buf $b

Notes/Questions about Leon Timmermans's talk

2021-06-09 Thread Marc Chantreux
hello, I just saw this and it's very good https://www.youtube.com/watch?v=elalwvfmYgk The features he picked are indeed things i really like in raku and i learned some interesting details. Other details are still bugging me so i have some questions there: A. if x -> $y with // For exemple,

Re: Buf to Str

2021-06-09 Thread Elizabeth Mattijsen
> On 9 Jun 2021, at 06:34, Paul Procacci wrote: > > Hopefully a pretty quick question > > GIven the following: > > my Buf $b .= new([72, 105, 0, 32, 97, 103, 97, 105, 110, 0]); > say $b.decode; > > I would expect this to print 'Hi'. > Instead it prints 'Hi again'. > >

Re: Buf to Str

2021-06-09 Thread ToddAndMargo via perl6-users
On 6/8/21 11:32 PM, ToddAndMargo via perl6-users wrote: Hi Paul, In "C", a chr(0), also called a "null" is a string terminator.  In Raku, the terminator is in the accompanying structure (hidden from you), when says long the string is. My guess as to what is happening is that the decode

Re: Buf to Str

2021-06-09 Thread ToddAndMargo via perl6-users
On 6/8/21 9:34 PM, Paul Procacci wrote: Hopefully a pretty quick question GIven the following: my Buf $b .= new([72, 105, 0, 32, 97, 103, 97, 105, 110, 0]); say $b.decode; I would expect this to print 'Hi'. Instead it prints 'Hi again'. https://docs.raku.org/type/Buf#(Blob)_method_decode