NativeCall questions

2020-05-08 Thread David Santiago
Hello, I'm porting some personal perl5 scripts to Raku, and one of those scripts is using Inline::C. The inline::c code would contain a function with the signature: AV* encode(unsigned char* data, size_t data_size) Description of the parameters on the original perl script: data -> binary

Re: NativeCall questions

2020-05-08 Thread Timo Paulssen
Hi David, the first thing that catches my eye is that your struct and the class have the members switched around, so you're already almost guaranteed to read a bogus pointer when trying to get the data. Also, please note that returning structs directly, or passing structs directly, as arguments

Re: NativeCall questions

2020-05-08 Thread David Santiago
Thanks for the help. > EncodedData *encode(unsigned char* data, size_t data_size) > and return > Also your struct and CStruct are defining the contents in the reverse > order. They must > match up exactly. > I did those two changes: """ EncodedData* ed = malloc(sizeof(EncodedData)); ed->data

Re: NativeCall questions

2020-05-08 Thread Curt Tilmes
On Fri, May 8, 2020 at 8:49 AM David Santiago wrote: > EncodedData* ed = malloc(sizeof(EncodedData)); > ed->data = encbuffer; > ed->crc32 = crc32; > return ed; You're returning a pointer to encbuffer -- make sure the storage for that is kept around somewhere. If it is passed in from Raku,

Re: Raku -npe command line usage

2020-05-08 Thread Brad Gilbert
The 「@i」 is defined within the 「BEGIN」 block, so it is scoped to the 「BEGIN」 block. If you didn't want that, don't use a *block* with 「BEGIN」. BEGIN my @i; Also you wrote the 「if」 wrong. There shouldn't be a 「;」 before the 「if」. You also don't need to use 「$_ ~~ 」 with 「/^WARN/」 as that

Re: Raku -npe command line usage

2020-05-08 Thread William Michels via perl6-users
On Fri, May 8, 2020 at 5:16 AM WFB wrote: > > Hi, > > I am trying to write an one-liner to go through all lines in a logfile and > look for an certain key word, store the line and sort them before printing > them out. > > My approach was: > raku -ne "BEGIN {my @i }; @i.push($_); if $_ ~~

Raku -npe command line usage

2020-05-08 Thread WFB
Hi, I am trying to write an one-liner to go through all lines in a logfile and look for an certain key word, store the line and sort them before printing them out. My approach was: raku -ne "BEGIN {my @i }; @i.push($_); if $_ ~~ /^WARN/; END { @i.sort.say }" That does not work because @i does

Re: NativeCall questions

2020-05-08 Thread Curt Tilmes
On Fri, May 8, 2020 at 6:44 AM David Santiago wrote: > > I'm porting some personal perl5 scripts to Raku, and one of those > scripts is using Inline::C. > [...] > Why? How do i fix it? I haven't tried all of this, but the first thing that leaps out is that repr('CStruct') is not a struct -- it

Re: Raku -npe command line usage

2020-05-08 Thread yary
ooh neat! I didn't know. Indeed this works. Thanks Sean! raku -ne'push my @i: $_ if .starts-with: q[WARN]; END .say for @i' sample.log -y On Fri, May 8, 2020 at 1:04 PM Sean McAfee wrote: > On Fri, May 8, 2020 at 6:53 AM Brad Gilbert wrote: > >> So together that would be: >> >> raku

Re: Raku -npe command line usage

2020-05-08 Thread yary
Ooops forgot the sort... let's golf with the hyper-operator again... raku -ne'push my @i: $_ if .starts-with: q[WARN]; END @i.sort>>.say' sample.log -y On Fri, May 8, 2020 at 1:10 PM yary wrote: > ooh neat! I didn't know. Indeed this works. Thanks Sean! > > raku -ne'push my @i: $_ if

Re: Raku -npe command line usage

2020-05-08 Thread William Michels via perl6-users
Maybe? perl6 -e 'lines() ==> grep /^WARN/ ==> sort() ==> join("\n") ==> say();' HTH, Bill. On Fri, May 8, 2020 at 9:10 AM Fernando Santagata wrote: > > raku -e'.say for lines() ==> grep(/^WARN/) ==> sort' sample.log > > is not very satisfying because for the "for" which breaks the flow. >

Re: NativeCall questions

2020-05-08 Thread David Santiago
Thanks for the information! Have a great weekend! Best regards, David Santiago Tobias Boege escreveu no dia sexta, 8/05/2020 à(s) 15:52: > > On Fri, 08 May 2020, David Santiago wrote: > > I also noticed that although my data string is defined as > > CArray[uint8], when i loop through the

Re: NativeCall questions

2020-05-08 Thread David Santiago
I also noticed that although my data string is defined as CArray[uint8], when i loop through the array, the values are signed ints: say $_ for $ed.data[0..10]; output: -98 -110 -109 -99 74 -109 -99 74 -105 -93 74 Is it possible to not "sign" them? Regards, David Santiago Curt Tilmes

Re: Raku -npe command line usage

2020-05-08 Thread yary
All good ideas so far, in the "more than one way to do it" spirit, can use "state" instead of "my", since state only initializes 1st time it's hit. raku -ne 'state @i;@i.push($_) if .starts-with(q[WARN]); END .say for @i.sort' sample.log Or adapting Brad's answer with the feed operator for

Re: NativeCall questions

2020-05-08 Thread Tobias Boege
On Fri, 08 May 2020, David Santiago wrote: > I also noticed that although my data string is defined as > CArray[uint8], when i loop through the array, the values are signed > ints: > > say $_ for $ed.data[0..10]; > > output: > > -98 There is an old open bug report about this:

Re: Raku -npe command line usage

2020-05-08 Thread Fernando Santagata
raku -e'.say for lines() ==> grep(/^WARN/) ==> sort' sample.log is not very satisfying because for the "for" which breaks the flow. OTOH this raku -e'lines().grep(/^WARN/).sort».say' sample.log doesn't use the feed operator and this raku -e'lines() ==> grep(/^WARN/) ==> sort() ==> say()'

Re: Raku -npe command line usage

2020-05-08 Thread yary
I like this formulation Fernando posted (removed a set of parens not needed with method calls) raku -e'lines.grep(/^WARN/).sort».say' sample.log It is clean, all left-to-right, and doesn't use "map" for its side-effects only. Putting the feed operator back in where it would work–have to keep

Re: Raku -npe command line usage

2020-05-08 Thread Sean McAfee
On Fri, May 8, 2020 at 6:53 AM Brad Gilbert wrote: > So together that would be: > > raku -ne 'BEGIN my @i; @i.push($_) if /^WARN/; END .say for @i.sort' > Or alternately the main body of the loop can be written: (my @i).push($_) if /^WARN/; Or even: push my @i: $_ if /^WARN/;

Re: Raku -npe command line usage

2020-05-08 Thread yary
> perl6 -e 'lines() ==> grep /^WARN/ ==> sort() ==> join("\n") ==> say();' that's neat too. This is showed me that I didn't have a clear grasp of the feed operator ==> vs the hyper-operator >> Now I have learned/internalized that the feed operators pass along the entire sequence (list?),

Re: Raku -npe command line usage

2020-05-08 Thread Fernando Santagata
On Fri, May 8, 2020 at 6:10 PM Fernando Santagata wrote: > raku -e'lines() ==> grep(/^WARN/) ==> sort() ==> reduce({$^a ~ "\n" ~ > $^b}) ==> say()' sample.log > and the reduce call can be written more compactly: reduce({"$^a\n$^b"}) -- Fernando Santagata

Re: Raku -npe command line usage

2020-05-08 Thread William Michels via perl6-users
>Boring hard-to-read solution not using any of those > raku -e'.say for sort grep *.starts-with(q[WARN]),lines' sample.log Interesting! I don't think I've seen a comma used like that in a one-liner. Also a very fast solution (thanks Brad!). Presumably the ",lines" tells raku/perl6 to run the

Re: Raku -npe command line usage

2020-05-08 Thread Andy Bach
>> raku -e'lines() ==> grep(/^WARN/) ==> sort() ==> join("\n") ==> say()' >> sample.log > raku -e'lines() ==> grep(/^WARN/) ==> sort() ==> reduce({$^a ~ "\n" ~ $^b}) > ==> say()' sample.log So what does reduce() do differently than join() here? I was thinking weeding out duplicates but it

Re: Raku -npe command line usage

2020-05-08 Thread yary
The comma is more boring than that, it's simply separating the arguments to the sub "grep" - adding parend .say for sort grep( *.starts-with(q[WARN]), lines ) grep as a sub takes a routine as the 1st arg, and the list to grep through after. -y On Fri, May 8, 2020 at 7:28 PM William

Re: Raku -npe command line usage

2020-05-08 Thread WFB
Uh, just stand up and having 16 answers in my inbox :-) Thanks guys! The : mistake was because I did not copy instead I wrote it and put the : in there accidentally. The curly braces for the phasers was the issue. But I though phasers are written this way like IF clauses are. I already saw