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. |
|||
01:30
m_athias left
01:31
m_athias joined
03:19
deoac left
06:42
kjp left
06:47
kjp joined
|
|||
jaguart | argh - I've just discovered that the conference day1 was yesterday! I thought is was Sat-Sun, and the email arrived saying 15:00 UTC... so I assumed Sat 16:00BST for me. :( will have to watch it on rewind | 09:44 | |
oh wait - today is already Sunday :o | 09:45 | ||
I think I'm lost in time... | |||
Nahita | :p | 09:50 | |
jaguart | m: say Version.new('1.2.3').Str | 09:59 | |
camelia | 1.2.3 | ||
jaguart | m: say Version.new('1.2.3').gist | ||
camelia | v1.2.3 | ||
jaguart | m: say Version.new('1.2.3') | 10:00 | |
camelia | v1.2.3 | ||
jaguart | this confused me for a while | ||
m: say Version.new('v1.2.3') | 10:01 | ||
camelia | vv.1.2.3 | ||
jaguart | m: say Version.new('v1.2.3').parts.join: ' ' | ||
camelia | v 1 2 3 | ||
lizmat | jaguart: hope you're in sync again now :-) | 10:29 | |
jaguart | extra coffee - catching up, 16:00 BST for the next zoom | 10:30 | |
Nemokosch | imma fix your delorean if that helps | 10:31 | |
jaguart | what would I use in a function signature for Int or Str-that-looks-like-Int, e.g. 0 or '0' | 10:41 | |
lizmat | m: sub a(Cool:D $a) { dd +$a }; a 42; a "666" | 10:46 | |
camelia | 42 666 |
||
lizmat | jaguart ^^ | ||
jaguart | That's Cool ;) thanks | ||
lizmat | this will also cover Num / Rat / Complex | 10:47 | |
Nahita | also Lists and Hashes right | 10:49 | |
but `Int:D()` also accepts Lists and Hashes | |||
jaguart | nice :) | 10:51 | |
m: sub x(Cool $a){ say $a,' is ',$a.^name };x(1);x('1');x('1.1.1'); | |||
camelia | 1 is Int 1 is Str 1.1.1 is Str |
||
Nahita | maybe `sub f($arg where * %% 1) { ... }` | ||
maybe `sub f($arg where * %% 1) { ... }` but this also accepts lists and hashes | 10:53 | ||
ok my overkill is `sub f(Int:D() $arg where {($_ ~~ Str|Int) && ($_ %% 1)}) { $arg.say }` | 10:55 | ||
in an attempt to "need an Int or Str which in numeric context equals to itself when decimals are removed; then coerce to integer" | 10:58 | ||
jaguart | Nahita - thanks 😮 | 11:05 | |
Nahita | ok my overkill is `sub f($arg where {($_ ~~ Str|Int) && ($_ %% 1)}) { $arg.say }` | 11:10 | |
in an attempt to "need an Int or Str which in numeric context equals to itself when decimals are removed" | |||
jaguart | I asked yesterday about Moo lazy builders -> and was pointed to raku.land(Attribute::Lazy) - which is fab, so... | ||
was hoping for the Moo handles -> qw/ list of methods /; - is there sugary syntax to proxy/delegate methods in Raku? | 11:11 | ||
e.g. has $meta will lazy { META6.new( file => './META6.json' ) } handles qw/ version /; | 11:12 | ||
which lazy-builds self.$meta and then passes calls to self.version through to $meta.version | 11:14 | ||
Moo also does method aliasing by using a hash instead of a list - e.g. handles { version => ver, major => primary, } etc. | 11:15 | ||
SmokeMachine | m: class C { has Int $.a handles < is-prime >= 42 }; say C.new.is-prime | ||
camelia | False | ||
jaguart | Smokin! thank you | 11:16 | |
CIAvash | docs.raku.org/language/typesystem#...it-handles | ||
jaguart | sorry - will search docs first next time! | ||
CIAvash | it's not a problem, there are just more examples there | 11:19 | |
jaguart | I got caught by Attribute::Lazy being in raku.land and searched there, without thinking to go back to the docs. | 12:46 | |
Anyone know about latest spec for META6.json - I see that github.com/jonathanstowe/META6 talks about 'raku-version' but that the META6 package in zef has slightly tweaked key 'raku', and the docs all talk about 'perl'... | 12:48 | ||
lizmat | I just go by with what App::Mi6 gives me on a new module | ||
:-) | |||
jaguart | Yeah - I've been using that too - but if I use META6 to load, read and write the META6.json I get a key-change | 12:49 | |
lizmat | ah, intriguing | ||
maybe skaji-san and rabidgravy should get in touch with each other :-) | 12:50 | ||
jaguart | hmmm - does that imply that all jonathanstowes like gravy? | ||
lizmat | you would need to ask them :-) | 12:51 | |
jaguart | btw - a huge thank you for all you do for raku - everywhere I look I see your hands 🙏 | 12:52 | |
deadmarshal | What is the equivalent of Perl's ntheory module in Raku? | 13:05 | |
metacpan.org/pod/ntheory | |||
lizmat | jaguart: you're welcome :-) | 13:08 | |
deadmarshal: I don't think there is a 1-to-1 translation | |||
deadmarshal | lizmat: ok thank u | 13:09 | |
lizmat | looks like it's no XS, so should be portable relatively easy, I'd say | 13:10 | |
deadmarshal | What is the reason behind %% operator? cuz one can simply do for example num1 % num2 == 0. | 13:16 | |
lizmat | well, the community wanted an operator to represent "is divisible by", and %% is just that | 13:17 | |
deadmarshal | Seems useless xD | 13:22 | |
lizmat | usefulness is in the eye of the beholder :-) | 13:24 | |
CIAvash | I'm sure you write `$x = $x + 1` instead of `$x++`, because you can simply do that | ||
deadmarshal | $x++ situation is different because ++$x and $x++ makes huge difference. but %% not so much | 13:27 | |
CIAvash | Then I guess you can also go and tell the Go community that their `x++` is useless because there is no `++x` in Go 😀 | 13:35 | |
then there is `+=`, `~=`, `[op]=`, `<=`, `>=` and other useless stuff | 13:43 | ||
Nahita | m: my @arr = 1..50; (@arr X[%%] (3, 5)).rotor(2).kv.map({($^val<> RZx ("fizz", "buzz")).join or @arr[$^idx]}).say | ||
seems useful to me :p | |||
Nemokosch | Insane stuff | 13:46 | |
Anyway, if you do anything with arithmetics, you'll appreciate %% | 13:47 | ||
Literally, why would you refuse a gift like this | |||
lizmat | m: my @arr = 1..50; (@arr X[%%] (3, 5)).rotor(2).kv.map({($^val<> RZx ("fizz", "buzz")).join or @arr[$^idx]}).say | 13:49 | |
camelia | (1 2 fizz 4 buzz fizz 7 8 fizz buzz 11 fizz 13 14 fizzbuzz 16 17 fizz 19 buzz fizz 22 23 fizz buzz 26 fizz 28 29 fizzbuzz 31 32 fizz 34 buzz fizz 37 38 fizz buzz 41 fizz 43 44 fizzbuzz 46 47 fizz 49 buzz) | ||
Nemokosch | Why is the reduction needed? | 13:53 | |
Nahita | uh, it's not actually, i guess i tend to write operators in square brackets as normally we do to refer them shortly like `&[*]` instead of `&infix:<*>` so... | 14:04 | |
to my defense, `X[%%]` looks better than `X%%` :p | |||
Nemokosch | You can very well be right, I'm not actually sure if it is a reduction in that position | 14:26 | |
14:58
andm joined
|
|||
andm | hello, i have string | 15:00 | |
'[["03","18","1","731","97"],["06","17.6","2","730","97"],["09","18.4","2","730","98"],["12","23.3","4","730","83"],["15","27.6","5","729","60"],]' | |||
is there a way to make raku think it's a raku code? | 15:01 | ||
15:15
deoac joined
|
|||
guifa_ | andm: you can use EVAL (with, of course, all of the security implications that that involves) | 15:16 | |
m: use MONKEY-SEE-NO-EVAL; my $string = '[["03","18","1","731","97"],["06","17.6","2","730","97"],["09","18.4","2","730","98"],["12","23.3","4","730","83"],["15","27.6","5","729","60"],]'; say EVAL $string; | |||
camelia | [[03 18 1 731 97] [06 17.6 2 730 97] [09 18.4 2 730 98] [12 23.3 4 730 83] [15 27.6 5 729 60]] | ||
guifa_ | You're required to use `use MONKEY-SEE-NO-EVAL` because of those security implications. | 15:18 | |
andm | guifa_, yes, it's works, thanks | 15:21 | |
deadmarshal | CIAvash: that is becuz go itself is useless Xd | 15:40 | |
15:42
Kaiepi left
|
|||
CIAvash | deadmarshal: I thought you would like Go, 'cause they share your way of thinking, "why X when you can simply do Y?" | 16:26 | |
deadmarshal | I like Oberon :D | 16:30 | |
16:39
Kaiepi joined
17:00
andm left
|
|||
Nemokosch | which reiteration of Oberon? | 18:14 | |
deadmarshal | 07 | 18:15 | |
Nemokosch | Tbh it looks worse than contemporary Pascal dialects at first sight | 18:19 | |
deoac | ``` | ||
class Foo { | |||
has Int @.bar[5,5]; | |||
} | |||
``` | |||
my $x = Foo.new; | |||
$x.bar[0;0] = 42 | |||
Nemokosch | 😅 | 18:20 | |
deoac | How can I write a postcircumfix operator so | ||
$x[[0;5]] | |||
does the same thing | |||
? | |||
Nemokosch | first off, I'd hope if you can do it, you can do it without overriding the operator itself, just overriding the method doing the access | 18:25 | |
AT-KEY that is, had to check | 18:26 | ||
do you mind if [0;5] is eventually [0,5] ? | 18:30 | ||
I mean, they are literals for the same data | |||
lizmat | only superficially so | 18:36 | |
m: dd [0,1,2,3] | |||
camelia | [0, 1, 2, 3] | ||
lizmat | m: dd [0,1;2,3] | ||
camelia | [(0, 1), (2, 3)] | ||
Nemokosch | I know I know | 18:49 | |
with this particular data, they are the same, not that , and ; are interchangable | |||
lizmat | oki :-) | 18:56 | |
Nemokosch | do you think I'm in the right with the general idea? 😛 | 18:57 | |
Kaiepi | the evil way would be to parse `qw` | 18:58 | |
deoac | No, I don't mind using either a comma or semi-colon | 19:00 | |
But when I've used a comma, I get an error: "Partially dimensioned views of shaped arrays not yet implemented. Sorry." | 19:01 | ||
Nemokosch | no worries, I think it can be "implemented" | 19:02 | |
m: class Foo { has Int @.bar[5,5]; method AT-KEY(\key) { @.bar[||key] } }; my $x = Foo.new; $x[[0;5]] = 42; dd $x.bar; | 19:16 | ||
aaalmost | |||
okay, I'm getting an error that I cannot immediately comprehend 😅 | 19:18 | ||
okay... yes, this would be with {} outside, not [] | 19:22 | ||
m: use 6.e.PREVIEW; class Foo { has Int @.bar[5,5]; method AT-KEY(\key) is rw { @.bar[||key] } }; my $x = Foo.new; my @idx = 0;5; $x{@idx} = 42; dd $x.bar; | 19:25 | ||
m: use v6.e.PREVIEW; class Foo { has Int @.bar[5,5]; method AT-KEY(\key) is rw { @.bar[||key] } }; my $x = Foo.new; my @idx = 0;5; $x{@idx} = 42; dd $x.bar; | 19:26 | ||
okay, let me dream big... | 19:27 | ||
m: use v6.e.PREVIEW; class Foo { has Int @.bar[5,5]; method AT-KEY(@key) is rw { @.bar[||@key] } }; my $x = Foo.new; $x{[1; 2]} = 42; dd $x.bar; | 19:28 | ||
Expected Positional but got Int | 19:31 | ||
well, rip me. I have no clue why an Int got passed... | |||
my best guess is that some sort of "single argument rule" applies, I don't know though | 19:32 | ||
m: use v6.e.PREVIEW; class Foo { has Int @.bar[5,5]; method AT-KEY(@key) is rw { @.bar[||@key] } }; my $x = Foo.new; $x{([1; 2], )} = 42; dd $x.bar; | 19:33 | ||
annoying | 19:34 | ||
so the last one worked but it also got quite ugly | |||
m: use v6.e.PREVIEW; class Foo { has Int @.bar[5,5]; method AT-KEY(@key) is rw { @.bar[||@key] } }; my $x = Foo.new; $x{$[1; 2]} = 42; dd $x.bar; | |||
deoac: my best attempt probably | 19:35 | ||
gotta wait for pros | |||
19:45
Nemokosch joined,
Nemokosch left
|
|||
Kaiepi | m:``` | 20:10 | |
only postcircumfix:<⟦ ⟧>(Mu \topic, @values is raw) { @values } | |||
dd 1⟦[ 2, 3; 4, 5 ]⟧; | |||
dd 1⟦( 2, 3; 4, 5 )⟧; | |||
``` | |||
something along these lines? | |||
not sure on how to do it w/o unicode without making it 6 characters | 20:12 | ||
something with a signature along these lines? | |||
Nemokosch | so this is a brand new operator? | ||
guifa_ | AT-KEY is for hashy stuff | 20:13 | |
AT-POS is for listy | |||
lizmat | Associative actually | ||
guifa_ | hence the -y ;-) | 20:14 | |
Kaiepi | partly. it wraps `[ ]`/`( )`, which does the dirty work with `;` | ||
guifa_ | Associative is like.... 6 letters more or something | ||
lizmat | hehe | ||
Nemokosch | yes, it was associative | ||
but I don't think it would have worked with positional | |||
hence with [] | |||
Kaiepi | oh i see | 20:18 | |
hold on | |||
oh that's cryptic | 20:32 | ||
m:``` | |||
use v6.e.PREVIEW; | |||
class Foo does Positional { | |||
has Int @.bar[5;5]; | |||
method ASSIGN-POS(+@dimensions) { | |||
@!bar.ASSIGN-POS: |my @[3] = @dimensions | |||
} | |||
} | |||
my Foo $x .= new; | |||
$x[0;0] = 1; | |||
say $x; | |||
``` | |||
it wants dimensioned arguments | 20:33 | ||
Nahita | m:``` | 20:34 | |
class F { | |||
has @.arr[2;3]; | |||
submethod TWEAK { | |||
@!arr := [[1, 3], [4, 5], [6, -1]]; | |||
} | |||
} | |||
multi sub postcircumfix:<[; ]>(F $obj, @indices) is raw { | |||
callwith($obj.arr, @indices); | |||
} | |||
my $f = F.new; | |||
say $f[1;1]; | |||
say $f[2;0] **= 3; | |||
say $f; | |||
``` | |||
m: ``` | |||
class F { | |||
has @.arr[2;3]; | |||
submethod TWEAK { | |||
20:35
discord-raku-bot left,
discord-raku-bot joined
|
|||
m:``` | 20:35 | ||
class F { | |||
has @.arr[2;3]; | |||
submethod TWEAK { | |||
@!arr := [[1, 3], [4, 5], [6, -1]]; | |||
} | |||
} | |||
multi sub postcircumfix:<[; ]>(F $obj, @indices) is raw { | |||
callwith($obj.arr, @indices); | |||
} | |||
my $f = F.new; | |||
say $f[1;1]; | |||
say $f[2;0] **= 3; | |||
say $f; | |||
``` | |||
Kaiepi | (shouldn't have `does Positional`) | 20:37 | |
Nahita | can these be done with `handles` i'm not sure | ||
i.e., i don't know :p | 20:38 | ||
Kaiepi | i think that winds up an awkward `FALLBACK` | ||
it needs a method name | 20:39 | ||
it needs a method name to dispatch to generically | |||
a method would need to take a method name to dispatch to generically | |||
deoac | How can you return an l-value? | 21:43 | |
That is, I want to modify the variable that's being returned. | 21:44 | ||
Nemokosch | my code had an example for that as well | 21:45 | |
Nahita's code as well | |||
define the function as "is rw" (if its always an lvalue) or "is raw" (if it should be kept as-is) | |||
gfldex | deoac: see: docs.raku.org/language/control#ind...-return-rw | 21:47 | |
Nemokosch | the way I understand it: if you pass a bare value to "is rw", it fails; if you pass it to "is raw", it won't fail but obviously you will only get the bare value back, without a container | ||
deoac | ah, thank you | 21:51 | |
Nemokosch | Well we didn't use return so... yeah. 😄 There are two ways now, at least | 22:00 |