🦋 Welcome to the MAIN() IRC channel of the Raku Programming Language (raku.org). This channel is logged for the purpose of keeping a history about its development | evalbot usage: 'm: say 3;' or /msg camelia m: ... | Log available at irclogs.raku.org/raku/live.html . If you're a beginner, you can also check out the #raku-beginner channel!
Set by lizmat on 8 June 2022.
guifa You know what would actually make slangs much easier to write? 04:37
private tokens
oh wait, private methods compose (I feel like they shouldn't?) 04:39
I can my scope it, but stubbing doesn't really work with tokens 05:01
moritz private methods (in roles, I assume) must compose; you never call anything on a role, but on a role applied to a class. If they didn't compose, you'd never be able to call them 07:01
guifa_ moritz yeah, that makes sense. I'm just annoyed at having to namespace my tokens in slangs, that's all :-) 11:54
SmokeMachine lizmat: yes, vim accepts `-q`... github.com/lizmat/Edit-Files/pull/1 15:36
lizmat s/vim/nvim/ I assume :-) 15:38
SmokeMachine yes :)
oliphant Hello whats an assertion way in Raku? like the assert or static_assert in some other languagse 16:05
Nemokosch are you writing test cases? 16:12
oliphant no writing a code where some place asserted to be unreachable 16:13
or some mathematical logic satisfied 16:14
moritz die "this should never be reached because of $reason" 16:19
there's actually a built-in always-fail assertion, prefix:<!!!!>
m: !!! "foo"
camelia foo
in block <unit> at <tmp> line 1
oliphant So did it fail? 16:21
moritz yes
m: !!! "foo"; say "never reached"
camelia foo
in block <unit> at <tmp> line 1
oliphant oh 16:22
moritz to answer the original question, raku has a lot of constructs that assertions are often used for
moritz these include: subtypes with code checks, PRE and POST conditions for routines, and code checks in signatures 16:22
m: subset Positive of Int where { $_ > 0 }; my Positive $x = 42; say "alive"; $x = -4; say "no more alive" 16:23
camelia alive
Type check failed in assignment to $x; expected Positive but got Int (-4)
in block <unit> at <tmp> line 1
moritz m: sub factors(Int $x where !.is-prime) { 42 }; factors(13)
camelia Constraint type check failed in binding to parameter '$x'; expected anonymous constraint to be met but got Int (13)
in sub factors at <tmp> line 1
in block <unit> at <tmp> line 1
moritz m: sub increment(Numeric $x) { POST $_ > $x; return $x +1 }; increment 4 16:24
camelia ( no output )
moritz m: sub increment(Numeric $x) { POST $_ > $x; return $x - 1 }; increment 4
camelia Postcondition '$_ > $x' failed
in sub increment at <tmp> line 1
in block <unit> at <tmp> line 1
moritz that said, I don't think there's an explicit assert 16:25
lizmat m: sub assert($condition, $message) { die $message unless $condition }; assert 42 < 666, 'foo'; assert 42 > 666, 'bar' 16:27
camelia bar
in sub assert at <tmp> line 1
in block <unit> at <tmp> line 1
lizmat oliphant: ^^ something like that ? 16:27
moritz it's easy to make one as lizmat demonstrated, though it does evaluate the message even if the condition is true
once RakuAST lands, it'll probably be easy to make a higher-quality one 16:28
oliphant wow POST
Whats $_ in POSt being?
Im familiar with $_
Asking its topic there
lizmat m: { POST say "POST: $_"; 42 } 16:29
camelia WARNINGS for <tmp>:
POST: 42
Useless use of constant integer 42 in sink context (line 1)
moritz oliphant: the return value of the routine
lizmat m: my $b := { POST say "POST: $_"; 42 }; $b()
camelia POST: 42
lizmat m: sub foo() { POST say "POST: $_"; 42 }; foo
camelia POST: 42
oliphant thank you Raku persons 16:30
My other query is difference of fail and die
lizmat you're welcome :-)
oliphant Above used die for example
But why not fail? 16:31
Its not cathchable?
(the die)
moritz fail is a bit softer than die 16:32
oliphant When should i fail insteed
moritz fail returns an exception wrapped in a timebomb, that explodes if you use it like a regular value, but if you check it for .defined first, it's good
lizmat m: sub foo() { fail "bar" }; my $a = foo; say "still alive"; my $b = $a
camelia still alive
lizmat m: sub foo() { fail "bar" }; my $a = foo; say "still alive"; my $b = $a + 2 16:33
camelia still alive
bar
in sub foo at <tmp> line 1
in block <unit> at <tmp> line 1
moritz this enables routines that both throw an exception if nobody checks it, but doesn't need exceptions if the user prefers it that way. More magical, supposedly better for highly parallel computations
it's a bit too magical for my tastes, so I go straight for die(), usually. 16:34
YMMV
oliphant oo timebomb 😂 i understand the diff 16:35
i need to see more code of people where to use where not i say 16:36
thanking again
moritz my pleasure 16:38
Nemokosch what is needed for a new version of a module to be published? 18:10
I mean, my PR to Terminal::Getpass got merged - is something additional needed so that the new version gets available?
moritz the maintainer needs to make a release and upload it to whatever ecosystem is used 18:14
Nemokosch 👍 18:15
Xliff \o 18:53
m: sub a (*@a) { @a.say }; my &b = &a.assuming(1, 2); &b.is-wrapped.say;
camelia False
Xliff m: sub a (*@a) { @a.say }; my &b = &a.assuming(1, 2); &b.is-wrapped.say; &b;
camelia WARNINGS for <tmp>:
False
Useless use of &b in sink context (line 1)
Xliff m: sub a (*@a) { @a.say }; my &b = &a.assuming(1, 2); &b.is-wrapped.say; &b.say;
camelia False
&__PRIMED_ANON
Xliff m: sub a (*@a) { @a.say }; my &b = &a.assuming(1, 2); &b.is-wrapped.say; &b().say; 18:54
camelia False
[1 2]
True
Xliff m: sub a (*@a) { @a.say }; my &b = &a.assuming(1, 2); &b.is-wrapped.say; &b();
camelia False
[1 2]
Xliff m: sub a (*@a) { @a.say }; my &b = &a.assuming(1, 2); &b.is-wrapped.say; &b(); &b.name.say
camelia False
[1 2]
__PRIMED_ANON
Xliff OK, If I have &b as above, is there any way to get back the reference to the original callable? 18:55
melezhik o/ 21:04
What's up
Nemokosch hello 21:10
as time passes, the more urgent it seems for me to document returned containers better
Nemokosch let me illustrate 21:10
Nemokosch m: my @flat-array = <the name is bond bon bond>; @flat-array.batch(2)[1;1] = 'short'; dd @flat-array; 21:11
camelia Array @flat-array = ["the", "name", "is", "short", "bon", "bond"]
Nemokosch this is unbelievably cool - but how should one expect it? 21:12
habere-et-disper How do you take the odd or even elements of a list? 21:20
m: say (10,11,12,13,14,15,16,17,18,19,20).grep( *.keys %% 2 )
camelia ()
lizmat m: say (10,11,12,13,14,15,16,17,18,19,20).grep({ $++ %% 2 }) 21:22
camelia (10 12 14 16 18 20)
lizmat m: say (10,11,12,13,14,15,16,17,18,19,20).grep({ ++$ %% 2 })
camelia (11 13 15 17 19)
p6steve m: say (10,11,12,13,14,15,16,17,18,19,20).grep( {$_ %% 2} )
Nemokosch oh for some reason I thought indices
liz also thought indices, it's fine then 😄
lizmat
.oO( the magic of the nameless state variable
)
Nemokosch the nameless state variable bit me this week 21:23
lizmat habere-et-disper: I interpreted it as odd or even *elements*, not the values
Nemokosch don't use it with recursive functions...
lizmat yeah
true
m: say (10,11,12,13,14,15,16,17,18,19,20).grep(:2nd) # wonder if that would make sense 21:24
camelia Cannot resolve caller grep(List:D: :nd(Int)); none of these signatures matches:
($: Bool:D $t, *%_)
($: Mu $t, *%_)
in block <unit> at <tmp> line 1
Nemokosch categorize can also work, to get both 21:25
Nemokosch (10..20).categorize({ $++ % 2 }) 21:26
oops
m: dd (10..20).categorize({ $++ % 2 })
camelia (my Any %{Mu} = 0 => $[10, 12, 14, 16, 18, 20], 1 => $[11, 13, 15, 17, 19])
p6steve (10..20).classify({$_ %% 2}) 21:27
{False => [11 13 15 17 19], True => [10 12 14 16 18 20]}
habere-et-disper lizmat Thank you -- I did want the indices! :)
Nemokosch right, categorize is the one that can overlap, classify is the one that cannot 21:28
p6steve (10..20).keys.classify({$_ %% 2}) 21:29
{False => [1 3 5 7 9], True => [0 2 4 6 8 10]}
Nemokosch of course rotor can also be useful to a certain degree 21:30
p6steve (10..20).keys.categorize(* %% 2)
Nemokosch m: dd (10..20).rotor(1 => 1) 21:31
camelia ((10,), (12,), (14,), (16,), (18,), (20,)).Seq
p6steve {False => [1 3 5 7 9], True => [0 2 4 6 8 10]}
Nemokosch rotor emits one-element lists though
lizmat and nowadays, there's also snip! 21:32
Nemokosch what is that?
lizmat m: dd (^10).snip( * < 5 )
camelia No such method 'snip' for invocant of type 'Range'. Did you mean any
of these: 'Slip', 'skip', 'flip', 'sin'?
in block <unit> at <tmp> line 1
p6steve huh?
lizmat meh
m: dd (0,1,2,3,4,5,6,7,8,9).snip( * < 5 ) 21:33
camelia No such method 'snip' for invocant of type 'List'. Did you mean any of
these: 'Slip', 'skip', 'flip', 'sin'?
in block <unit> at <tmp> line 1
lizmat hmmm
Nemokosch what version?
I also don't have it with 2022.04
lizmat m: dd Compiler.new.version 21:34
camelia v2022.06.55.g.7.ec.4.b.10.d.7
SmokeMachine m: my &incr := * + 1; 41 ==> incr() ==> say() #`(this works...); [==>] 41, incr(), say() # should this work?
camelia Potential difficulties:
Useless use of [==>] in sink context
at <tmp>:1
------> ==> incr() ==> say() #`(this works...); ⏏[==>] 41, incr(), say() # should this wo
42
Cannot resolve caller METAOP_REDUCE_LIST(VMNull); none
SmokeMachine m: my &incr := * + 1; 41 ==> incr() ==> say() # this works...
camelia 42
lizmat aah...
SmokeMachine m: my &incr := * + 1; [==>] 41, incr(), say() # should this work?
camelia Potential difficulties:
Useless use of [==>] in sink context
at <tmp>:1
------> my &incr := * + 1; ⏏[==>] 41, incr(), say() # should this wo
Cannot resolve caller METAOP_REDUCE_LIST(VMNull); none of these signatures match…
lizmat m: use v6.e; dd (^10).snip( * < 5 )
camelia ===SORRY!=== Error while compiling <tmp>
Raku v6.e requires PREVIEW modifier
at <tmp>:1
------> use v6.e⏏; dd (^10).snip( * < 5 )
lizmat m: use v6.*; dd (^10).snip( * < 5 )
camelia ((0, 1, 2, 3, 4), (5, 6, 7, 8, 9)).Seq
lizmat *phew* only on 6.e :-) 21:35
p6steve oh there was a recent SO on that - cool
stackoverflow.com/questions/728094...n-function 21:37
is snip === nsap
/snip/span/
btw why not call it span?
habere-et-disper .grep(:2nd)  is rather css like 21:38
lizmat m: use v6.*; dd (^20).snip( * < 5, * < 10 ) # p6steve: can have more than one condition, and span cannot
camelia ((0, 1, 2, 3, 4), (5, 6, 7, 8, 9), (10, 11, 12, 13, 14, 15, 16, 17, 18, 19)).Seq
Nemokosch also, any idea how to be more explicit about the containers? Namely that functions usually treat their arguments as raw 21:39
lizmat afk& 21:41
Nemokosch actually this also means that some things _only work_ with @, which is a whole new perspective for me
p6steve lizmat: tx! 21:43
habere-et-disper Is there a list of deprecations? I want to ask the REPL if possible. 21:44
Nemokosch the REPL about deprecations? 21:45
gfldex habere-et-disper: There is no complete list but since they are introduced by a trait, you could wire Rakudo up to show them all. 21:47
habere-et-disper gfldex Thank you. I don't know how to do this but will investigate. 21:56
SmokeMachine m: use v6.*; dd (^20).snip( |^Inf .map: { { $^a * 5 > $^B } } ) 22:03
camelia ===SORRY!=== Error while compiling <tmp>
Unsupported use of $^B variable
at <tmp>:1
------> ^20).snip( |^Inf .map: { { $^a * 5 > $^B⏏ } } )
SmokeMachine m: use v6.*; dd (^20).snip( |^Inf .map: { { $^a * 5 > $^b } } ) 22:06
camelia Too few positionals passed; expected 2 arguments but got 0
in block at <tmp> line 1
in block <unit> at <tmp> line 1
SmokeMachine m: use v6.*; dd (^20).snip( |^Inf .map: { * * 5 > * } ) 22:07
camelia ===SORRY!=== Error while compiling <tmp>
Malformed double closure; WhateverCode is already a closure without curlies, so either remove the curlies or use valid parameter syntax instead of *
at <tmp>:1
------> dd (^20).snip( |^Inf .map: {…
SmokeMachine m: use v6.*; dd (^20).snip( |^Inf .map: { (* * 5 > *) } )
camelia MoarVM panic: Memory allocation failed; could not allocate 67462656 bytes
lizmat SmokeMachine:hmmm.. interesting.. :-) 23:02
care to make an issue for that ?
El_Che hi lizmat 23:05
lizmat El_Che: hi, but going afk for the night & 23:07
El_Che :) 23:13