00:02 sjn left 00:03 sjn joined 00:41 sjn left, sjn joined 00:52 sjn left 00:53 sjn joined 01:23 Heptite left 02:46 sjn left 02:48 sjn joined 03:03 sjn left 03:05 sjn joined 05:11 Heptite joined 05:20 sjn left 05:26 sjn joined 05:37 sjn left 05:39 sjn joined 05:49 sjn left 05:50 sjn joined 05:58 sjn left 06:00 sjn joined 06:08 sjn left 06:14 sjn joined 06:19 sjn left, sjn joined 06:28 sjn left 06:35 sjn joined 07:14 Heptite left 07:34 sjn left 07:46 sjn joined 07:51 sjn left, sjn joined 08:33 sjn left 08:34 sjn joined 08:48 sjn left 08:49 sjn joined
sampersand—2B +| +^2B == FF how can i raku function return "self"? 09:13
I can use $!foo for instance vars, and $.foo for methods, btu how do you return "self" 09:14
wambash self 09:34
m: class A { has $.b; method s () {self} }; say A.new(:3b).s
Raku eval A.new(b => 3)
uli.pink oh haii sampersand 10:03
im learning raku too
10:24 sjn left 10:46 sjn joined 10:51 sjn left 11:02 sjn joined 11:12 sjn left 11:14 sjn joined 11:29 sjn left 11:36 sjn joined 11:44 sjn left 11:45 sjn joined 11:50 Heptite joined 11:55 sjn left 11:57 sjn joined 13:15 sjn left 13:21 sjn joined 13:29 sjn left 13:36 sjn joined 13:42 sjn left 13:44 sjn joined 13:49 sjn left, sjn joined 13:53 Heptite left 13:54 sjn left, sjn joined 14:02 sjn left 14:06 lizmat joined 14:09 sjn joined
ab5tract To get a reference to self you can do: 15:02
m: class C { has $.a = <a>; method m($THIS: $other-arg = “default value”) { $!a = $other-arg; $THIS } }; my $i = C.new; say $i.m === $i 15:07
camelia True
ab5tract Note that the name and capitalization of $THIS are up to you to choose, nothing is enforced 15:08
15:53 sjn left 16:05 sjn joined 16:09 sjn left 16:15 sjn joined 16:21 sjn left, sjn joined 16:33 sjn left 16:35 sjn joined
sampersand—2B +| +^2B == FF Sick 16:41
ab5tract you can also do type constraints there, as per usual 16:56
m: role R { multi method m(R:U $THIS:) { dd :type-object($THIS) }; multi method m(R:D $THIS:) { dd :defined-object($THIS) } }; R.m; R.new.m;
camelia :type-object(R)
:defined-object(R.new)
ab5tract m: class C { has $.p = "/tmp/foo"; method IO { $!p.IO }; method m(IO() $SELF:) { dd :coerced($SELF) } }; C.new.m 16:58
camelia :coerced(IO::Path.new("/tmp/foo", :SPEC(IO::Spec::Unix), :CWD("/home/camelia")))
ab5tract note that the above can even be shortened via `handles` 16:59
m: class C { has $.p handles <IO> = "/tmp/foo"; method m(IO() $SELF:) { dd :coerced($SELF) } }; C.new.m
camelia :coerced(IO::Path.new("/tmp/foo", :SPEC(IO::Spec::Unix), :CWD("/home/camelia")))
ab5tract and for a final (probably unnecessary) demonstration: 17:10
m: class A { ... }; class B { ... }; role R { multi method m(A:D $S:) { dd :A($S) }; multi method m(B:D $S:) { dd :B($S) } }; class A does R {}; class B does R {}; A.new.m; B.new.m
camelia :A(A.new)
:B(B.new)
17:15 sjn left 17:16 sjn joined 17:41 Heptite joined
thowe I have a csv file that I am reading with a script simply by doing "for $file.IO.lines". some of the fields are missing, and ther eis just no space between the commas like ",,". I am splitting on the commas into an array like so "my @splitline = split(',', $line);". Trying to do anything with the fields which I would expect to just be empty strings or undefined produces errors like "Use of uninitialized value of type Any". How do I check for d 18:22
ab5tract thowe: so I wouldn't expect split to generate any uninitialized values 18:26
thowe the error seems to be generated simply by checking if the value is true? the line generating errors most often is " if ( @splitline[0] ) {" 18:27
if I remove this check, most variations work...
I don't understand something about checking for trueness here 18:28
ab5tract so one thing to consider is that`if @splitline[0]` will not resolve to true if @splitlinep[0] is an empty string
you can check for defined-ness in a number of ways, one of which would be `if @splitline[0] ~~ Str:D` 18:29
this `:D` is a "type smiley" and is a way to say here a defined instance of type `Str` 18:30
thowe yeah, but it isn't just being false, it is generating the error...
OK, lemme try that... 18:31
ab5tract m: say "defined!" if "" ~~ Str:D; say "not defined!" if Str ~~ Str:U; say "not said!" if Str ~~ Str:D;
camelia defined!
not defined!
ab5tract thowe: feel free to share a paste of the larger code if you can/want
thowe That helped... It helped me find another place where I was trying to use something wrong a couple lines later as well. I'm dealing with poorly maintained data. A large part of my task here is going through millions of lines to check if any of these fields are even simply not used at all. It appears to have been constructed from various iterations of a database that they then collate all the data from into a single csv. Some of the data is ei 18:40
I would normally use Perl 5, but I am trying to do more stuff with Raku just because.
18:42 sjn left
ab5tract `--ll-exception` can also come in handy at times like this by (sometimes) pointing towards a more relevant line number 18:45
you can also keep track of line numbers by doing `for $file.IO.lines -> $idx, $line { ... }` 18:48
nahita3882 forgot kv! 18:50
ab5tract oops! lol
thowe should it be $file.IO.lines.kv ? 18:51
yeah, that seems to work better, thanks :) 18:52
ab5tract and it might make sense to leverage `given/when`, `class Missing { has $.line; has $.idx }; my @missing; for split(',', $line).kv -> $field, $value { given $value { when *.chars == 0 { @missing.push: Missing.new: :$line, :$idx } ... }}`
thowe I seem to have solved most of my issues by coercing to string with .gist 18:53
ab5tract sorrhy, that's totally broken
hmm, that sounds like it might be a bit of an anti-pattern, but at the same time: TMTOWTDI! 18:54
.gist is a bit more verbose than .Str (or ~$foo) and a bit less verbose than .raku 18:55
thowe well, it's just Q&D so I can figure out how I want to build the schema I store these in... Basically just detecting unused fields and doing max length checks, etc... 18:56
also, it appears once I fixed a few other assumptions, that I was able to remove a lot of that stuff, fix some line placement, remove a line or two, and fixed the errors anyway. So, yeah, I was creating the issues myself it seems 19:00
ab5tract thowe: here's a non-broken example of what I was attempting above: gist.github.com/ab5tract/ea8ce7d74...c432265d6c 19:01
thowe: nice! definitely not trying to push you in any particular direction, just sharing some random tidbits 19:03
thowe I appreciate it, you are helping 19:05
gitlab.com/-/snippets/4788965 19:07
19:09 sjn joined
thowe can you see that? that's an example 19:09
19:13 sjn left 19:14 sjn joined
sampersand—2B +| +^2B == FF How do I repeat a list? (1, 2) xx 3yields ((1 2) (1 2) (1 2)), and i want (1 2 1 2 1 2) 19:22
and is !!! or ... preferred 19:23
antononcube You can use .flat. 19:24
19:25 sjn left
Or you can pre-slip: |(1, 2) xx 3 . 19:26
19:30 sjn joined 19:41 sjn left 19:47 sjn joined 19:51 sjn left 19:52 sjn joined
ab5tract thowe: yup I can see it. Looking good :) 20:03
20:07 sjn left 20:10 Heptite left 20:14 sjn joined 20:50 Heptite joined 20:57 lizmat left 21:09 lizmat joined 21:30 sjn left 22:01 sjn joined 22:12 sjn left 22:24 sjn joined 22:30 sjn left 22:37 sjn joined 22:45 sjn left 22:52 sjn joined 22:59 Heptite left