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.
a12l So it looks like self in this context is the string that "Bob" says. From what I understand, the straight forward way to enable this is to create a new subclass to Str that implements the role Bob, i.e. something like class A is Str does Bob. Is that correct? 00:06
Trying to figure out how I should have figured out how to implement it without looking at the solution, because even with the solution I'm wondering how I'm expected to figure it out 00:07
00:21 MasterDuke joined
rcmlz I looked up mine, I also used given/when … github.com/rcmlz/exercism-solution...ob.rakumod 03:50
When you implement/invent a new exercise for a language, you have to supply an default solution. Most coding things in Exercism are very regulated and automated - I like that project a lot. 03:53
05:29 sjn left 05:34 sjn joined 06:29 MasterDuke left
ab5tract a12l: you actually don’t need a subclass, you can apply a role directly to an object 07:38
m: role A { method m() { say self.WHAT } }; my $s but A = “foo”; $s.a 07:40
camelia Cannot modify an immutable 'Any+{A}' type object
in block <unit> at <tmp> line 1
ab5tract It’s always when I don’t test first with camellia 07:43
m: role A { method m() { say self.WHAT } }; my $s = “foo” but A; $s.m; my $i = 8 but A; $i.m
camelia (Str+{A})
(Int+{A})
ab5tract You can have methods dispatch for only a given type using the syntax you were using before 07:44
m: role A { multi method m(Str $self:) { say “I am but a Str: $self”}; multi method m(Int $self:) { say “I am but an Int: $self”}}; my $s = “foo” but A; $s.m; my $i = 8 but A; $i.m 07:48
camelia I am but a Str: foo
I am but an Int: 8
07:48 lizmat_ left 07:49 lizmat joined
ab5tract Or, if you don’t plan to use the containerized $self reference in the method, you can omit a name and use for ex. multi m(Str $:) to create the dispatch rule without injecting the reference into the method body 07:50
I hope that clears things up a bit. I also like exercism a lot but I would have to dig into the onboarding experience to say whether this feels appropriately set up by earlier questions 07:51
19:20 swaggboi left 19:21 swaggboi joined
a12l ab5tract: What does the but keyword do? Can't find documentation about it 21:30
ab5tract It’s like ‘does’ but per object 21:34
It is definitely harder to find than it should be: docs.raku.org/routine/but 21:35
a12l ab5tract: Thanks for the link! I'll look at it. 21:36
I'm looking at the explanation for given docs.raku.org/syntax/given 21:37
ab5tract My pleasure! It can be a bit daunting to dive into Raku, so keep asking any questions you run into 21:38
a12l Specifically the code snippet given 42 { .say; .Numeric; }. Trying to understand how the .<method> syntax works.
Is it because if you don't specify an object before the dot, it by default use $_?
ab5tract So the traditional name for a topic variable is $_ 21:39
Yeah, that’s exactly right!
a12l Thanks again! 21:40
ab5tract m: given “foo” { say .uc }
camelia FOO
ab5tract m: for ^5 { say .succ }
camelia 1
2
3
4
5
a12l Never seen that in any other PL
ab5tract Yeah, we like our shortcuts :)
a12l Is it common and I've never seen that, or is it Raku specific? 21:41
Not familiar with Perl, so don't know what is new with Raku, and what is inherited 🙂
librasteve m: say .uc given "foo"
Raku eval FOO
librasteve hehe
a12l How does that work with stuff in different orders?
Also seen examples with for and if 21:42
ab5tract I don’t think it’s super common, but it’s sort of a form of tacit programming so languages that trend in that direction might support it
lizmat one of the things you need to grok about Raku, are blocks and their signatures 21:43
librasteve if, for, given are "topicalizers" --- that means they set the topic for their block --- in perl and raku the topic is S_
(sorry $_)
lizmat m: my $a = -> $_ { .uc }; $a("foo")
camelia ( no output )
lizmat m: my $a = -> $_ { .uc }; say $a("foo")
camelia FOO
a12l The only languages that I've used that support tacit programming is Haskell and Uiua, and I guess they're different enough that I wouldn't see the similarities even if they'd a similar way to express it.
ab5tract In Perl you have to refer to the topic variable via $_ (well, as usual with Perl it’s more complex than that, but as a general rule it works) 21:44
antononcube Uiua? How about J? Or K?
lizmat and then you realize "for" just repeatedly calls a block 21:45
and "if" does so conditionally
sleep&
a12l @antononcube I'd only time for one array PL, so I choose the one that was stack based (wanted to test that for some time, want to look at Forth). Guess the second array lang I want to test out is BQN. Only have so much time 🙂 21:46
antononcube Or yeah -- Haskell-Shmaskell, very different from Raku from eclecticism POV.
librasteve these keywords (if, for, given) take form if $x > 0 { do_thing } and also there is a one-liner variant do_thing if $x>0 21:47
a12l In the example my $a = -> $_ { .uc }; say $a("foo"), how is say $a("foo") still part of the -> $_ { .uc }; block? 21:48
Or do I missread the code? 21:49
librasteve m: my $a = -> $_ { .uc }; say $a.WHAT; 21:50
Raku eval (Block) 21:51
antononcube @a12l Please, consider making Raku implementation of Uiua. Or at least a grammar. 21:53
librasteve so `$a("foo") is a function call where $a is the function and "foo" is the argument 21:54
ab5tract m: my &a = { .uc.say }; a “foo” 21:55
camelia FOO
ab5tract m: { .uc.say }(“foo”) 21:56
camelia FOO
ab5tract you don’t generally write -> $_ {…} because {…} gets the topic variable for free 21:58
If you want to ensure no arguments, you can use -> {…}
And you can store blocks in &-sigiled variables and call them like regular subroutines 21:59
Or, likewise, you can grab hold of regular subroutines by using &
m: my &s = &say; s “yo!” 22:00
camelia yo!
ab5tract Hope all that helps more than it hurts :) 22:01
&sleep for $me 22:02
a12l Thanks for all the help people! 22:03
ab5tract .&sleep for my $self = Inf; # grammatically accurate 22:04
a12l Ah, now I understand. say $a("foo") gets used as an argument to the lambda function > $_ { .uc }; say $a("foo") 22:05
ab5tract It’s actually that the block is stored in $a 22:07
librasteve m: { .uc.say }("foo") 22:08
Raku eval FOO
librasteve hehehe
ab5tract librasteve: I appreciate the giggles but it makes me curious about what’s funny :) 22:09
librasteve just me laughing at the power of raku - sorry I will desist 22:10
ab5tract Not at all, just wanted to understand
librasteve my poor sense of humour 22:11
ab5tract Seems like a mwahahaha would also be appropriate ;)
librasteve g'night
ab5tract so the scalar container (marked by the $ sigil) is more or less universal 22:12
and it gets different powers based on what is stored in it
m: my $a = [1,2,3]; say $a[2]; $a = %( :a(1), :b(2) ); say a<a>; $a = { .uc }; say $a(“block”) 22:15
camelia ===SORRY!=== Error while compiling <tmp>
Undeclared routine:
a used at line 1
ab5tract m: my $a = [1,2,3]; say $a[2]; $a = %( :a(1), :b(2) ); say $a<a>; $a = { .uc }; say $a(“block”)
camelia 3
1
BLOCK
ab5tract m: my $a = []; $a(“nope”) 22:16
camelia No such method 'CALL-ME' for invocant of type 'Array'
in block <unit> at <tmp> line 1
ab5tract As that error message indicates, a class (or role) can grant its objects $a(“arg”) semantics by defining a CALL-ME method (or multi methods) 22:18
Ok, out for real now. Happy hacking!
a12l Thanks ab5tract! 22:30