This channel is intended for people just starting with the Raku Programming Language (raku.org). Logs are available at irclogs.raku.org/raku-beginner/live.html
Set by lizmat on 8 June 2022.
guifa habere-et-disper it's doing scalar-style assignment 01:00
m: my UInt ( $foo, @bar ) := ( 3, [14] ); say $foo, @bar; 01:01
camelia 3[14]
guifa binding works though
jaguart m: my @foo of Int = 33,44,'a'; 03:22
camelia Type check failed in assignment to @foo; expected Int but got Str ("a")
in block <unit> at <tmp> line 1
jaguart m: my ( @foo of Int) = 33,44,'a'
camelia ( no output )
jaguart hmm my repl says this results in ([33 44 a]) 03:23
m: my (UInt $foo, @bar of UInt ) = ( 3, 14,15,'a' ) 03:24
camelia ( no output )
jaguart m: my (UInt $foo, @bar of UInt ) = ( 3, 14,15,'a' ); @bar.raku 03:25
camelia ( no output )
jaguart Again, my repl (2022.7) ends up with @bar containing an 'a' 03:26
guifa jaguart: I can confirm that. And it's that the `of Foo` isn't applied
golfed: 03:27
m: my (@foo of Int) = 1,'a'; say @foo; say @foo.of
camelia [1 a]
(Mu)
jaguart it works as expected with no brackets :o 03:28
guifa The parentheses induce special handling, and certain attributes aren't be applied as a result 03:32
jaguart M: my (UInt @bar) = 1,2; @bar.raku 03:34
gives this in my repl: Array[<anon>].new(1, 2)
m: my UInt @bar = 1,2; @bar.raku 03:35
camelia ( no output )
jaguart gives: Array[UInt].new(1, 2)
m: my UInt @bar = 1,2; say @bar.raku 03:38
camelia Array[UInt].new(1, 2)
jaguart m: my (UInt @bar) = 1,2,'a'; say @bar.raku
camelia Type check failed in assignment to @bar; expected <anon> but got Str ("a")
in block <unit> at <tmp> line 1
jaguart m: my (@bar of UInt) = 1,2,'a'; say @bar.raku 03:39
camelia [1, 2, "a"]
rcmlz Hello, I was wondering whether there is a more Rakuish way of generating all subsequences in an array. The function .combinations gets close, but I did not succeed in finding a correct usage. Here is my not-so-nice solution, any thoughts on how to make that more elegant? 10:28
m:
sub subsequences(@input){
my $n = @input.elems();
my @result;
for ^$n {
my $subseq_len = $_ + 1;
for ^$n -> $i { # start at every element of array
my @subsequenz;
@subsequenz.append(@input[$i]);
for 1..^$subseq_len -> $j { # add $subseq_len elements
@subsequenz.append(@input[$j]);
}
m: 10:30
sub subsequences(@input){
my $n = @input.elems();
my @result;
for ^$n {
my $subseq_len = $\_ + 1;
for ^$n -> $i { # start at every element of array
my @subsequenz;
@subsequenz.append(@input[$i]);
for 1..^$subseq_len -> $j { # add $subseq_len elements
@subsequenz.append(@input[$j]);
}
lizmat please post code in a gist 10:31
rcmlz How do I post code in a gist? 10:36
Nahita hello rcmlz i think they mean gist.github.com/ or pastebin.com/ or hastebin.com/ kind of things 10:40
rcmlz gist.github.com/rcmlz/5c33ae1a2cd2...b23c7a1c14
Nahita because the message is from IRC bridge and not sure how multiple line code blocks are seen there
rcmlz <@836605577400549436> Thank you. I was reading gist() in Raku and did not get it. Now it is clear. 10:42
I logged in to IRC to see what a mess I created there by pasting so much code ... 10:52
irclogs.raku.org/raku-beginner/live.html shows me, that indeed it became unreadable. Sorry, I did not know that. Will use gist in the future. 10:53
lizmat thank you :-)
sorry for being a bit grumpy in the early morning
lizmat looking at the gist, feels like lines 9-11 can be simplified to: 10:56
@subsequenz.append(@input[1..^$subseq_len]);
rcmlz Hello, I was wondering whether there is a more Rakuish way of generating all subsequences in an array. The function .combinations gets close, but I did not succeed in finding a correct usage. Here is my not-so-nice solution, any thoughts on how to make that more elegant? 10:57
gist.github.com/rcmlz/5c33ae1a2cd2...b23c7a1c14
lizmat I see that you want to return a Set at the end
perhaps docs.raku.org/type/SetHash#method_set could be of use ? 10:58
so not create an array, but create a SetHash
rcmlz No, Set or Array does not matter 10:59
lizmat if you really want to return an immutable Set, you could coerce it to a Set on line 15
rcmlz array, list, set - anything I can later itterate over is fine
lizmat : indeed, using the range saved me one loop. gist.github.com/rcmlz/3e604059949f...80265459a2 11:29
mahafyi Inline::Perl will use only system installed version, or can allow for a perlbew verision also? 14:08
rcmlz I developed two versions of a function that are doing the same. Is there a prefered way in Raku to compare the performance of them depending on the input size? gist.github.com/rcmlz/3e604059949f...80265459a2 15:25
How do you usually measure speed and memory usage of two alternatives? 15:27
avuserow rcmlz: there are a few Benchmark modules in the ecosystem. I've been using "Bench" lately. There's also Benchmark and Benchy. 19:13
.tell rcmlz there are a few Benchmark modules in the ecosystem. I've been using "Bench" lately. There's also Benchmark and Benchy.