🦋 Welcome to the MAIN() IRC channel of the Raku Programming Language (raku.org). Log available at irclogs.raku.org/raku/live.html . If you're a beginner, you can also check out the #raku-beginner channel!
Set by lizmat on 6 September 2022.
MasterDuke [Coke]: pretty sure ugexe gave an example of how to do that in one of the channels in the past month or two 01:38
melezhik .tell tonyo - finally I've made it - full automation of fez upload via pipeline - fosstodon.org/@melezhik/109402367802442237 03:42
tellable6 melezhik, I'll pass your message to tonyo
melezhik happy thanks giving to everyone who observes this holiday ! 03:43
ToddAndMargo Happy Thanksgiving to all too! 03:50
What is the proper syntax for this?
my $k = CArray[uint8].new(0xFF xx $j )
Cannot invoke object of type 'NQPMu'
It does not like $j (which is 6)
Guest32 docs.raku.org/routine/xx 03:52
ToddAndMargo I am not seeing any way to use a variable there.  Am I missing something? 03:54
I want to use the variable to set the length 03:55
ToddAndMargo say [1, 2] xx $j; 04:00
Cannot invoke object of type 'NQPMu'
any other way to presalt my CArray?
Guest32 [2] > my $l = CArray[uint8].new(255 xx 6); 04:05
NativeCall::Types::CArray[uint8].new
[3] > say $l.kv;
(0 255 1 255 2 255 3 255 4 255 5 255)
ToddAndMargo my $k = CArray[uint8].new(0xFF xx $j )     The reason for the $j is that I do not know the length until it is calculated 04:07
Guest32 [3] > my $j = 7; 04:08
7
[4] > my $l = CArray[uint8].new(255 xx $j);
NativeCall::Types::CArray[uint8].new
[5] > say $l.kv;
(0 255 1 255 2 255 3 255 4 255 5 255 6 255)
ToddAndMargo Where is my typo? 04:12
> $j =6; $k = CArray[uint8].new(0xFF xx $j ); print $j ~ "\n";
Cannot find method 'qast' on object of type NQPMu
Figured it out.  My repl does not like my $j.  When run directly, it works perfectly.  Sorry for the false alarm 04:16
Now what am I doing wrong? 04:19
ppSessionInf       = <NativeCall::Types::Pointer<4817055982656>>
pCount             = <2>
Length             = <48>
   $Result = GetWTSEnumerateSession $hServer, $Reserved, $Version, $ppSessionInf, $pCount;
   my uint16 $Length = $pCount * (12 + (12 * $Win64bit));
   my $ca = CArray[BYTE].new( 0xFF xx $Length );
   $ca = $ppSessionInf.deref;
Internal error: unhandled target type
What should I have as a target type? 04:20
the target type is throwing on `$ca = $ppSessionInf.deref;`
Guest32 Give it a read: docs.raku.org/language/numerics 04:24
ToddAndMargo what section? 04:27
Is there a way to ask raki what type is being returned? 04:28
not declaring the variable type does not work either `my $x = $ppSessionInf.deref;`  neither does `say $ppSessionInf.deref;` 04:29
Guest32 [8] > my $v = 1; 04:31
1
[9] > my $l = CArray[uint8].new($v++ xx $j);
NativeCall::Types::CArray[uint8].new
[10] > say $l[0].WHAT;
(Int)
[10] > say $l.WHAT;
(CArray[uint8])
[10] > say $l.kv;
(0 1 1 2 2 3 3 4 4 5 5 6 6 7)
ToddAndMargo appartenly 1repr1 does not exist either 04:32
say $ppSessionInf; return `NativeCall::Types::Pointer<0x1e2f9c04020>` 04:33
How do I tell NativeCall I want 24 bytes that that pointer points to? 04:34
.deref is giving me a bad time! 04:35
Guest32 As far I can tell there is no valid hexadecimal representarion (0xFF) in Raku lang. 04:36
ToddAndMargo 0xFF is uint8 04:37
Guest32 I can't find the strings "0x" or "hexa" in the search box of docs.raku.org
ToddAndMargo say 0xFF.base(16) 04:38
FF
evalable6 FF
ToddAndMargo > my $i=0xFF; say $i.base(16) ~ "  " ~ $i.base(2) 04:40
FF  11111111
my uint8 $i=0xFF; say $i.base(16) ~ "  " ~ $i.base(2)
FF  11111111
evalable6 FF  11111111
ToddAndMargo How do I tell NativeCall I want 24 bytes that that pointer points to? 04:41
ToddAndMargo `say "$ppSessionInf.WHAT = <" ~ $ppSessionInf.WHAT ~ ">";` gives me 04:44
Use of uninitialized value of type NativeCall::Types::Pointer in string context.
Methods .^name, .raku, .gist, or .say can be used to stringify it to something meaningful.
  in sub GetSessionNo at PopUpTest2.pl6 line 98
NativeCall::Types::Pointer<3452477188480>.WHAT = <>
say "$ppSessionInf.deref.WHAT = <" ~ $ppSessionInf.deref.WHAT ~ ">"; 04:46
Internal error: unhandled target type
Perhaps, did I just trip across a bug in NativeCall? 04:49
Guest32 no ideia 04:53
Nemokosch Hi, is there anyone who would feel strongly about the removal of "Defined as:" phrases from the top of signatures in the documentation? 13:05
tellable6 2022-11-23T09:54:02Z #raku-dev <lizmat> Nemokosch: I think it's time to do a PR to add yourself to github.com/rakudo/rakudo/blob/master/CREDITS :-)
2022-11-24T18:30:43Z #raku-dev <lizmat> Nemokosch: would you like a commit bit ?
Nemokosch Example: docs.raku.org/routine/sum "Defined as:" at two out of three places 13:06
rbt Is there a way to see when a Num or Rat will fit into num64 without reducing precision? 15:13
This write-num64(0, $_.Num) just tosses extra lower bytes. 15:16
Nemokosch probably .Num itself does 15:21
rbt Indeed. Is there a better way of detecting tossed bytes than this: $value != $value.Num.Rat 15:29
Geth advent: tbrowder++ created pull request #102:
Moving tbrowder's Raku Advent article source to another location
16:02
advent/master: 9 commits pushed by (Tom Browder)++
avuserow rbt: maybe narrow would help? docs.raku.org/routine/narrow 16:06
not sure if that helps with native types though. your solution may be the best 16:07
rbt Unfortunately, narrow provides datatypes which may still overflow num64. 16:11
avuserow is there a way to get regexes to return Str instead of Matches? here's my usecase: 16:15
m: "foo.bar::baz" ~~ /^ $<relation>=(\S+) "." $<column>=(<-[:]>+) "::" $<cast>=(\S+) $/; dd [:$<relation>] # this is what I get
camelia [:relation(Match.new(:orig("foo.bar::baz"), :from(0), :pos(3)))]
avuserow m: "foo.bar::baz" ~~ /^ $<relation>=(\S+) "." $<column>=(<-[:]>+) "::" $<cast>=(\S+) $/; dd [:relation($<relation>.Str)] # this is what I want but simpler :)
camelia [:relation("foo")]
gfldex m: my Str() @a = ('foo=10' ~~ /$<a>=[\w+] '=' $<b>=[\d+]/)<a b>; .say for @a; 17:36
camelia foo
10
gfldex avuserow: ^^^
gfldex m: say ('foo=bar=10' ~~ /$<a>=('foo' '=' $<b>=('bar' '=' $<c> = [\d+]))/){||<a b c>}; 17:46
camelia (「foo=bar=10」
b => 「bar=10」
c => 「10」 Nil Nil)
gfldex m: use v6.*; say ('foo=bar=10' ~~ /$<a>=('foo' '=' $<b>=('bar' '=' $<c> = [\d+]))/){||<a b c>}; 17:47
camelia 「10」
sortiz rba, As far as I remember any Num can be stored as num64 without losing precision: 17:51
m: my $b = Buf.allocate(8).write-num64(0,pi); say $b.read-num64(0) === pi;
camelia True
Nemokosch avuserow: I think I found a hacky way for your syntax 17:54
m: "foo.bar::baz" ~~ /^ $<relation>=(\S+) "." $<column>=(<-[:]>+) "::" $<cast>=(\S+) $/; $/ := $/.Hash>>.Str; dd [:$<relation>]
camelia [:relation("foo")]
Nemokosch the problem is that this binding seems to kill the mechanism that backs up $/ 17:56
so now I'm stuck with the value I got into it, no matter how many times I match :\
Nemokosch m: my $match = "foo.bar::baz" ~~ /^ $<relation>=(\S+) "." $<column>=(<-[:]>+) "::" $<cast>=(\S+) $/; { my $/ := $match.Hash>>.Str; dd [:$<relation>]; }; "alma" ~~ / ma /; dd $/; 18:07
camelia [:relation("foo")]
Match $/ = Match.new(:orig("alma"), :from(2), :pos(4))
Nemokosch now, the hack doesn't leak at least 18:07
but it's getting too verbose to be useful
sortiz rbt: Ups, the above was for you. 18:11
rbt soritz: Thank-you. I'd come to that conclusion as well. I've got a different solution for Rat. Trying to cleanup some of the DBIish MySQL driver issues. 18:42
sortiz: Thank-you ^ 18:44
sortiz Some loss of precision when converting between Num and Rat (or FatRat) is inevitable. 18:45
avuserow Nemokosch, thanks for the ideas. Luckily I found that I can solve this a layer up 20:18
m: class Foo {has Str() $.bar}; "foo.bar::baz" ~~ /^ $<relation>=(\S+) "." $<column>=(<-[:]>+) "::" $<cast>=(\S+) $/; say Foo.new(:$<bar>)
camelia Foo.new(bar => Str)
avuserow m: class Foo {has Str() $.relation}; "foo.bar::baz" ~~ /^ $<relation>=(\S+) "." $<column>=(<-[:]>+) "::" $<cast>=(\S+) $/; say Foo.new(:$<relation>) 20:19
camelia Foo.new(relation => "foo")
rbt sortiz: I managed to find loss in precision while creating a FatRat directly. 20:52
say '-0.1234567890123456774144'.FatRat; # output: -0.123456789012345677
evalable6 -0.123456789012345677
sortiz rbt: Creating a FatRat from Num? 20:57
rbt From a string. 20:58
Adding digits gets the correct output.
sortiz A FatRat from Str attempts to use as many digits as available. But from from Num it use a default epsilon. (1e-6) 21:00
gfldex This is calling Cool.FatRat what is in turn calling self.Numeric.
sortiz &brb 21:00
gfldex and in role Numeric we can find: method FatRat(Numeric:D:) { self.Rat.FatRat } 21:01
rbt: please file a Rakudobug
rbt Yeah, I filed #5108
gfldex This is rather convoluted. Str.val -> Cool.Numeric -> *.Rat.FatRat 21:06
m: say '-0.1234567890123456774144'.val
camelia No such method 'val' for invocant of type 'Str'. Did you mean 'EVAL'?
in block <unit> at <tmp> line 1
gfldex m: say val('-0.1234567890123456774144')
camelia -0.1234567890123456774144
gfldex m: say val('-0.1234567890123456774144').WHAT
camelia (RatStr)
rbt It works if you add a digit. Appended a 9 to the end: 21:07
say '-0.12345678901234567741449'.FatRat
evalable6 -0.12345678901234567741449