Re: Is irc.libera.chat down?

2024-04-19 Thread David Santiago


Do you have any adblocker or any extension that blocks js? If so try to
disable it.

You can also use a dedicated client instead of the browser: 

www.mirc.com (for windows) or https://hexchat.github.io/ (for windows
and linux).


Regards,
David Santiago



A sex, 19-04-2024 às 03:09 -0700, Todd Chester via perl6-users
escreveu:
> > A sex, 19-04-2024 às 02:36 -0700, Todd Chester via perl6-users
> > escreveu:
> > > Hi All,
> > > 
> > > Is
> > >  https://kiwiirc.com/nextclient/irc.libera.chat/#raku
> > > down?
> > > 
> > > -T
> > 
> 
> On 4/19/24 03:03, David Santiago wrote:
>  >
>  > It works for me.
>  >
>  > Regards,
>  > David
>  >
> 
> Hi David,
> 
> The circle just goes round and round and after
> a while, it times out.
> 
> I tried both Firefox and Brave Browser.
> 
> I wonder if I got "quieted" or banned.   Is there
> a way to tell?
> 
> -T



Re: Is irc.libera.chat down?

2024-04-19 Thread David Santiago


It works for me.

Regards,
David


A sex, 19-04-2024 às 02:36 -0700, Todd Chester via perl6-users
escreveu:
> Hi All,
> 
> Is
>     https://kiwiirc.com/nextclient/irc.libera.chat/#raku
> down?
> 
> -T



Re: Help with %?RESOURCES variable

2023-04-17 Thread David Santiago


Hi Polgár

A seg, 17-04-2023 às 18:08 +0200, Polgár Márton escreveu:
> I think this is the classic case of ?-twigilled, "compile-time" 
> variables only being available in modules. It kind of forces you to 
> always have the pattern of: heavy-lifting in a module inside lib, and
> the script just uses the module.
> 



yes, that was the case. It works inside a module. I guess i have to
think differently on how to organize the code.

Thanks and best regards,
David Santiago



Help with %?RESOURCES variable

2023-04-17 Thread David Santiago


I'm trying to use the variable %?RESOURCES without success. It doesn't
work even when i install it locally with zef 

I have the following:

demanuel@archlinux test> cat resources/text.txt
This is my test file
demanuel@archlinux test> cat bin/run-me
sub MAIN(){
say %?RESOURCES{"text.txt"}.slurp(:close);
}
demanuel@archlinux test> cat META6.json 
{
  "raku" : "6.d",
  "name" : "Test",
  "api"  : "1",
  "auth" : "demanuel",
  "version" : "0.0.1",
  "description" : "my resources test",
  "authors" : [ "demanuel" ],
  "license" : "GPLv3",
  "resources": [
"text.txt"
  ]
}
demanuel@archlinux test> tree
.
├── bin
│   └── run-me
├── lib
├── META6.json
└── resources
└── text.txt

4 directories, 3 files
demanuel@archlinux test> raku -I ./lib bin/run-me
Nil
demanuel@archlinux test> zef install .
===> Testing: Test:ver<0.0.1>:auth:api<1>
===> Testing [OK] for Test:ver<0.0.1>:auth:api<1>
===> Installing: Test:ver<0.0.1>:auth:api<1>

1 bin/ script [run-me] installed to:
/home/demanuel/.raku/bin
demanuel@archlinux test> run-me
Nil
demanuel@archlinux test> 




Can someone point me what i'm doing wrong?

Best regards,
David Santiago



Re: for and ^ question

2021-01-01 Thread David Santiago




> for .1^...5 {print "$_\n";}
1.1
2.1
3.1
4.1


both still increments by 1

What am I doing wrong?



do this if you want to increment by 0.1:

say $_ for {0.1+$_}...^5



Best regards,

David Santiago



Re: Help with bug

2020-12-30 Thread David Santiago
Thanks for the explanation!

A December 30, 2020 3:28:24 PM UTC, Gianni Ceccarelli  
escreveu:
>On 2020-12-30 David Santiago  wrote:
>> Thanks! It's indeed much clearer. However i have a question, why the 
>> react on line 24?
>> 
>> The react there isn't required right?
>
>I think it is ☺ The code, without the debugging bits::
>
>react {
>whenever $channel -> $val {
>$conn.print("SENDING\r\n");
>
>react {
>whenever $conn-supply -> $line {
>if $line ~~ /^340/ {
>$conn.print("[$consumer]: value $val\r\n");
>} else {
>done;
>}
>}
>}
>}
>}
>
>I read this as:
>
>* loop as long as the channel has values, then exit
>* for each value in the channel:
>  * write to the server
>  * then loop reading from the server
>  * and exit *this inner loop* when you get a non-340 line
>
>Without the second ``react``, that ``done`` would exit the first ``react``,
>essentially terminating the client. There's probably a way to write
>the whole thing differently (keeping more explicit state, probably).
>
>Also, my understanding of ``whenever`` is that it's adding a hook into
>the event loop, and only leaving the surrounding ``react`` (or
>``supply``) will remove that hook (people who understand this better
>than I do: please correct me!). If that's true, adding a hook many
>times on the same condition looks wrong to me…
>
>-- 
>   Dakkar - 
>   GPG public key fingerprint = A071 E618 DD2C 5901 9574
>6FE2 40EA 9883 7519 3F88
>   key id = 0x75193F88
>

-- 
Sent from my phone with K-9 Mail. Please excuse my brevity.

Re: Help with bug

2020-12-30 Thread David Santiago



Às 14:43 de 30/12/20, Gianni Ceccarelli escreveu:

David: please look at my version of your code, I really think it's
clearer and simpler to work with, without the explicit ``.tap`` and
``.then`` (ok, I have a few ``.then``, but they're for debugging, they
don't affect the actual working of the program!)



Thanks! It's indeed much clearer. However i have a question, why the 
react on line 24?


The react there isn't required right?


Best regards,

David Santiago



Re: Help with bug

2020-12-30 Thread David Santiago


Hi!


Às 00:16 de 30/12/20, Elizabeth Mattijsen escreveu:

react, feels like a code smell to me.  An `await` will block the `react` block 
from processing other messages until the `await` returns.  Which feels like it 
is opening up a large window of dead-locking opportunities.



I changed the tap code to:

$channel.Supply.tap(->$val {
react {
whenever $conn.print("[$consumer] SENDING\r\n").Supply ->$result {
given $result {
when Kept {
whenever $conn.Supply ->$line {
print "[$consumer] $line";
if $line ~~ /^340/ {
whenever $conn.print("[$consumer]: value 
$val\r\n").Supply ->$r {
#note("[$consumer]: success") }
}else {
done;
}
}
}
}
}
}
}, done=>{say "[$consumer] DONE!";});


And it still hangs from time to time.


Best regards,
David Santiago



Re: Help with bug

2020-12-29 Thread David Santiago



Às 19:12 de 29/12/20, Gianni Ceccarelli escreveu:


I fear we've uncovered a hard-to-diagnose bug in
``IO::Socket::Async::SSL`` …



:-(


Thanks for the confirmation. Hopefully this can be used as a test case 
to help solve it.



Best regards,

David Santiago





Re: Help with bug

2020-12-29 Thread David Santiago



Hi!


Gianni Ceccarelli wrote:


 if $line ~~ /^340/ {
 await $conn.print("[$consumer]: value $val\r\n");
 } else {
 done;
 }

Notice that if the client receives a 340, it sends stuff back to the
server, and *does not exit*. You may want to add a ``done`` after that
``await``.


i don't want it to exit, i want it to keep reading from the socket until 
a "200" code happens.


Example:

Client -- "Sending data" --> Host

Client <  340 code  -- Host

Client  "value XXX" > Host

Client <--- 200 OK code  Host


Like you said it looks like it's getting stuck in a react, but why? :-|


Regards,

David Santiago





Help with bug

2020-12-29 Thread David Santiago


Hi!

I need some help in debugging my script. Sometimes it hangs and i don't 
know why.


There's a channel with all the values, and then i create N promises to 
take a value from the channel and to write it to a socket. (one producer 
with multiple consumers)



I'm attaching two scripts (client.raku and server.raku). The problem is 
in the client.raku (42 lines). The server.raku script is just a slightly 
modified version of  IO::Socket::Async::SSL documentation example.



To reproduce the problem first start the server (raku ./server.raku), 
and then run the client script (raku client.raku)



raku --version:

Welcome to Rakudo(tm) v2020.12-5-g3beb71cc9.
Implementing the Raku(tm) programming language v6.d.
Built on MoarVM version 2020.12-7-g6bf54d784.



Thank you,

David Santiago




#!/usr/bin/env perl6
use IO::Socket::Async::SSL;

sub MAIN() {
my $counter = 0;
react {
my %ssl-config =
certificate-file => 'server-crt.pem',
private-key-file => 'server-key.pem';
whenever IO::Socket::Async::SSL.listen('localhost', 4433, |%ssl-config) 
-> $conn {
say "Got conn!";
await $conn.print(get_fortune());
#await $conn.print(get_fortune());
whenever $conn -> $line {
say $line;
if $line.contains("SENDING") {
await $conn.print("340 OK {$counter++}\r\n");
} else {
await $conn.print("200 OK\r\n");
#$conn.close;
}
}
}
}
}

sub get_fortune(-->Str) {
return run('fortune', :out).out.slurp(:close)~"200 OK\r\n";
}

multi MAIN() {
my $channel = Channel.new();
$channel.send($_) for ^29;
$channel.close();
my @promises = do for ^4 -> $consumer {
start {

my $p = IO::Socket::Async::SSL.connect('localhost', 4433, insecure 
=> True);
my $conn;
# Read the MOTD
await $p.then: -> $prom {
$conn = $prom.result;
react whenever $conn.Supply.lines -> $line {
say "[$consumer] Intro: $line";
done if $line ~~ /^200/;
}
}

# Start consuming
$channel.Supply.tap(-> $val {
await $conn.print("SENDING\r\n").then: -> $promise {
react whenever $conn.Supply -> $line {
print "[$consumer] $line";
if $line ~~ /^340/ {
await $conn.print("[$consumer]: value $val\r\n");
} else {
done;
}

}
}
}, done=>{say "[$consumer] DONE!";});
say "[$consumer] TAP DONE!";
}
}

await Promise.allof(@promises);

say $_.status for @promises;
}



Re: How to unbuffer $*IN

2020-09-27 Thread David Santiago



Às 21:35 de 26/09/20, Gianni Ceccarelli escreveu:

On 2020-09-26 David Santiago  wrote:

I'm trying to capture key presses in the terminal and according to
raku's documentation i need to have $*IN unbuffered.

You have to tell the terminal to stop buffering (AFAIK Raku doesn't
buffer its inputs), which is not exactly trivial.

You may be better off using
https://modules.raku.org/dist/Term::ReadKey:cpan:JKRAMER (for example)


Thank you. I will take a look :-)


How to unbuffer $*IN

2020-09-26 Thread David Santiago



Hi!


I'm trying to capture key presses in the terminal and according to 
raku's documentation i need to have $*IN unbuffered.



Can someone point me in the right direction on how to do that?


Best regards,

David Santiago


Re: Help converting CArray[uint8] to Blob

2020-06-17 Thread David Santiago
Super!

That what i was looking for, i changed the code to:

my Instant $init = DateTime.now.Instant;
my Blob $blob = blob-from-carray($ed.data, size=>$ed.data_size);
say "bindata =  {DateTime.now.Instant-$init}";


Output:

Bindata= 0.00060054

So it passed from approx 1.1 to 0.0006 secs. That's quite an improvement!

Thank you so much.

Best regards,
David Santiago


Ralph Mellor  escreveu no dia quarta,
17/06/2020 à(s) 11:57:
>
> > Unfortunately, i get the error "Error 
> > X::AdHoc+{X::Await::Died}+{X::React::Died}: Don't know how many
> elements a C array returned from a library"
>
> I googled the error message and got a bunch of matches including this:
>
> https://stackoverflow.com/questions/51081475/getting-data-out-of-native-pointers
>
> This will show the way to maximize the speed because it minimizes
> the *number* of copy operations (to one) and expense of the copy
> (by making it native code).
>
> hth


Re: Help converting CArray[uint8] to Blob

2020-06-17 Thread David Santiago
Hi!


> $ed.data.head($ed.data_size)

Unfortunately, i get the error "Error
X::AdHoc+{X::Await::Died}+{X::React::Died}: Don't know how many
elements a C array returned from a library"

> > my uint8 @data = $ed.data[0..$ed.data_size-1].Array;
> > my Blob $bindata = Blob[uint8].new(@data);
>
> Afaict that's a total of five HLL element-by-element copies.
>
> I would expect this to work and be at least as fast and possibly a lot faster:
>
> my Blob $bindata .= new: $ed.data;


Because of the error above, i have to do:

my Blob $bindata .= new: $ed.data[^$ed.data_size];


which takes slightly more than 1 sec:
Bindata in 1.1679568

Btw, the size of the $ed.data_size is 750K.

Regards.
David Santiago

Ralph Mellor  escreveu no dia terça,
16/06/2020 à(s) 23:08:
>
> > my Data $ed = await $yenc_promise;
>
> The promise must initialize each element of the CArray[uint]. It looks
> pretty quick; I'm guessing it's low-level code doing that.
>
> > my uint8 @data = $ed.data[0..$ed.data_size-1].Array;
> > my Blob $bindata = Blob[uint8].new(@data);
>
> Afaict that's a total of five HLL element-by-element copies.
>
> I would expect this to work and be at least as fast and possibly a lot faster:
>
> my Blob $bindata .= new: $ed.data;
>
> hth


Re: Help converting CArray[uint8] to Blob

2020-06-16 Thread David Santiago
Thanks for the answer.

There's a slight performance improvement, but It still takes more than 1 second:

Code:

my Instant $init3 = DateTime.now().Instant;
#my Blob $bindata = Blob[uint8].new(@data);
my Blob $bindata = Blob[uint8].new($ed.data[^$ed.data_size]);
say "Bindata in {DateTime.now.Instant - $init3}";


Bindata in 1.1250962


:-(

Curt Tilmes  escreveu no dia terça, 16/06/2020 à(s) 21:40:
>
> On Tue, Jun 16, 2020 at 5:18 PM David Santiago  wrote:
> > my uint8 @data = $ed.data[0..$ed.data_size-1].Array;
> > my Blob $bindata = Blob[uint8].new(@data);
>
> Not absolutely sure, but it seems like you are copying the data twice.
> Try just
>
> my $bindata = Blob.new($ed.data[^$ed.data_size]);


Help converting CArray[uint8] to Blob

2020-06-16 Thread David Santiago
Hi!

Can i get some help in trying to improve the performance of the
following snippet?

The following code runs inside a react block that it's waiting for
channel values.

The promise $yenc_promise returns a CStruct with a CArray[uint] $data
and a uint8 $data_size.

my Instant $init = DateTime.now().Instant;
my Data $ed = await $yenc_promise;
say "Wating for promise in {DateTime.now.Instant - $init}";
my Instant $init2 = DateTime.now().Instant;
my uint8 @data = $ed.data[0..$ed.data_size-1].Array;
say "extracting in {DateTime.now.Instant - $init2}";
my Instant $init3 = DateTime.now().Instant;
my Blob $bindata = Blob[uint8].new(@data);
say "Bindata in {DateTime.now.Instant - $init3}";
say "Total = {DateTime.now.Instant-$init}";


So basically i'm extracting the CArray from the struct and then
converting it to a blob (so i can pass it to socket's write function)

When i run that code i get the following times:

Wating for promise in 0.000409156
extracting in 1.5681954
Bindata in 0.1248611
Total = 1.760531992

How can I improve that piece of code so it will take less than 1
second (against the 1.5 plus secs)?

And why if I put more promises running that same code, it gets way
slower? For example with five promises:

Wating for promise in 0.0003156
Wating for promise in 0.000339
Wating for promise in 0.0003339
Wating for promise in 0.000343
Wating for promise in 0.0003477
extracting in 3.2270008
extracting in 3.4507399
Bindata in 0.4428602
Total = 3.6717681
Bindata in 0.2877211
Total = 3.7541319
extracting in 3.88532646
extracting in 3.72995056
extracting in 3.90478574
Bindata in 0.16822032
Total = 4.0554652
Bindata in 0.15585004
Total = 3.90223033


Best regards,
David Santiago


Re: I need help with Config:INI

2020-05-30 Thread David Santiago
Hope this helps :-)

Basically the %hash variable contains another hash, and with spaces in
keys you cannot use them with "<>"


use Config;
use Config::INI;

my Str $IniFile = slurp "config.ini";
my %hash = Config::INI::parse($IniFile);

dd %hash;
print "\n";

for %hash.kv -> $section_name, %section_value  {

put "on $section_name we have: ";
for %section_value.kv -> $key, $value {
put "$key -> $value";
}

}

print "\n";

put %hash{'Backup paramters'};


ToddAndMargo via perl6-users  escreveu no dia
sábado, 30/05/2020 à(s) 00:02:
>
> Hi All,
>
> I an not figure out how to read the hash.
>
>
> ~~~ ini.test.pl6.ini ~
> # Raku: Confug::INI test INI
> # edit at your own risk
>
> [Backup paramters]
> target=B:\myDocsBackp\backup1
> partition=BACKUP
>
> [eMail]
> smtp=smtp.bozo.com
> address=b...@theclown.com
> port=587
> ~~~ /ini.test.pl6.ini ~
>
>
> ~~~ ini.test.pl6 ~
> #! /usr/bin/env raku
>
> #`{
>  # zef install Config
>  # zef install Config::INI
>
>
>
> https://github.com/tadzik/perl6-Config-INI/blob/master/lib/Config/INI.pm
>  line 45 starts documtation
>
>  use Config::INI;
>  my %hash = Config::INI::parse_file('config.ini');
>  #or
>  %hash = Config::INI::parse($file_contents);
>  say %hash<_>;
>  say %hash;
>
>  This module provides 2 functions: parse() and parse_file(), both taking
>  one C argument, where parse_file is just parse(slurp $file).
>  Both return a hash which keys are either toplevel keys or a section
>  names. For example, the following config file:
>
>  foo=bar
>  [section]
>  another=thing
>
>  would result in the following hash:
> }
> #   { '_' => { foo => "bar" }, section => { another => "thing" } }
>
>
> use Config;
> use Config::INI;
>
> my Str $IniFile = slurp "ini.test.pl6.ini";
> my %hash = Config::INI::parse($IniFile);
>
> dd %hash;
> print "\n";
>
> for %hash.kv -> $key, $value  { print "   hash<$key> = [$value]\n\n"; }
> print "\n";
> ~~~ /ini.test.pl6 ~
>
> ~ run the test 
> $ ini.test.pl6
>
> Hash %hash = {"Backup paramters" => ${:partition("BACKUP"),
> :target("B:\\myDocsBackp\\backup1")},
> :eMail(${:address("bozo\@theclown.com"), :port("587"),
> :smtp("smtp.bozo.com")})}
>
> hash = [partition BACKUP
> target  B:\myDocsBackp\backup1]
>
> hash = [address  b...@theclown.com
> port587
> smtpsmtp.bozo.com]
> ~ /run the test 
>
>
> How do I read the hash so I get section
> `[eMail]` `smtp`?  (Or any of the other values
> as well.)
>
>
> Many thanks,
> -T


Re: Help with grammar

2020-05-23 Thread David Santiago
Thank you all for your replies.

I was able to fix it and better understanding grammars :-)

Regards,
David Santiago

Patrick R. Michaud  escreveu no dia quinta,
21/05/2020 à(s) 21:05:
>
> On Thu, May 21, 2020 at 08:40:08PM +, David Santiago wrote:
> > Can someone explain me why my grammar isn't working? Unfortunately i
> > can't figure it out :-(
> >
> > |  headers
> > |  |  header
> > |  |  * MATCH "Proxy-Connection"
> > |  |  header-value
> > |  |  * MATCH "keep-alive\n"
> > |  |  crlf
> > |  |  * FAIL
> > |  * FAIL
> > * FAIL
> > Nil
>
> Notice how  is capturing the newline in "keep-alive\n"?  That 
> means there's not a newline for the <.crlf> subrule that follows, and thus 
> the match fails.
>
> Try changing "rule header-value" to be a "token" instead.  That will prevent 
> it from consuming any whitespace immediately following the + sequence. 
>  When I tried your script with header-value defined as a token, it got a lot 
> farther into the match:
>
>   $ rakudo test.raku
>   TOP
>   |  request-line
>   |  |  method
>   |  |  * MATCH "CONNECT"
>   |  |  request-uri
>   |  |  * MATCH "ssl.gstatic.com:443"
>   |  |  http-version
>   |  |  * MATCH "HTTP/1.1"
>   |  |  crlf
>   |  |  * MATCH "\n"
>   |  * MATCH "CONNECT ssl.gstatic.com:443 HTTP/1.1\n"
>   |  headers
>   |  |  header
>   |  |  * MATCH "Proxy-Connection"
>   |  |  header-value
>   |  |  * MATCH "keep-alive"
>   |  |  crlf
>   |  |  * MATCH "\n"
>   |  * MATCH "Proxy-Connection: keep-alive\n"
>   * MATCH "CONNECT ssl.gstatic.com:443 HTTP/1.1\nProxy-Connection: keep-"
>   Nil
>
>
> Personally, I would likely define  to be something more like
>
> token header-value { \N+ }
>
> which gets any sequence of non-newline characters, since some of the headers 
> coming afterwards contain spaces and characters which aren't part of .
>
> Pm


Help with grammar

2020-05-21 Thread David Santiago
Hi!

Can someone explain me why my grammar isn't working? Unfortunately i
can't figure it out :-(

Full script attached (42 lines) - the new lines in the script are
always only "\n"

The output:

TOP
|  request-line
|  |  method
|  |  * MATCH "CONNECT"
|  |  request-uri
|  |  * MATCH "ssl.gstatic.com:443"
|  |  http-version
|  |  * MATCH "HTTP/1.1"
|  |  crlf
|  |  * MATCH "\n"
|  * MATCH "CONNECT ssl.gstatic.com:443 HTTP/1.1\n"
|  headers
|  |  header
|  |  * MATCH "Proxy-Connection"
|  |  header-value
|  |  * MATCH "keep-alive\n"
|  |  crlf
|  |  * FAIL
|  * FAIL
* FAIL
Nil


It matches the request line's newline but not the headers.


Best regards,
David Santiago


test.raku
Description: Binary data


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 array, the values are signed
> > ints:
> >
> > say $_ for $ed.data[0..10];
> >
> > output:
> >
> > -98
>
> There is an old open bug report about this: 
> https://github.com/Raku/old-issue-tracker/issues/5859
>
> Best,
> Tobias


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  escreveu no dia sexta, 8/05/2020 à(s) 12:56:
>
> 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, you'll be fine as long as
> you hold on to the
> object on that side.  Otherwise you might need to allocate/copy it to make 
> sure.
>
> > class EncodedData is repr('CStruct') {
> > has CArray[uint8] $.data;
> > has uint32 $.crc32;
> > }
>
> That's fine, but CArray[uint8] is just a pointer -- it doesn't know
> how long the array
> it is pointing to is.  It either needs a sentinel at the end (like the
> Nul at the end of a
> C string), or a separate field with a size to figure that out.
>
> > Don't know how many elements a C array returned from a library
>
> yep
>
> Curt


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 = encbuffer;
ed->crc32 = crc32;
return ed;
"""

And i also changed the CStruct [1] to:

class EncodedData is repr('CStruct') {
has CArray[uint8] $.data;
has uint32 $.crc32;
}

I'm not getting a SIGSEGV anymore, however i'm now getting the
following error when trying to "say $_ for $ed.data.list":

Don't know how many elements a C array returned from a library
  in method elems at
/usr/share/perl6/core/sources/8660F65A7B3492675BB3B2058DB30E411A4C4E54
(NativeCall::Types) line 223
  in method list at
/usr/share/perl6/core/sources/8660F65A7B3492675BB3B2058DB30E411A4C4E54
(NativeCall::Types) line 226
  in sub MAIN at bin/uints.p6 line 15
  in block  at bin/uints.p6 line 3


I can access without problems $ed.crc32



[1] - if i change the data type to str i get the error: "String
corruption detected: bad storage type"


Best regards,
David Santiago


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 string (the value comes from read $FH)
data_size -> size in bytes of binary_string (the value comes from the
return of the read function)

And it would return an array with two values (a binary string and its crc32):

"""
SV* enc_string = newSVpv(buffer, 0);
SV* ret = sv_2mortal(newAV());
av_push(ret, enc_string);
SV* hex_string = newSVpv(hex_number, 0);
av_push(ret, hex_string);
free(hex_number);
return ret;
"""


Now for using it in raku, i'm changing  the return value to a struct:
typedef struct{
  unsigned char* data;
  uint32_t crc32;
} EncodedData;

So i changed the signature to:
EncodedData encode(unsigned char* data, size_t data_size)

And i'm returning the struct:
"""
EncodedData ed;
ed.crc32 = crc32;
ed.data = encbuffer;

return ed;
"""

Create a shared lib gcc -shared -olibmylib.so mylib.c

Now on my raku script i did:
"""
class EncodedData is repr('CStruct') {
has uint32 $.crc32;
has str $.data;
}

sub MAIN() {
sub encode(str $data, size_t $size --> EncodedData) is
native('lib/MyLib/libmylib.so') {*};
my EncodedData $ed = encode("this is my string that will be
encoded", "this is my string that will be encoded".chars );
say $ed.crc32.base(16);
say $ed.data;
}
"""
However this isn't working. Everytime i access "$ed.data" I'm getting
the following error:
"fish: 'raku bin/uints.p6' terminated by signal SIGSEGV (Address
boundary error)"

Why? How do i fix it?

Also the read method from the IO::Handle returns a Buf. I would like
to pass it directly to my C function. Is there any change in the
C/raku code i should do?
The data field from class EncodedData is type "str". Should it be
CArray[uint8] instead?

Best regards,
David Santiago


Re: Question about Blob and Buf

2020-02-11 Thread David Santiago
Hi Timo,

Thanks for the answer:

> the liskov substitution principle
I didn't knew about this principle. I'm now going down the rabbit hole.
Is this always the case for all the derived classes in Raku?

Best regards,
David Santiago

Timo Paulssen  escreveu no dia terça, 11/02/2020 à(s) 13:32:
>
> On 11/02/2020 14:14, David Santiago wrote:
> > Awesome explanation! Thank you!
> >
> > BTW,
> >> my Blob $read = Buf.new;
> > Is it creating either a Blob or a Buf?
> >
> > Regards,
> > David Santiago
>
>
> Hi David,
>
> "my Blob $read" will define the variable $read to 1) only accept things
> that typecheck against Blob, and 2) has the starting value of Blob (the
> Blob type object). Assigning Buf.new to it will assign the newly created
> Buf object to the variable, because a Buf Is-A Blob (by the liskov
> substitution principle, everywhere you can use a Blob, you can also use
> a Buf, but not the other way around).
>
> BTW, assigning to a variable with a % or @ sigil behaves differently.
> That is called "list assignment" and will actually use whatever type the
> % or @ variable is defined to use (Hash and Array by default) and store
> the values from the right-hand side of the assignment into the existing
> object. This is why "my %foo = SetHash.new()" will result in a
> Hash. For this example, you would want "my %foo is SetHash = "
> instead.
>
> Hope that clears things up
>   - Timo
>


Re: Question about Blob and Buf

2020-02-11 Thread David Santiago


Awesome explanation! Thank you!

BTW, 
> my Blob $read = Buf.new;

Is it creating either a Blob or a Buf?

Regards,
David Santiago


-- 
Sent from my Android device with K-9 Mail. Please excuse my brevity.


Re: Question about Blob and Buf

2020-02-11 Thread David Santiago
A 11 de fevereiro de 2020 12:03:19 CET, Simon Proctor  
escreveu:
>Ok I 100% don't know after trying this out :
>
>my Buf $a = Buf.new(1,2,3);
>my Blob $b = Blob.new(4,5,6);
>$a ~= $b;
>say $a
>
>And it worked fine so... I dunno.
>
>
>On Tue, 11 Feb 2020 at 11:00, Simon Proctor  wrote:
>
>> I think the problem is IO::Socket.read() returns a Blob not a Buf.
>>
>> ~ has a Buf, Buf variant :
>> https://docs.raku.org/language/operators#infix_~
>>
>> But not a Blob one. Buf does Blob but not vice versa.
>>
>> I think you need to transform the output from .read into a Buf if you want
>> to use the ~= how you want to.
>>
>> Would this work?
>> my Blob $read = Buf.new;
>> $read ~= Buf.new( $socket.read(1024) );
>>
>>
>> On Tue, 11 Feb 2020 at 10:46, Kevin Pye  wrote:
>>
>>>
>>> ~ works fine for concatenating Bufs; For example:
>>>
>>> my $a = Buf.new(1,2,3);
>>> my $b = $a ~ Buf.new(4,5,6)
>>>
>>> will assign correctly to $b.
>>>
>>> I can't work out what the problem is here, despite trying various
>>> combinations. Perhaps socket isn't really returning a Blob?
>>>
>>> Kevin.
>>>
>>> On Tue, 11 Feb 2020 at 21:01, JJ Merelo  wrote:
>>>
>>>> You are using ~, which stringifies. Bufs are not strings: you need to
>>>> decode them to concatenate it to a string. If what you want is to
>>>> concatenate the buffer, probably ,= will work (not sure about this, would
>>>> have to check), or any other operator that works on Positionals.
>>>>
>>>> JJ
>>>>
>>>> El mar., 11 feb. 2020 a las 10:56, David Santiago ()
>>>> escribió:
>>>>
>>>>> A 11 de fevereiro de 2020 10:47:34 CET, David Santiago <
>>>>> deman...@gmail.com> escreveu:
>>>>> >A 11 de fevereiro de 2020 09:46:06 CET, David Santiago <
>>>>> deman...@gmail.com> escreveu:
>>>>> >>
>>>>> >>Hi!
>>>>> >>
>>>>> >>Can someone explain me why this doesn't work:
>>>>> >>
>>>>> >>my Blob $read;
>>>>> >>$read ~= $socket.read(1024);
>>>>> >>
>>>>> >>Dies with error:
>>>>> >>
>>>>> >>X::Buf::AsStr: Cannot use a Buf as a string, but you called the
>>>>> Stringy method on it
>>>>> >>
>>>>> >>This also doesn't work:
>>>>> >>
>>>>> >>my Buf $read;
>>>>> >>$read ~= $socket.read(1024);
>>>>> >>
>>>>> >>Dies with the same error as above.
>>>>> >>
>>>>> >>
>>>>> >>But this works?
>>>>> >>
>>>>> >>my Blob $read = Buf.new;
>>>>> >>$read ~= $socket.read(1024);
>>>>> >>
>>>>> >>
>>>>> >>Best regards,
>>>>> >>David Santiago
>>>>> >
>>>>> >
>>>>> >Hi!
>>>>> >
>>>>> >Can someone explain me why this doesn't work:
>>>>> >
>>>>> >my Blob $read;
>>>>> >$read ~= $socket.read(1024);
>>>>> >
>>>>> >Dies with error:
>>>>> >
>>>>> >X::Buf::AsStr: Cannot use a Buf as a string, but you called the
>>>>> Stringy method on it
>>>>> >
>>>>> >This also doesn't work:
>>>>> >
>>>>> >my Buf $read;
>>>>> >$read ~= $socket.read(1024);
>>>>> >
>>>>> >Dies with the same error as above.
>>>>> >
>>>>> >
>>>>> >But this works?
>>>>> >
>>>>> >my Blob $read = Buf.new;
>>>>> >$read ~= $socket.read(1024);
>>>>> >
>>>>> >
>>>>> >Best regards,
>>>>> >David Santiago
>>>>>
>>>>>
>>>>> Hi!
>>>>>
>>>>> Can someone explain me why this doesn't work:
>>>>>
>>>>> my Blob $read;
>>>>> $read ~= $socket.read(1024);
>>>>>
>>>>> Dies with error:
>>>>>
>>>>> X::Buf::AsStr: Cannot use a Buf as a string, but you called the Stringy
>>>>> method on it
>>>>>
>>>>> This also doesn't work:
>>>>>
>>>>> my Buf $read;
>>>>> $read ~= $socket.read(1024);
>>>>>
>>>>> Dies with the same error as above.
>>>>>
>>>>>
>>>>> But this works?
>>>>>
>>>>> my Blob $read = Buf.new;
>>>>> $read ~= $socket.read(1024);
>>>>>
>>>>>
>>>>> Best regards,
>>>>> David Santiago
>>>>>
>>>>> --
>>>>> Sent from my Android device with K-9 Mail. Please excuse my brevity.
>>>>>
>>>>
>>>>
>>>> --
>>>> JJ
>>>>
>>>
>>
>> --
>> Simon Proctor
>> Cognoscite aliquid novum cotidie
>>
>> http://www.khanate.co.uk/
>>
>
>

Hi!

I'm still confused.
The read returns a blob, and ~ can be used with strings and Buf. I get this.

>my Blob $read = Buf.new

Does  this means that Blob will do Buf role as well?

>my Buf $a = Buf.new(1,2,3);
>my Blob $b = Blob.new(4,5,6);
>$a ~= $b;

Since this is allowed, does it means that Blob does Buf role by being 
coerced(?) as well? But then shouldn't this be allowed as well?

>my Blob $read;
>$read ~= $socket.read(1024)

Best regards,
David Santiago


-- 
Sent from my Android device with K-9 Mail. Please excuse my brevity.


Question about Blob and Buf

2020-02-11 Thread David Santiago
A 11 de fevereiro de 2020 10:47:34 CET, David Santiago  
escreveu:
>A 11 de fevereiro de 2020 09:46:06 CET, David Santiago  
>escreveu:
>>
>>Hi!
>>
>>Can someone explain me why this doesn't work:
>>
>>my Blob $read;
>>$read ~= $socket.read(1024);
>>
>>Dies with error:
>>
>>X::Buf::AsStr: Cannot use a Buf as a string, but you called the Stringy 
>>method on it
>>
>>This also doesn't work:
>>
>>my Buf $read;
>>$read ~= $socket.read(1024);
>>
>>Dies with the same error as above.
>>
>>
>>But this works?
>>
>>my Blob $read = Buf.new;
>>$read ~= $socket.read(1024);
>>
>>
>>Best regards,
>>David Santiago
>
>
>Hi!
>
>Can someone explain me why this doesn't work:
>
>my Blob $read;
>$read ~= $socket.read(1024);
>
>Dies with error:
>
>X::Buf::AsStr: Cannot use a Buf as a string, but you called the Stringy method 
>on it
>
>This also doesn't work:
>
>my Buf $read;
>$read ~= $socket.read(1024);
>
>Dies with the same error as above.
>
>
>But this works?
>
>my Blob $read = Buf.new;
>$read ~= $socket.read(1024);
>
>
>Best regards,
>David Santiago


Hi!

Can someone explain me why this doesn't work:

my Blob $read;
$read ~= $socket.read(1024);

Dies with error:

X::Buf::AsStr: Cannot use a Buf as a string, but you called the Stringy method 
on it

This also doesn't work:

my Buf $read;
$read ~= $socket.read(1024);

Dies with the same error as above.


But this works?

my Blob $read = Buf.new;
$read ~= $socket.read(1024);


Best regards,
David Santiago

-- 
Sent from my Android device with K-9 Mail. Please excuse my brevity.


Re: Substr behaviour with CRLF

2020-02-10 Thread David Santiago
Thanks for the help.

I do agree with Paul that something should be mentioned in the substr 
documentation.

David Santiago
-- 
Sent from my Android device with K-9 Mail. Please excuse my brevity.


Re: Substr behaviour with CRLF

2020-02-10 Thread David Santiago
A 10 de fevereiro de 2020 16:57:55 CET, David Santiago  
escreveu:
>
>
>Hi!
>
>Is there a way to change the the following behaviour, so it considers \r\n as 
>two characters when using substr, instead of one?
>
>On raku version 2019.11
>
>> "1234\r\n". substr(*-4)
>4
>78
>> "1234\r\n". substr(*-4).ords()
>(52 13 10 55 56)
>
>
>Best regards,
>David Santiago
>

Copied wrong the example:

It should be:

On raku version 2019.11

> "1234\r\n78". substr(*-4)
4
78
> "1234\r\n78". substr(*-4).ords()
(52 13 10 55 56)



-- 
Sent from my Android device with K-9 Mail. Please excuse my brevity.


Substr behaviour with CRLF

2020-02-10 Thread David Santiago



Hi!

Is there a way to change the the following behaviour, so it considers \r\n as 
two characters when using substr, instead of one?

On raku version 2019.11

> "1234\r\n". substr(*-4)
4
78
> "1234\r\n". substr(*-4).ords()
(52 13 10 55 56)


Best regards,
David Santiago

-- 
Sent from my Android device with K-9 Mail. Please excuse my brevity.


Re: GIT PR Help

2020-01-17 Thread David Santiago
A 17 de janeiro de 2020 21:44:00 CET, ToddAndMargo via perl6-users 
 escreveu:
>On 2020-01-17 12:20, Trey Harris wrote:
>> If the issue is that you aren’t comfortable enough with Git¹, I assume 
>> as part of the basic toolkit of a sysadmin you know how to generate a 
>> unified diff patchfile (with `diff -ruN` or equivalent)?
>> 
>> If so, if you generate one and upload it attached to a GitHub issue, we 
>> can figure out how to turn it into a PR rather trivially (and if I’m the 
>> first to pick it up, I’ll include step-by-step instructions on how to do 
>> it as a Git PR in the future).
>
>Now I am confused.  Exactly what is going on with a PR?
>
>What I am after is to add an example to a document page.
>Is there any special thing about this other than just
>asked for it?  It sounds like I download my own copy
>of the page (with git), then make the alterations,
>then request others evaluate it?
>
>Your in confusion,
>-T

Offlist

Git is a distributed version control system. This means that you create copies 
of the original (upstream) repo (hence the distributed part). 

This is a very simplified explanation:
So you do your changes and commit on your repo. Since you want your changes to 
go to upstream, you need to create a pr (pull request). Github helps in this, 
which means that you push your changes to your repo in github (assuming that 
you forked to your account  in github), also known as origin, and on github a 
link will appear to create a pull request.

If you click on that link, you will be redirected to the create pull request 
page, where you can see your changes.

Then the pr needs to be aproved to be merged into upstream, you might get some 
comments with changes you need to do and so. You then just commit the new 
changes and push them to your repo in git and the pr is updated.

This is just one of many workflows possible with git.

Let me know if you have questions


Regards, 
David




-- 
Sent from my Android device with K-9 Mail. Please excuse my brevity.


Re: How to process command line options

2020-01-06 Thread David Santiago
Thanks for the reply!

That was the issue, the missing '=', and the order. I thought that
because it was a named parameter the order wouldn't matter.

Regarding the second question, on how to have the same switch multiple
times, using a @ sigil doesn't work:

Code:

subset Layout of Str where * ~~ /^<[12345]>\+[kk|1]$|^6\+$|^[studio|unusual]$/;

multi sub MAIN("apt",
Layout :@layout! #= Apartment layout. Values accepted:
1+kk,2+kk,...,5+kk, 6+, studio, unusual
) {
say "enter!";

}

When invoking:

$>  raku bin/script.raku --layout='unusual' --layout='1+kk' apt
Usage:
  bin/script.raku --layout= ... apartment

--layout= ...Apartment layout. Values accepted:
1+kk,2+kk,...,5+kk, 6+, studio, unusual


Unfortunately I'm unable to find any example in google on how to do
this. I guess i will have to look for some module.

Best regards,
David Santiago

Patrick Spek via perl6-users  escreveu no dia
segunda, 6/01/2020 à(s) 09:25:
>
> On Sun, 5 Jan 2020 22:32:02 +
> David Santiago  wrote:
>
> > Hello.
> >
> > I'm following
> > https://docs.raku.org/language/5to6-nutshell#Getopt::Long but i still
> > haven't figured it out how do i use a constraint in a named parameter
> > when processing a command line.
> >
> > I have this piece of code:
> >
> > multi sub MAIN("apt",
> > :$layout where $layout ~~
> > /^<[12345]>\+[kk|1]$|^6\+$|^[studio|unusual]$/ #= Apartment layout.
> > Values accepted: 1+kk,2+kk,...,5+kk, 6+, studio, unusual
> > ) {
> > say "Enter";
> > }
> >
> > however when i run it i get the --help message:
> >
> > $ raku script.raku apt --layout '1+kk'
> > Usage:
> >   script.raku [--layout=] apartment
> >
> >   --layout=Apartment layout. Values accepted:
> > 1+kk,2+kk,...,5+kk, 6+, studio, unusual
> >
> >
> > If i make layout a positional parameter then it works correctly. Is
> > there a way to make this work with a named parameter?
> > And how do i make possible to use the "--layout" option several times?
> > Changing the parameter from $layout to @layout doesn't work.
> >
> >
> >
> > Best regards,
> > David Santiago
>
> Hi David,
>
> The default parameter handling of Raku requires you to use an "=" sign
> between the option name and value. Additionally, the option needs to be
> before any positional arguments. Try running it as follows:
>
> raku script.raku --layout='1+kk' apt
>
> As for the ability to add it several times, I believe using an @ sigil
> instead of a $ sigil should work, but perhaps someone else has spotted
> an issue that I missed here.
>
> --
> With kind regards,
>
> Patrick Spek
>
>
> www:  https://www.tyil.nl/
> mail: p.s...@tyil.nl
> pgp:  1660 F6A2 DFA7 5347 322A  4DC0 7A6A C285 E2D9 8827
>
> social: https://soc.fglt.nl/tyil
> git:https://gitlab.com/tyil/


How to process command line options

2020-01-05 Thread David Santiago
Hello.

I'm following https://docs.raku.org/language/5to6-nutshell#Getopt::Long
but i still haven't figured it out how do i use a constraint in a
named parameter when processing a command line.

I have this piece of code:

multi sub MAIN("apt",
:$layout where $layout ~~
/^<[12345]>\+[kk|1]$|^6\+$|^[studio|unusual]$/ #= Apartment layout.
Values accepted: 1+kk,2+kk,...,5+kk, 6+, studio, unusual
) {
say "Enter";
}

however when i run it i get the --help message:

$ raku script.raku apt --layout '1+kk'
Usage:
  script.raku [--layout=] apartment

  --layout=Apartment layout. Values accepted:
1+kk,2+kk,...,5+kk, 6+, studio, unusual


If i make layout a positional parameter then it works correctly. Is
there a way to make this work with a named parameter?
And how do i make possible to use the "--layout" option several times?
Changing the parameter from $layout to @layout doesn't work.



Best regards,
David Santiago