🦋 Welcome to the MAIN() IRC channel of the Raku Programming Language (raku.org). This channel is logged for the purpose of keeping a history about its development | evalbot usage: 'm: say 3;' or /msg camelia m: ... | Log inspection is getting closer to beta. If you're a beginner, you can also check out the #raku-beginner channel!
Set by lizmat on 25 August 2021.
gfldex elcaro: gfldex.wordpress.com/2020/10/26/pl...olescence/ 00:13
elcaro gfldex: yeah I knew about this, and used your module prior... but I thought it was only `postcircumfix:<{|| }>` ... not `postcircumfix:<[|| ]>` 00:42
when your blog post was published, I'm sure I tried using it on a matrix and it didn't work. maybe I'm wrong... or maybe it was fixed later. 00:43
gfldex elcaro: It can take a few weeks for PRs to make it into a release. 00:56
elcaro gfldex: It was after the merge... more likely I forgot to use v6.e.PREVIEW before testing :/ 02:17
glad it's there, tho... seems I've been awaiting a feature that's been implemented for over a year :D 02:18
Manifest0 How can i invoke a method from an object, when i have the method name as string in a var, like this: class A{method t(){say "t!!"}}; my $a = A.new(); my $m = 't'; $a.$m(); ? 10:40
gfldex m: class A{method t(){say "t!!"}}; my $a = A.new(); my $m = 't'; $a.$m(); 10:49
camelia No such method 'CALL-ME' for invocant of type 'Str'
in block <unit> at <tmp> line 1
gfldex m: class A{method t(){say "t!!"}}; my $a = A.new(); my $m = 't'; $a."$m"();
camelia t!!
Manifest0 gfldex: super! :-) 10:50
i have to say, though, it's not intuitive 10:54
Ergo444 hi 12:36
where can I view the log of this channel?
lizmat logs.liz.nl/raku/live.html
lucs How can I successfully slurp in (or something) a latin1 encoded file when I don't happen to know the encoding? 13:04
lizmat slurp :encoding("latin1") ?
lucs Yeah, but I don't know the encoding, it might be UTF-8 or latin1. 13:05
lizmat actually: :enc<latin1>
lucs Fair enough, still :)
lizmat then utf8-c8 as encoding perhaps ? 13:06
lucs Hmm... I'll try-that.
Still complains of malformed UTF-8 :( 13:08
Ergo444 not suprising 13:09
lucs I'd try to trap the exception, except that the data is coming from $*IN, so if it fails at first, I think the data is not available to try again, or is it? 13:10
Is there any way to get the raw $*IN contents into a variable and work from that? 13:12
lizmat slurp(:bin) will give you a Bug 13:14
*Buf
lucs Oh, okay, never worked with those, will read up on them.
Thanks.
mscha m: class Foo { rule foo { foo }; method bar($s) { dd $s ~~ /<foo>/ } }; Foo.new.bar('foo'); 13:25
camelia No such method 'foo' for invocant of type 'Match'
in method bar at <tmp> line 1
in block <unit> at <tmp> line 1
mscha m: class Foo { my rule foo { foo }; method bar($s) { dd $s ~~ /<&foo>/ } }; Foo.new.bar('foo');
camelia Match.new(:orig("foo"), :from(0), :pos(3))
mscha Declaring a `rule` (or `token`, `regex`) is apparently legal outside of a Grammar, but is unusable as far as I can tell. Why isn't he first one a syntax error? 13:27
ab5tract m: class A{method t(){say "t!!"}}; my $a = A.new(); my $m = 't'; $a.<<$m>>(); 13:46
camelia Type A does not support associative indexing.
in block <unit> at <tmp> line 1
ab5tract (was simply curious :) )
habere-et-disper What is the recommended/idiomatic way to sort an array of arrays? 14:13
m: say sort [ [1,3,2], [5,4,6], [6,2,1] ].map: *.sort
camelia ((1 2 3) (1 2 6) (4 5 6))
habere-et-disper It seems we have to say sort twice? 14:14
lizmat what is the criterium to sort the lists on ?
habere-et-disper Maybe that is a good compromise for composability?
habere-et-disper lizmat ascending numerical order is fine 14:16
lizmat so you want to sort on the first element, if that's the same, sort on the next, etc ?
after having sorted all of the "sub" arrays ? 14:17
habere-et-disper Sort all the sub-arrays, then the top array. 14:17
Which I sort of think of as a default in this case?
lizmat well, I think it will stringify arrays and compare that 14:18
which is... suboptimal
habere-et-disper okay, thanks. 14:20
Are we using the Edit Distance/Levenshtien algorithm to make suggestions? That would seem to automatically catch typos. 14:25
lizmat yes, we are, plus some specific suggestions 14:26
m: say "foo".length
camelia No such method 'length' for invocant of type 'Str'. Did you mean any
of these: 'chars', 'codes'?
in block <unit> at <tmp> line 1
habere-et-disper Wow! Excellent. Thanks. 14:28
tbrowder publishing modules to Zef with mi6 is now soooo easy. i have now published 8 there which were orig on cpan and will do more. 14:58
tbrowder if you haven't been using App::Mi6 for module management you have been missing the boat 14:59
Ergo444 how can I empty a hash? 15:01
m: my %h; %h = {};
camelia Potential difficulties:
Useless use of hash composer on right side of hash assignment; did you mean := instead?
at <tmp>:1
------> 3my %h; %h = {}7⏏5;
Ergo444 What is wrong in here?
SmokeMachine m: my %h = :a, :b; say %h; %h = (); say %h 15:03
camelia {a => True, b => True}
{}
lizmat m: my %h; %h = ();
camelia ( no output )
mcmillhj Maybe I am being dense and not understanding the documentation, but is there are there methods for adding and removing elements from sets? Or am I supposed to use the set operators for this? docs.raku.org/type/Set 15:04
El_Che "A Set is an immutable set"
"(For mutable sets, see SetHash instead.)"
lizmat m: my %s is SetHash; %s.set: 1,2,3; dd %s 15:05
camelia Too many positionals passed; expected 2 arguments but got 4
in block <unit> at <tmp> line 1
lizmat m: my %s is SetHash; %s.add: 1,2,3; dd %s
camelia No such method 'add' for invocant of type 'SetHash'
in block <unit> at <tmp> line 1
lizmat hmmm
mcmillhj El_Che sorry, I did mean to link SetHash I have both tabs open :) 15:06
lizmat m: my %s is SetHash; %s.set: (1,2,3); dd %s
camelia SetHash.new(2,1,3)
mcmillhj lizmat okay, but to test for existence do I just `%s{<KEY HERE>}` ?
lizmat mcmillhj: indeed
m: my %s is SetHash; %s.set: (1,2,3); dd %s{1}; dd %s{0} 15:07
camelia Bool::True
Bool::False
mcmillhj okay, great. I think I was just not understanding the documentation. Thanks all.
El_Che mcmillhj: then the documentation may need some love 15:10
mcmillhj El_Che I think it was more me being confused / not reading carefully. I was just kind of expecting an API like I have seen in other languages: .add, .has, etc... My bias isn't the docs fault though :) 15:11
lizmat mcmillhj: BagHashes have .add 15:13
Ergo444 hello what is wrong with this?
lizmat mcmillhj: SetHashes also have .unset 15:14
Ergo444 m: my %h; %h = {};
camelia Potential difficulties:
Useless use of hash composer on right side of hash assignment; did you mean := instead?
at <tmp>:1
------> 3my %h; %h = {}7⏏5;
Ergo444 useless use?
it is not useless
lizmat Ergo444: so what do you think it should do ?
Ergo444 empty the hash 15:15
lizmat %h = ()
will do that for you
Ergo444 what is wrong with {}?
lizmat well, its semantics are not clear
Ergo444 how so?
lizmat should it flatten or not ? 15:16
%h = () will reset an existing Hash object 15:17
%h := { } will re-bind the %h to a fresh (empty) Hash object
Ergo444 flatten?
Flatten what?
lizmat the right hand side of %h = }
the right hand side of %h = { } 15:18
Ergo444 there is nothing to flatten
lizmat yes there is, A Hash object
%h = { }
is effectively the same as:
%h = Hash.new
Ergo444 and? 15:19
How would an object be flattened? 15:22
I only know this term with lists. 15:23
What does it mean to flatten an object?
lizmat well, generally we talk about it in the context of arrays / hashes only 15:24
m: my @a = { :a, :b }; dd @a
camelia Array @a = [:b(Bool::True), :a(Bool::True)]
lizmat this flattened the hash into Pairs in the array 15:25
m: my @a = { :a, :b }, { :c, :d }; dd @a
camelia Array @a = [{:a(Bool::True), :b(Bool::True)}, {:c(Bool::True), :d(Bool::True)}]
lizmat this did not, because of the single argument rule
Ergo444 What is the single assignment rule? 16:07
lizmat single argument rule 16:09
m: my @a = ^5; for @a { dd $_ } 16:10
camelia Int @a = 0
Int @a = 1
Int @a = 2
Int @a = 3
Int @a = 4
lizmat note that this flattened the array in the for loop
m: my @a = ^5; for @a, @a { dd $_ }
camelia Array @a = [0, 1, 2, 3, 4]
Array @a = [0, 1, 2, 3, 4]
lizmat note that this did not, because the for loop got more than 1 argument
Guest36 Beat do raku 16:34
ab5tract The single argument rule should arguably ( ;) ) be considered the lynch pin to understanding the somewhat odd corners of when to slip/flatten and when to not. IIRC this was basically how we came to "solve" the GLR (Great List Refactor). 16:36
which reminds me to ask a) how is TimToady these days?; and b) where is the butterfly book? :) 16:37
mcmillhj m: class Point { has Int $.x; has $.y; method find(SetHash[Point] %search-space) { return Nil; } }; my $p = Point.new(x => 0, y => 0); $p.find(SetHash.new); 19:04
camelia Type check failed in binding to parameter '%search-space'; expected Associative[SetHash[Point]] but got SetHash (SetHash.new())
in method find at <tmp> line 1
in block <unit> at <tmp> line 1
mcmillhj ^ what's the correct way to type the `find` function if I want to accept a `SetHash` of `Point` objects 19:04
lizmat m: class Point { has Int $.x; has $.y; method find(SetHash[Point] $search-space) { return Nil; } }; my $p = Point.new(x => 0, y => 0); $p.find(SetHash.new); 19:10
camelia Type check failed in binding to parameter '$search-space'; expected SetHash[Point] but got SetHash (SetHash.new())
in method find at <tmp> line 1
in block <unit> at <tmp> line 1
lizmat m: class Point { has Int $.x; has $.y; method find(SetHash[Point] $search-space) { return Nil; } }; my $p = Point.new(x => 0, y => 0); $p.find(SetHash[Point].new);
camelia ( no output )
lizmat mcmillhj ^^ 19:11
m: class Point { has Int $.x; has $.y; my constant SHP = SetHash[Point]; method find(SHP $search-space) { return Nil; } }; my $p = Point.new(x => 0, y => 0); $p.find(SHP.new);
camelia 5===SORRY!5=== Error while compiling <tmp>
Undeclared name:
SHP used at line 1
mcmillhj lizmat ty++ 19:12
lizmat m: class Point { has Int $.x; has $.y; our constant SHP = SetHash[Point]; method find(SHP $search-space) { return Nil; } }; my $p = Point.new(x => 0, y => 0); $p.find(SHP.new);
camelia 5===SORRY!5=== Error while compiling <tmp>
Undeclared name:
SHP used at line 1
lizmat m: class Point { ... }; our constant SHP = SetHash[Point]; class Point { has $.x; has $.y; method find(SHP $search-space) { return Nil; } }; my $p = Point.new(x => 0, y => 0); $p.find(SHP.new); 19:13
camelia ( no output )
mcmillhj oh nice, that looks a lot cleaner. Thank you.
lizmat mcmillhj: what is done there with class Point { ... } is called "stubbing the class" so that it is known, and only later actually filled in 19:16
mcmillhj lizmat I like it, it will let me rewrite my types in my domain 19:17
mcmillhj Is there a way to provide an initial value for `reduce` ? 20:37
lizmat this is typically the value that the argumentless call of the operator returns 20:43
lizmat m: say &infix:<+>() 20:44
camelia 0
lizmat m: say &infix:<*>()
camelia 1
lizmat mcmillhj ^^ is that what you mean
?
mcmillhj not exactly, I was thinking more like a foldl or foldr operation but when I can supply the initial value of the accumulator 20:45
I can paste my small example if that would make it more clear.
lizmat yes, please 20:46
mcmillhj Uploaded file: uploads.kiwiirc.com/files/12b32d29...pasted.txt 20:49
topaz.github.io/paste/#XQAAAQBmAgA...+0TxaCF4mb
/9/TUj9S4YvpcEK6xYWPhCiPug5vxGfsTBgY=
maybe reduce is the wrong verb, it's more like aggregate in my case 20:54
lizmat perhaps something like this: 20:58
m: my %m is Map = "(", 1, "[", 2, q/{/, 3, "<", 4; my $current = "<"; say %m{$current}
camelia 4
lizmat m: my %m is Map = "(", 1, "[", 2, q/{/, 3, "<", 4; my $current = "x"; say %m{$current} // 0
camelia 0
mcmillhj that could work, let me try that out. Thank you. 21:04
tonyo what happened with this? docs.raku.org/language/modules#Dis...ng_modules 21:48
was fez removed for some reason?
[Coke] docs.raku.org/language/modules#Upl..._ecosystem ? 21:51
don't see any recent changes to that bulleted list. 21:53
last content change on that file is from Jul 31 2021
(and it doesn't seem to touch that section) - so probably not yet added.