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.
:(**@args, *%kwargs) is there a way to "unbound" a method then bound them back to another object 01:05
Nemokosch there is method_table on the metaobject 01:12
I did manage to delete a method from a class using that 01:13
oh I can see the risk
you need to make sure that the self argument is set up in a way that supports both the original class and the new class 01:14
:(**@args, *%kwargs) im trying to recreate super which is just evaluating superclass methods in the context of current object so i think its safe 01:17
is it like this? Someclass.^method_table::mymethod and then the object i get is a sub? 01:25
Nemokosch do you state that or is it just wishful thinking? 01:26
:(**@args, *%kwargs) yeah its just thinking
Someclass.^method_table<mymethod> 01:27
ok this is right
m: class C { has $.x; } my $a = A.new(x => 1); say C.^method_table<x>($a:); 01:31
m: class C { has $.x; } my $c = C.new(x => 1); say C.^method_table<x>($a:);
m: class C { has $.x; } my $c = C.new(x => 1); say C.^method_table<x>($c:);
what
m: class C { has $.x; } my $c = C.new(x => 1); say C.^method_table<x>($c); 01:33
nice 01:34
m: class C { has $.x; } my $c = C.new(x => 1); say $c.^method_table<x>($c); 01:36
Nemokosch 👋 😴
:(**@args, *%kwargs) gn 01:37
why doesn't it work notably if i change has $!o to has $.o it worked again 02:07
glot.io/snippets/ghoxb47ub4 02:08
Rog oh wow, colors are working now 02:55
02:56 kjp left 03:00 kjp joined
stevied ok, this is unexpected for me: 04:39
m: class Box { has $.data; multi method new($d = '') { say 'here'; self.bless(data => $d); } } my $box = Box.new('hi'); say $box.data; my $box2 = Box.new(data => 'be'); say $box2.data;
I don't know why the same new method gets called for different arguments
now look at this:
m: class Box { has $.data; multi method new($d) { say 'here'; self.bless(data => $d); } } my $box = Box.new('hi'); say $box.data; my $box2 = Box.new(data => 'be'); say $box2.data; 04:40
when I take away the default value for $d in new(), it works as expected
what explains this?
I don't expect multi method new($d = '') to get called with Box.new(data = 'be') 04:43
stackoverflow.com/questions/752654...unexpected 04:56
05:17 Heptite left
ok, it works if I slap an is built to the $data attribute. always wondered what is built was for 05:20
:(**@args, *%kwargs) i think raku choose to call new($d = '') because it can accept no positional args 07:08
i don't know enough of raku dispatch rules 07:09
stevied I asked on SO and got a good answer.
stackoverflow.com/a/75265629/1641112 07:10
The *%_ special variable makes it override Mu’s new() 07:11
:(**@rest, *%rest) hmm implicit *%_ 07:17
another thing to note when writing signatures 😭 07:18
stevied Heh. Right. I didn’t even know about it until last week. 07:24
Lots to keep track of. 07:25
Every time I go back and read the docs I learn more and more subtle stuff I missed or didn’t get before.
:(**@rest, *%rest) this is why explicit better than implicit 07:27
stevied Yeah. I was just thinking the same thing. Better to spell everything out even if it results in more code. At least at first. 07:28
Unfortunately, I like to drive myself crazy trying different things to see if I can get them to work. 07:31
:(**@rest, *%rest) idk why you have to override new and use bless 07:36
which are preferred methods to create custom constructor use BUILD or override new? 07:39
stevied Depends if you need to override the constructor methods. 07:42
New does not call parent new. So you use BUILD in that case.
I was trying to figure out how to do things without a BUILD method. It makes things a little harder with just new() method. 07:44
I like to see how I can do things with minimal code. I do learn a lot that way. 07:45
:(**@rest, *%rest) is there a turtle module in raku 08:17
Nemokosch Logo stuff? 09:25
@stevied I think by now you know but yeah... by default, any named argument can be discarded from a call 09:26
Tbh feels like a legacy thing, I wonder what the cost of a change would be
:(**@rest, *%rest) yeah 09:40
Nemokosch When I googled it, I got "Raku fetish turtle" xdd 09:42
:(**@rest, *%rest) raku is not that widely used and its only 8 years old so there is room for change 09:43
Zephyr I skipped a few words at first glance and was wondering why you'd google that
Nemokosch would the turtle module have its own graphics? 09:45
how does the Python version work
I see there is a Perl module that comes completely without graphics, only holding the state
:(**@rest, *%rest) it can use the canvas widget of existing gui frameworks
in fact that is what python does 09:46
Nemokosch > The turtle module provides turtle graphics primitives, in both object-oriented and procedure-oriented ways. Because it uses tkinter for the underlying graphics, it needs a version of Python installed with Tk support. hmmm 09:48
just to reiterate @:(**@rest, *%rest) are you running Rakudo on Windows? 09:51
:(**@rest, *%rest) yes, tho i mostly use glot 09:52
gfldex Most of the time, TWEAK works best. 10:02
Nemokosch to quote vrurg, BUILD should rarely ever be used 10:07
new is good if you want to create multiple creation interfaces to the same underlying data, mainly 10:08
TWEAK is kind of a final step in the creation, default values and blessing stuff has already happened by that time iirc 10:09
it would be interesting to see how much of stuff works well on Windows 10:13
I mean hopefully the core would work without any problems 10:14
but there are many libraries where this is not obvious
also, the filesystem is different, I think that's leveraged with an underlying multiplatform C library
and the "JVM backend" probably does its usual Java business 10:15
gfldex Pretty much the first thing I had to learn was to Introspect All The Things!, because the compiler had so many bugs. If you do the same, you will spot all the hidden gems. I strongly disagree that explicit is better, because that is a statement of opinion, not of fact. Most of the time I don't want to deal with all the details. It's just to much cognitive load. Being able to step back and look at the whole 10:20
picture will come with time. Or it wont. It's not a given that a good programmer will "get" Raku. Nor should we aim for that. One size fits all has never worked well.
Nemokosch by the way, consider trying @jaguart 's Grok module 10:21
I suppose he wrote it with similar thoughts in mind - it would be good to see how the underlying data is composed before making any assumptions 10:22
10:52 NemokoschKiwi joined 11:21 NemokoschKiwi left 11:33 ab5tract joined 11:58 ab5tract left, ab5tract joined 12:12 snonux joined 12:34 ab5tract left
btw I wonder what the most stable choice is if somebody wants to do graphics with Raku 13:04
there are many GTK ports but I barely know GTK
13:13 snonux left
:(**@rest, *%rest) maybe make yet another tcltk binding? 13:22
Nemokosch tbh could be 13:25
I'd assume it has a C interface? 13:26
13:38 NemokoschKiwi joined 13:41 NemokoschKiwi left
:(**@rest, *%rest) don’t know how python does it but i assume its just sending a bunch of commands to the tcl backend 14:00
14:45 raschip joined
stevied Well if your immediate objective is to just get the code to work the way you expect, best to not try anything fancy and spell things out. 14:52
Raku is fairly easy if you stick to the straightforward stuff. It’s when you try to take advantage of all its conveniences it seems to get a lot harder. At least for me. 14:53
:(**@rest, *%rest) sometimes tho raku places assumptions on where you don’t expect which is where its better to be explicit 15:08
like the named argument thing
or just better to read the docs 15:14
stevied yeah, I guess if I pass a Pair to a constructor with a key that does not exist as an attribute, I assume I would get some kind of warning. But maybe that's just a bad assumption on my part. 15:16
15:16 Heptite joined
:(**@rest, *%rest) m: class A { has $.x; } A.new(:nope); 15:17
stevied but I don't know how I went a year in Raku without knowing about *%_.
:(**@rest, *%rest) m: class A { has $.x; } dd A.new(:nope);
raku belike 15:18
Nemokosch I remember Bruce Gray talking about this on a Raku Study Group meetup 15:19
(next one is tomorrow btw)
:(**@rest, *%rest) also Any being both the base class and the equivalent of undefined :cameliathink:
Nemokosch for the attribute of sort
:(**@rest, *%rest) (this has been talked to death i know)
anyways how to make class methods 15:20
Nemokosch is it not enough that you invoke the method on the type object? 15:22
stevied class methods are explained well in docs 15:28
:(**@rest, *%rest) basically i have a class variable representing shared data and i want to have class methods to access them ok the question should be “how to make class variables”
Nemokosch try my-scope inside the class, I'd say 15:29
:(**@rest, *%rest) class method have a ::?CLASS:U type constraint on the invocant
15:30 snonux joined
stevied docs.raku.org/language/objects#Cla...ce_methods 15:30
for like a class variable, just use a regular old "my" variable 15:33
:(**@rest, *%rest) hmm that means i can also define subs in class bodies my sub something { ... } not sure how that would turn out 15:34
stevied yes, you can do that. no problem 15:35
this is what I have done
look at example at the bottom of this section: docs.raku.org/language/objects#Obj...nstruction 15:36
the example is introduced with "Here is an example where we enrich the Str class with an auto-incrementing ID:"
:(**@rest, *%rest) how do i pad a number with zeros 15:40
in its string representation 15:41
Nemokosch I'd definitely just use sprintf
:(**@rest, *%rest) ok
Nemokosch with the arguments known from C
:(**@rest, *%rest) m: printf(“%2d”, 1) 15:42
m: printf(“%10d”, 1)
m: printf(“%010d”, 1) 15:44
m: class TV { # class my %tvs; method tvs(::?CLASS:U:) { %tvs } # instance has $.owner; submethod BUILD(:$!owner) { my $tv-serial = 'TV%04d'.sprintf(%tvs.elems); %tvs{$tv-serial} = self; } } TV.new(owner => 'foo'); TV.new(owner => 'bar'); TV.new(owner => 'baz'); TV.new(owner => 'quux'); dd TV.tvs; 15:57
i think this is how it works 15:58
Nemokosch nice 16:12
16:27 snonux left 16:31 snonux joined
p6steve personally I would go method tvs(TV:U:) {...} instead of method tvs(::?CLASS:U:) {...} that just seems a bit clearer... 16:34
:(**@rest, *%rest) should i put the code inside the BUILD body in TWEAK or new? 16:36
p6steve ... (I see that the docs don't mention my way ... so perhaps it has some issues) 16:37
:(**@rest, *%rest) or keep it there?
p6steve ... I usually go with TWEAK since then I can use all the attr defaults and so on
... or I use multi method new() to hone down a variety of creation options 16:38
:(**@rest, *%rest) conceptually it assigns a serial number to the TV instance and put it in %tvs 16:39
which is why idk where would it fit 16:40
BUILD or TWEAK
raschip The usual recommendation is to go with TWEAK, using BUILD will disable a ton of features you'd have to implement yourself. 16:41
16:43 snonux left
:(**@rest, *%rest) ok 16:48
stevied @gfldex wrote something up years ago about throwing an exception when bad name arguments are passed: perl6advent.wordpress.com/2015/12/...d-methods/ 17:35
p6steve raschip++ 18:32
18:38 ab5tract joined 19:03 ab5tract left 19:53 ab5tract joined
stevied i found a bug in the fez module: my $regex = $_.split('*').map({$_ eq '' ?? '.*' !! "'$_'"}).join(''); rx/ <$regex> / 20:52
^^ broken code 20:53
Nemokosch could you elaborate?
stevied If I remove the angle brackets from the second line, it works
let me get you the module file that's broken 20:54
github.com/tony-o/raku-fez/blob/64...akumod#L13
so, if there is a .gitignore file in the directory the module just hangs 20:55
why is that $regex scalar in angle brackets? 20:56
Nemokosch I don't know, maybe let's ask tonyo 20:59
stevied I plan to, but I want to try to make sure I understand the bug. 21:00
docs.raku.org/language/regexes#Reg...erpolation 21:01
I haven't read it but it looks confusing as shit
Nemokosch one thing is sure: <$foo> and $foo is not the same 21:02
stevied ok, so I think I get it 21:03
not sure how this could go unreported for so long
Nemokosch <$foo> seems like some secret way to turn a string into a regex
stevied and seems like it should be caught by a test
there really are hardly any tests for fez module
Nemokosch well, what do you get exactly 21:04
stevied what do I get when I use fez with a .gitignore file? It just hangs forever 21:05
when I remove the angle brackets, it creates a tarball in sdist
and it doesn't hang
21:07 raschip left 21:09 raschip joined
Nemokosch hmm, the truth is 21:11
I'm not sure if I published anything with raw fez in the last 3 months, when this change happened
but if it's really as you say, indeed it's strange that nobody reported it 21:12
21:14 ab5tract left
stevied the lib/Fez/Util/Pax.rakumod was added on 10/15/2022 21:17
so it's new
alright, well, I guess I got enough to write a decent report
all those maps and greps are confusing as hell, though. I don't understand what's going on with the manifest. seems like that could or should be greatly simplified 21:18
I don't understand this part of the Fez readme: #### using pax pax is the bundler included with v38 onward to avoid compatibility issues with certain BSDs. git archive is no longer used as it caused a lot of confusion - this means that what's on disk is what is getting bundled rather than what is in main/master! #### using git archive (deprecated with v38) fez will attempt to run `git archive` which 21:21
will obey your `.gitignore` files. it is a good idea to put sdist/ in your root gitignore to prevent previously uploaded modules.
it says git archive is "no longer used" and then in the next section is says it's deprecated 21:22
oh, maybe I have to put sdist into the gitignore. maybe that's why it's hanging. it's recursive
nope, still hangs 21:25
now I wonder if I switch to 2022.07 if it will work. let's see 21:35
holy shit. it worked. 21:36
using same version of fez
i think this is a bad bug in rakudo 21:39
Nemokosch hmmmm 21:46
does the regex work differently? @stevied
stevied it must 21:49
I will try to confirm. Can you see if you can reproduce? 21:50
Nemokosch which part? 21:54
stevied see if you can do fez upload on directory with a .gitignore file in 2022.07 and 2022.12 21:55
lizmat fwiw, I've uploaded the latest App::Rak using 2022.12+ on Mojave without any problems (yes, it has a .gitignore file) 21:57
stevied ok, thanks 21:58
now it's hanging for me again on 2022.07. very weird
I think I must have been using my local, hacked version of fez and didn't know it 21:59
/lizmat are you on a mac?
lizmat uploading from Monterey 22:00
22:07 MasterDuke joined
Sparkill ogl 22:08
stevied i'm not sure why the presence of .gitignore would make a difference in ventura and not monterey 22:13
i have a copy of monterey though. i can try on that 22:14
Nemokosch I'd say, you are already a squashathon participant, de facto 😉 22:16
stevied heh 22:19
fuck. hangs on my old mac running big sur running 2022.06
none of this makes any sense. 22:20
Nemokosch could you please log the content of the @ignores variable? 22:21
stevied sure 22:22
Nemokosch Fez could really use a verbose mode tbh
stevied [method rx/ <$regex> / method rx/ <$regex> / method rx/ <$regex> / method rx/ <$regex> / method rx/ <$regex> / method rx/ <$regex> /]
that's what I got
doesn't look like it would work 22:23
looks like a mess
Nemokosch well it could work imo, the textual form is ugly though 22:24
regexes are kind of methods
stevied i don't get why there are repetitive methods, though 22:26
makes no sense to me
oh, it's an arry of methods
Nemokosch for the lines of the gitignore file
lizmat could be that the rendering of each regex is incomplete / incorrect
stevied I keep forgetting that arrays use whitespace separators
Nemokosch you could use dd @ignores (in this case, I don't expect anything informative tbh) 22:27
one thing I have a bad feeling about is any 22:28
junctions can have cunning issues
what could really help with knocking the regex part down is logging $regex itself, to see if it's as lizmat said 22:29
stevied tried with Data::Dump and it's a giant mess of output 22:30
Nemokosch I just meant everyday dd 22:31
stevied here's $regex: '.precomp/' '/Directory-'.* .*'.iml' .*'.idea' 'sdist/' .*
Nemokosch okay, thanks
it seems valid, at least 22:32
stevied remember, when I remove .gitignore, everything works
gotta be a bug in the module
Nemokosch I mean, this piece of code only runs when .gitignore is present 22:33
stevied right
if it works for liz, maybe it's something in the .gitignore itself
22:33 raschip left
Nemokosch but sometimes it worked for you as well with the same data, right?? 22:34
stevied ok, yeah, when I pull some lines from gitignore, it work
got it 22:35
there's a blank line at end of the .gitignore. makes it choke
Nemokosch "null regex not allowed" 22:36
stevied ok, cool. now I can relax 🙂
or, at least, I can move on to the other fez bug 🙂 22:37
Nemokosch makes it choke???
that's the .* right there 22:38
but why should that make it choke? 🙀
stevied yeah, choke. crap out. fuck up.
it just hangs
more technically, it hangs when trying to read the .exitcode on the pax command 22:39
not sure why
Nemokosch could you log the @manifest please? 22:42
maybe we've been going the wrong way all along?
stevied with or without the blank line in .gitignore?
Nemokosch maybe both 22:43
I'd expect there to be a difference between the two cases 22:44
stevied k, one sec
trying to see if I can upload via mi6 right now. have to install some modules
wow! mi6 release now works on 2022.12 for me 22:48
ok, let me check manifest 22:49
with no blank line in .gitignore: [META6.json LICENSE Changes t/02-more.rakutest t/01-basic.rakutest xt/Author-Tests.rakutest README.md lib/Directory.rakumod dist.ini] 22:50
with blank line: [] 22:51
so that's definitely the problem
Nemokosch well yeah the empty repo is not healthy xD
.gitignore itself ignores empty lines, right?
stevied well, it's proper to end all files with a blank line 22:52
that's the way all text files are supposed to be
Nemokosch well I hope not cause it's ugly but anyway 😅
I think .gitignore doesn't give a damn about empty lines 22:53
and they definitely don't ignore the whole folder
stevied yeah, I highly doubt it doesn't like them
www.oreilly.com/library/view/versi...05s08.html
^^ say blanks lines are ignored 22:54
Nemokosch yep, cool
then this is one definite bug in fez
stevied more tecnically, ever text file should end with \n 22:55
it just looks like a blank line in your editor
but it's not blank. it doesn't exist
Nemokosch empty line - turns into .* as a regex - matches everything, boom, all files gone
tbh I'm not sure about .* 'some string' either 22:56
stevied yeah, you're going to have to explain that to me. why is it wiping files out?
I know what .* is obviously, but not in the context of this file collector
why doesn't it match every file instead? 22:57
Nemokosch because it's negated in the code
the output of any
stevied i can't wrap my head around that ls sub in there. too confusing 22:58
Nemokosch looks quite bizarre, with ! and .so at the same time
do you have .iml or .idea files in your folder?
stevied you'd have to spend a half hour breaking that down (at least I would)
yeah. .iml and .idea 22:59
Nemokosch hm, those are (rightfully) sorted out
idk the backtrack rules of regex 23:00
but they fit this use case apparently
stevied got to be an easier way to generate the file listing that excludes what's in .gitignore than this 23:01
it's just a mess
is what 's in .gitignore even regexes?
that doesn't seem right at all 23:02
not regexes raku would understand anyway, I wouldn't think
Nemokosch this is not a sentence I would understand anyway 😛 23:03
stevied it looks like the fez code treats each line in .gitignore like a raku regex. 23:04
Nemokosch well regexes are more powerful than .gitignore patterns I think
stevied i have very strong doubts that this a proper method for determining which files to ignore
Nemokosch so this can work
buuut 23:05
I'd rather wish for this to be outsourced into its own module
that does this in a sane, foolproof way
stevied this is possible in .gitignore: A trailing "/**" matches everything inside. For example, "abc/**" matches all files inside directory "abc", relative to the location of the .gitignore file, with infinite depth.
Nemokosch with tests, right?
stevied raku doesn't know how to interpret /**
Nemokosch or, another approach
(what mi6 does) 23:06
git ls-files
and call it a day
stevied this definitely needs tests, yeah
but this has a custom ls command
doesn't use mi6
Nemokosch I mean, the whole "what files need to be saved" is intended to be "all tracked files", no? 23:07
I'd guess so
stevied I presume. but the readme for fez says he is moving away from git acrhive
it looks like it's doing a roll your own method for collecting files. not a super trivial task, if you ask me 23:08
Nemokosch there's also this
raku.land/zef:lizmat/Git::Files
stevied yeah, should probably outsource to that module 23:09
Nemokosch this also runs git ls-files under the hood
stevied maybe tony-o cargo culted from mi6 or this module 23:10
Nemokosch actually this is an interface to git ls-files
stevied alright, at any rate, I gotta go get ready for dinner. check you later. thanks again for helping me brainstorm this. helps me find the problem sooner 23:11
Nemokosch 🤝 23:14
bon appetit
Sharparam i am at a loss at what's going on here: perl [6] > my @pairs = [(2..4, 6..8), (2..3, 4..5), (5..7, 7..9), (2..8, 3..7), (6..6, 4..6), (2..6, 4..8)] [(2..4 6..8) (2..3 4..5) (5..7 7..9) (2..8 3..7) (6..6 4..6) (2..6 4..8)] [7] > @pairs.map: { $_[0] ~~ $_[1] } (True False False False False False) [8] > @pairs.map: { my ($a, $b) = $_[0], $_[1]; $a ~~ $b } (False False False False True False) why does it 23:20
behave different if each Range in the pair is assigned to a variable? i must be missing something fundamental
Nemokosch hello hello 23:27
the second version seems right... :cameliathink: 23:33
oh, I have my suspicion
~~ alters $_
I'm curious if this ever worked differently, then I'll be back to you with an interpretation @Sharparam 23:35
Sharparam yeah the second version produces the expected result, i'm not sure what the first one actually does 23:36
Nemokosch "nothing to bisect" says the bot - this always worked this way (since 2015 at least) 23:37
Sharparam hm, "The smartmatch operator aliases the left-hand side to $_" 23:38
i wonder if that's why
Nemokosch docs.raku.org/language/traps#Topic..._operators
yes
Sharparam right, that makes sense then 23:39
Nemokosch so it's like
you fetch the left range
temporarily rename it $_
Sharparam so a more compact way to do it would be: @pairs.map: { [~~] $_ } 23:40
Nemokosch well, almost 23:41
tbh I didn't expect it to work but the result got even more interesting than I thought
m: my @pairs = [(2..4, 6..8), (2..3, 4..5), (5..7, 7..9), (2..8, 3..7), (6..6, 4..6), (2..6, 4..8)]; say @pairs.map: { [~~] $_ }; 23:42
this is where one would want to give up 🤠 but there is a remedy 23:43
m: my @pairs = [(2..4, 6..8), (2..3, 4..5), (5..7, 7..9), (2..8, 3..7), (6..6, 4..6), (2..6, 4..8)]; say @pairs.map: { [~~] $_[] };
I'm rather surprised that this works
Sharparam curious 23:44
it also works if binding instead: perl [0] > my @pairs := (2..4, 6..8), (2..3, 4..5), (5..7, 7..9), (2..8, 3..7), (6..6, 4..6), (2..6, 4..8) ((2..4 6..8) (2..3 4..5) (5..7 7..9) (2..8 3..7) (6..6 4..6) (2..6 4..8)) [1] > @pairs.map: { [~~] $_ } (False False False False True False) [2] > my @pairs = (2..4, 6..8), (2..3, 4..5), (5..7, 7..9), (2..8, 3..7), (6..6, 4..6), (2..6, 4..8) [(2..4 6..8) (2..3 4..5) 23:45
(5..7 7..9) (2..8 3..7) (6..6 4..6) (2..6 4..8)] [3] > @pairs.map: { [~~] $_ } (True True True True True True)
Nemokosch the important thing is to get rid of the container
m: my @pairs is List = (2..4, 6..8), (2..3, 4..5), (5..7, 7..9), (2..8, 3..7), (6..6, 4..6), (2..6, 4..8); say @pairs.map: { [~~] $_ }; 23:47
container = mutation + itemization
and the values of an array always come in containers 23:48
okay now I understand why it works, after all 23:49
there is no $_ lookup between the operands, it all happens before starting with the operator 👏 23:50
Sharparam right
Nemokosch how long have you been using Raku? you don't seem that much of a beginner 23:51
Sharparam a bit on-and-off for a while, i come back to it occasionally, i still feel like a beginner in it though :p 23:53
i've been mostly translating advent of code solutions from ruby to raku to get more familiar with it
Nemokosch oh okay, have fun 23:54
Ruby did seem kind of like a language inspired by Perl, too
Sharparam yeah, perl and smalltalk iirc? 23:55
Nemokosch Well, I don't know much about Smalltalk but it Ruby does look visually similar that's for sure 23:58
Sharparam never used smalltalk myself either. long ago a friend introduced me to ruby on rails and since then ruby has just *clicked* with me ^^ 23:59