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.
03:30 teatime joined 03:31 teatime left 04:11 ab5tract left 04:13 ab5tract joined 05:28 siavash joined 05:34 ab5tract left 05:37 ab5tract joined 05:41 ab5tract left 05:43 ab5tract joined 07:51 dakkar joined 08:21 tea3po left, tea3po joined 09:20 wafflus joined
wafflus is this supposed to work? my @even_numbers = @numbers.where: { $_ % 2 == 0 }; 09:20
i got that from ai but where does not seem to work i'm guessing it only used when declaring vars and functions? 09:21
antononcube It looks like good enough hallucination. 09:46
wafflus '=D 09:47
if i have a list of numbers can i use @numbers.grep to select only unique values that match a pattern (2 for example) i've tried using junctions and ~I can't get it correct 09:49
i know there is a unique function but i want to see if its possible using grep 09:50
i thought maybe i could use some sort of junction but cant seem to get it to work 09:51
09:51 siavash left
nemokosch Probably it's for a reason 09:56
Nahita junctions, idk. with a state variable you can simulate .unique with grep py In [12]: my @nums = 12, 3, 4, 12, 5, 22, 2, -2, 222, 0, 4, 222 Out[12]: [12 3 4 12 5 22 2 -2 222 0 4 222] In [13]: @nums.grep: { /2/ && !%.{$_}++ } Out[13]: (12 22 2 -2 222) 10:01
% is the anonymous state variable here, a Hash
wafflus cool ty 10:02
Nahita it employs the "seen" idiom: we check !%.{$_} first, i.e., has this number not seen yet 10:03
++ marks it seen via autovivification the first time; for other (second+) times, it's a normal increment of the value
wafflus so autovivification will only increase the value on the 2nd pass? 10:04
or 2nd value rather 10:05
Nahita in the first pass, it doesn't exist at all in the hash. so it will autovivify it and give it a value 1 in the hash table
if it is encountered more from then on, it will be 2, 3, 4 etc.
all are nonzero numbers and will say "i have seen this number before", and grep won't include it 10:06
wafflus !%.{$_} does the ! mean falsify? 10:07
Nahita yeah it negates
wafflus k
nemokosch $var++ on an undefined value will yield 0 and increment that
Nahita . between the variable % and lookup {$_} was needed otherwise it thinks i'm trying to form a Hash with 1 element ($_) 10:09
since {...} operator is like a method, . is puttable in between there
nemokosch The reason it has to be so compact is that these anonymous variables can't be backreferenced 10:10
Nahita same for array indexing, i.e., @val.[...] is valid to say instead of @val[...]
wafflus pretty cool stuff  but how come /2/ works in your example but not 2? i take it /2/ is a regex I would have thought 2 would work but the result is different 10:13
nemokosch 2 is merely True in boolean context 10:14
Nahita in a boolean context, a regex automatically matches against the topic $_
nemokosch 2 && x will always evaluate to x
Nahita so it's as if written as $_ ~~ /2/ && ...
you can also do .contains(2) for this specific case BTW 10:15
wafflus k i think i understand
Nahita like .grep: { .contains(2) && ...}
a bare 2 would be the value 2, no $_ involved 10:16
and it's truthful, so it's a no-op in &&
nemokosch while going through the grammar, I noticed that even something like $var.++ would work 10:17
somebody really liked this dot notation
wafflus :)
dakkar nemokosh: IIRC, the reason for that is the "unspace": since Raku cares about whitespace, you can't just write `$var ++`, and some people *really* like being able to vertically align their method/postfix calls 10:24
nemokosch $var\ ++ seems to work, what am I missing? 10:26
dakkar after some very vocal complaints, the syntax `$object.\ method()` was added
(you were missing the second half of my remembrance 😜)
`$var\ ++` is fine when you need to add 2 columns
but `$var\++` won't work (I'm pretty sure there's very good reasons to not parse it as a postfix call) 10:27
so you can `$var.++` to add 1 column
nemokosch yeah the fact that you can only add spaces in front of a schoolbook method call is odd and bothering tbh 10:28
dakkar 😁 is there _any_ feature of Raku that you like? Or do I only notice when you're bothered by something?
nemokosch survivor bias I guess
dakkar probably
_elcaro_ That almost worked... and for a very brief period in 2016, it might have. A long time ago, I advocated for aliasing grep to where. 10:29
nemokosch not even other "dotty calls", and to make it worse, once you detached a method, no matter how much you attach the rest of your postfixes to it, they will be considered detached and broken
dakkar nemokosh: I don't understand that sentence
nemokosch a.&bar works 10:30
a .foo also works
but a .foo.&bar doesn't work
the a .foo proactively infects the rest of the expression 10:31
dakkar uh?
m: class A { method foo() { return self } }; sub bar($thing) { say "got $thing" }; A.new.foo.&bar
camelia got A<4643776846560>
nemokosch well, try it yourself
you forgot the space after A
or after new, as you prefer
dakkar ooh, right 10:32
I didn't even know that `$object .method` was allowed
nemokosch I think that comfortably made it to 6.c 10:33
lizmat yeah, that made it to the Christmas release :-) 10:34
as |foo as syntactic sugar for foo.Slip 10:35
did
nemokosch |foo can also turn positionals into a capture, or something like that 10:36
like foo.Slip would still be passed as one argument
m: my @a = <1 2 3>; say @a.Slip; say |@a; 10:37
Raku eval (1 2 3) 123
nemokosch m: my @nums = 12, 3, 4, 12, 5, 22, 2, -2, 222, 0, 4, 222; say @nums.grep: { /2/ && !%.{$_}++ } 10:38
Raku eval (12 22 2 -2 222)
nemokosch I still wanted to toy around with this 10:39
m: my @nums = 12, 3, 4, 12, 5, 22, 2, -2, 222, 0, 4, 222; say @nums.grep: { next unless /2/; !%.{$_}++ } 10:40
Raku eval (12 22 2 -2 222)
nemokosch using next to skip over entries in mapping is often a good idea 10:41
dakkar: this one is for you 😁
dakkar why? 10:42
nemokosch "any feature you like"
it counts, doesn't it
dakkar aah! thank you ☺ 10:43
nemokosch m: my @nums = 12, 3, 4, 12, 5, 22, 2, -2, 222, 0, 4, 222; say @nums.grep: { next unless /2/; next if %.{$_}++; True } 10:44
Raku eval (12 22 2 -2 222)
nemokosch this is still not such a bad idea if one likes this style 10:45
m: my @nums = 12, 3, 4, 12, 5, 22, 2, -2, 222, 0, 4, 222; say @nums.grep: { next unless /2/; my $appeared-already = %.{$_}; next if $appeared-already; $appeared-already = True; True } 10:47
Raku eval (12 12 22 2 -2 222 222)
nemokosch okay, I didn't intend it to break down just yet...
should have used binding I think 10:48
this happens when you change your mind halfway 10:49
m: my @nums = 12, 3, 4, 12, 5, 22, 2, -2, 222, 0, 4, 222; say @nums.grep: { next unless /2/; my $appeared-already := %.{$_}; next if $appeared-already; $appeared-already = True; True }
Raku eval (12 22 2 -2 222)
nemokosch redemption
_elcaro_ Probably better to check uniqueness first... could save you doing a whole bunch of regex matches.. but then that's just *.unique.grep(/2/) 10:50
nemokosch yeah well it really depends on the cost of each operation, and it's not obvious at least that the uniqueness is cheaper tbh
for readability's and composability's sake, of course the composition of existing operations would be the most idiomatic 10:52
but since we walked down on this path, I wanted to show some things with these list manipulation callbacks and anonymous variables 10:53
m: my @nums = 12, 3, 4, 12, 5, 22, 2, -2, 222, 0, 4, 222; say @nums.grep: { next unless /2/; my $appeared-already := %.{$_}; next if $appeared-already; $appeared-already = True; True } 10:56
Raku eval (12 22 2 -2 222)
nemokosch this is obviously overkill but the important thing is that a hash or a list (or whatever "deep mutable" data structure) can give you something you can directly write, much like a reference 10:57
in this case, it can do that even if the key didn't even exist
it prepared a slot, like "this is where this data should go once it actually exists" 10:58
I borrowed that slot and set it myself, it became stored in the hash
now the final step would be to not borrow the "reference" (scalar container) but instead reuse the same expression 11:00
m: my @nums = 12, 3, 4, 12, 5, 22, 2, -2, 222, 0, 4, 222; say @nums.grep: { next unless /2/; next if %.{$}; %.{$} = True; True } 11:01
Raku eval (12 12 22 2 -2 222 222)
nemokosch and this won't work
because anonymous variables get (re)declared on all occurrence 11:02
meaning that they can only be used sparingly
wafflus m: @n = (0,12,2,2,8,8,10,12,22); say @n.grep: { /^22$/ && !%.{$_}++ } 11:12
camelia ===SORRY!=== Error while compiling <tmp>
Variable '@n' is not declared. Perhaps you forgot a 'sub' if this was
intended to be part of a signature?
at <tmp>:1
------> <BOL>⏏@n = (0,12,2,2,8,8,10,12,22); say @n.gre
wafflus m: my @n = (0,12,2,2,8,8,10,12,22); say @n.grep: { /^22$/ && !%.{$_}++ }
camelia (22)
nemokosch this is some funny logic 11:14
"collect all the unique values that are exactly 22"
lizmat m: say (0,12,2,2,8,8,10,12,22).grep: 22 11:16
camelia (22)
wafflus my orginal question (i think) was to output the value 2 only if it was unique 11:18
using grep 11:19
i know there is a unique which i  think is what i will probally will use but i wanted to see if it could be done using grep
hence the rabbit hole
lizmat m: say (1,2,3,2,3,4,2,3).first: 2
camelia 2
lizmat why not use first instead of grep? 11:20
wafflus ok can u do multiple values? could i extend it to say match 2 and 3? 11:22
lizmat m: say (1,2,3,2,3,4,2,3).first: 2 | 3
camelia 2
lizmat m: say (1,3,2,3,4,2,3).first: 2 | 3
camelia 3
wafflus k thats only outputing the first unique value that matches the pattern not all unique values 11:25
orginally i was trying to learn and understand junction and i was trying to mix them with grep 11:27
lizmat m: say (1,3,2,3,4,2,3).unique 11:28
camelia (1 3 2 4)
lizmat m: say (1,3,2,3,4,2,3).Set
camelia Set(1 2 3 4)
lizmat m: say (1,3,2,3,4,2,3).Bag
camelia Bag(1 2(2) 3(3) 4)
lizmat take your pick :-)
wafflus ok ty
m: say (5,5,5,5,2,2).bag 11:33
camelia No such method 'bag' for invocant of type 'List'. Did you mean 'Bag'?
in block <unit> at <tmp> line 1
wafflus m: say (5,5,5,5,2,2).Bag
camelia Bag(2(2) 5(4))
12:19 teatwo joined 12:22 tea3po left
lizmat rakudoweekly.blog/2023/09/04/2023-...september/ 12:23
oops
And yet another Rakudo Weekly hits the Net ^^ 12:24
wafflus in raku is there a method that  can return the actual string of what inside a function? 12:33
lizmat you mean the code?
wafflus sorry
lizmat no
not at the moment
you *can* find out where the code lives, though 12:34
m: say &infix:<+>.file
camelia SETTING::src/core.c/Numeric.rakumod
lizmat m: say &infix:<+>.line
camelia 209
wafflus ok thanks
lizmat that will usually lead you to the proto
wafflus i was jsut trying to put some blocks of code inside an array and print the string representation and then the result 12:35
lizmat m: for &infix:<+>.candidates { say "$_.file: $_.line" } 12:36
camelia Sub object coerced to string (please use .gist or .raku to do that)
infix:<+>.file: infix:<+>.line
infix:<+>.file: infix:<+>.line
infix:<+>.file: infix:<+>.line
infix:<+>.file: infix:<+>.line
infix:<+>.file: infix:<+>.line
infix:<+>.file: …
wafflus you actually helped me more than need ty
lizmat m: for &infix:<+>.candidates { say "$_.file(): $_.line()" }
camelia SETTING::src/core.c/Numeric.rakumod: 210
SETTING::src/core.c/Numeric.rakumod: 211
SETTING::src/core.c/Real.rakumod: 145
SETTING::src/core.c/Int.rakumod: 312
SETTING::src/core.c/Int.rakumod: 313
SETTING::src/core.c/Int.rakumod: 314
SETTING:…
lizmat yw :-)
wafflus btw when you use pastebin do you set the code to expire? (I always do as it seems polite and might fill the server) 12:42
though i'm sure its never going to do that 12:43
12:44 NemokoschKiwi joined 12:46 NemokoschKiwi left 12:50 samebchase joined
samebchase What's the idiomatic way to drop n elements in a list. I know List.head can be used to get the first N elements, what's the best way to drop the first N elements? 12:52
lizmat m: my @a = ^10; say @a.skip(5) 12:56
camelia (5 6 7 8 9)
samebchase Thanks lizmat! 12:57
I have a feeling I've asked this exact same question a few years ago. 😬
lizmat maybe .skip didn't exist yet then
samebchase docs.raku.org/type/List I was looking here and wondering if there's a built-in 12:59
lizmat m: use v6.e.PREVIEW: my @a = ^20; say @a.skip(5,3,6)
camelia ===SORRY!=== Error while compiling <tmp>
Bogus statement
at <tmp>:1
------> use v6.e.PREVIEW:⏏ my @a = ^20; say @a.skip(5,3,6)
expecting any of:
colon pair
lizmat m: use v6.e.PREVIEW; my @a = ^20; say @a.skip(5,3,6)
camelia (0 1 2 3 4 8 9 10 11 12 13)
lizmat samebchase: maybe make a doc issue about that
samebchase yup 13:00
wafflus pastebin.com/VhJFeWr1 anyone know why the 3rd example outputs brackets and if it's possible to do do multiple comparisons using < etc and get the correct result? 13:04
nemokosch it's always suspicious that if something like this is missing, it's not actually a method of List
and this seems to be the case here as well
this complicates the documentation quite often
docs.raku.org/type/Any#routine_skip
dakkar wafflus: I feel you're using `|` where `||` would make more sense to me 13:05
wafflus ok i will try
dakkar (`|` is the infix version of the `any` junction constructor, `||` is the boolean "or" operator) 13:06
nemokosch and you often use two asterisks
there are like three layers of traps here
dakkar oh yes, that too
nemokosch 1. | is for junctions 2. || is a "thunky" operator that perhaps doesn't even whatever-curry 3. two asterisks mean two different parameters 13:07
the failsafe way is to just use a {} block and $_ as the parameter in it
wafflus maybe the 2nd * is like map and goes to the 2nd value in grep?
nemokosch for what code? 13:08
wafflus :m say (2, 4, 2, 5, 10, 12).grep((* > 5)||(* <5))
m: (2, 4, 2, 5, 10, 12).grep((* > 5)||(* <5)) 13:09
camelia ( no output )
wafflus m: say (2, 4, 2, 5, 10, 12).grep((* > 5)||(* <5))
camelia (10 12)
nemokosch (* > 5)||(* <5) evaluates to the first function
so it's the same for your purposes as just * > 5 13:10
wafflus m: say {(2, 4, 2, 5, 10, 12).grep({$_ > 5|| ^5})} 13:12
camelia -> ;; $_? is raw = OUTER::<$_> { #`(Block|4297854902856) ... }
wafflus k that was diffrent then the prel 13:13
repl
nemokosch m: say (2, 4, 2, 5, 10, 12).grep({$_ > 5|| ^5})
Raku eval (2 4 2 5 10 12)
nemokosch what are you trying to achieve, though
antononcube Out-hallucinating a certain LLM? 13:15
wafflus m: say (2, 4, 2, 5, 10, 12).grep((^5) | (6 .. 12))
camelia (2 4 2 10 12)
nemokosch In Raku, it's relatively painless to decide what you want to solve and write some code for it 13:16
but it's really painful to write some random code and figure out what you expect it to do...
antononcube Hmm… no, that is Mathematica !!!
wafflus m: say (2, 4, 2, 5, 10, 12).grep((^5) | (6 .. *)) 13:17
camelia (2 4 2 10 12)
nemokosch the DIHWIDT principle is basically a nod to this phenomenon
wafflus something like that but i was trying to do it with < and > operators
nemokosch "doctor, it hurts when i do this - then don't"
wafflus i could only manged to do it with 1
antononcube Sorry, I reacted too quickly — should have waited to read/see that.
Back to LLM-land… 13:18
wafflus i thought i could do two comparisons so far all have met with failure
in one line
nemokosch wafflus: isn't this more or less "all (positive) values but 5"?
non-negative*
anyway, what about something like 13:19
wafflus yes but i guess its more if i can do i that way
i know i could do a not 5
nemokosch m: say (2, 4, 2, 5, 10, 12).grep({ 3 < $_ < 6 || 7 < $_ < 11 }) 13:20
Raku eval (4 5 10)
wafflus cool
m: say (1...14).grep({$_ <5 || 5 < $_ <= 12 }) 13:27
camelia (1 2 3 4 6 7 8 9 10 11 12)
nemokosch yep, legit 13:32
wafflus is that ↑ the equivalent to 13:33
m: say (1...14).grep({$_ <5 || ($_ <= 12) && $_ >5 }) 13:34
camelia (1 2 3 4 6 7 8 9 10 11 12)
antononcube This is a very quotable statement in the context of working with LLMs to generate Raku code. 13:35
nemokosch what are you gonna do with it? 13:36
antononcube Hmm… put in a blog post, or two, or five. (With attribution.) 13:38
wafflus my statements?
antononcube @nemokosch Or, if you prefer without attribution. (“A certain Raku enthusiast stated once that…”) 13:39
nemokosch lol 13:42
yeah don't forget that replies don't carry through the IRC bridge 13:43
antononcube Good to know!
wafflus was scared that someone was going to do a blog about his statments (look at this idiot wafflus) 13:44
nemokosch 🤣 13:47
antononcube @wafflus No — quotes from your posts here will be introduced with: “A certain Raku adopter-wannabe (trying to do it at home, alone) asked once…” 13:49
wafflus k i mean you can use my irc nick it's not my real name 13:50
as long as your polite :)
you are 13:51
one of those lol 13:52
antononcube @wafflus You are getting the wrong message it seems. Let me clarify and quantify: > In order to be considered a Raku enthusiast, you have to have at least 1/40th of Nemokosch’s number of posted notes. 13:53
wafflus roughly 2 million posts ok got it
antononcube Yeah, not a trivial number. 🙂
wafflus i had already gussed you ment nemo earlier :D
anyways nice talking to you all thanks for your help 13:54
13:54 wafflus left
nemokosch you are welcome 13:55
antononcube Good. But now I am thinking that Raku community should have a Nemokosch unit.
nemokosch XDD
is that like Erdős number?
antononcube Ha!! Good question! What I have in mind is much less structure-based — it is more of a normalization procedure based unit. 13:56
Although, we can make a graph of how people “connect” to Nemokosch, with different types of edges (guess the types!) and then apply Erdos’ number. 13:58
This reminds me — I plan to implement a “Graph” package for Raku. Hopefully, before TRC-2023. 14:00
14:48 tea3po joined 14:51 teatwo left 16:39 dakkar left 17:41 teatwo joined 17:43 teatime joined 17:44 tea3po left 17:45 teatwo left 19:21 teatwo joined 19:24 teatime left 20:09 habere-et-disper joined
habere-et-disper Is rakudo star supposed to include rakudoc (or p6doc) ? 20:09
20:11 KOTP_ joined 20:12 deadmarshal_ left, KOTP left, KOTP_ is now known as KOTP 20:13 KOTP left, KOTP joined 20:19 teatwo left, teatwo joined 20:21 deadmarshal_ joined 20:22 teatwo left, teatwo joined 20:25 teatwo left, teatwo joined 20:47 ab5tract left
nemokosch well, who are you asking? 21:17
habere-et-disper Hi nemokosch ! o/ 21:25
My question isn't directed -- all input welcomed !
21:47 sivoais left 21:49 sivoais joined
nemokosch I was just wondering if you are curious about an opinion, or found something that is supposedly present but apparently not, you know, this sort of stuff 21:51
the "hidden meaning"
my personal opinion is that it would be nice to include it, but then it should be probably included along the whole doc repository or something, or at least this should be the mid-term goal 21:52
habere-et-disper Right. So I use the most excellent web docs, but I tried once to use offline in the terminal but neither `rakudoc` nor `p6doc` seems available. Is that my install or just the current state of affairs ? 21:54
nemokosch I don't know much about Rakudo Star, to be honest, and never used these doc tools 21:58
rakudoc is working and installable, from what I know, but I don't know how it can be used with the Raku docs themselves 21:59
lately there have been discussions that it should somehow preinstall the docs, from which we can conclude that it hasn't been the case 22:00
habere-et-disper (y) 22:06
How do we do optional chaining again ? In JavaScript it's with `?.` and I thought we could do something similar. I'm using `//` instead. 23:53
nemokosch well technically, andthen does that 23:54
23:58 Util left, Util joined