🦋 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: ... | Logs can be inspected at colabti.org/irclogger/irclogger_log/raku
Set by lizmat on 1 May 2021.
kybr m: class Foo { proto foo($this, :$that) { } ; method bar { &foo.signature } } ; Foo.new.bar.say 02:03
camelia ($this, :$that)
kybr m: class Foo { proto foo($this, :$that) { } ; method bar { &foo.signature } } ; Foo.bar.say 02:04
camelia ($this, :$that)
kybr m: class Foo { method foo($this, :$that) { } ; method bar { &foo.signature } } ; Foo.bar.say 03:13
camelia 5===SORRY!5=== Error while compiling <tmp>
Undeclared routine:
foo used at line 1
PimDaniel Hi! 11:44
\o
What is or vs || or | ?
m: say False | True; 11:45
camelia any(False, True)
PimDaniel m: say False || True;
camelia True
PimDaniel m: say False or True;
camelia WARNINGS for <tmp>:
False
Useless use of constant integer True in sink context (line 1)
PimDaniel I do not understand any more. 11:46
parv m: say ( False || True ) ; ( say False ) || True ; say ( False or True ) 11:51
camelia WARNINGS for <tmp>:
True
False
True
Useless use of constant integer True in sink context (line 1)
parv m: x = say False ; x.WHAT 11:54
camelia 5===SORRY!5=== Error while compiling <tmp>
Preceding context expects a term, but found infix = instead.
Did you make a mistake in Pod syntax?
at <tmp>:1
------> 3x =7⏏5 say False ; x.WHAT
parv m: $x = say False ; x.WHAT
camelia 5===SORRY!5=== Error while compiling <tmp>
Variable '$x' is not declared
at <tmp>:1
------> 3<BOL>7⏏5$x = say False ; x.WHAT
parv m: $x = say False ; $x.WHAT
camelia 5===SORRY!5=== Error while compiling <tmp>
Variable '$x' is not declared
at <tmp>:1
------> 3<BOL>7⏏5$x = say False ; $x.WHAT
parv m: my $x = say False ; $x.WHAT
camelia False
parv m: my $x = say False ; say $x
camelia False
True
parv m: my $x = say False ; say $x.WHAT 11:55
camelia False
(Bool)
parv m: my $x; my $y = False; say $y == False | True 11:56
camelia any(True, False)
parv m: my $x; my $y = False; say $y == (False | True) 11:57
camelia any(True, False)
parv m: my $x; my $y = False; $x = $y == (False | True)
camelia ( no output )
parv m: my $x; my $y = False; $x = $y == (False | True) ; say $x
camelia any(True, False)
PimDaniel parv thank you to give a try for me: I think the documentation is for me umbiguous because i do not well understand english language. According to docs.raku.org/routine/or or should behave almost like || but i struggle to understand terms :"looser precedence" and "it short-circuit". 11:59
parv PimDaniel, regarding short circuit: in case of ||, if the first condition is true, then second is not evaluated. In case of &&, if the first condition is false, second condition will not be evaluated. 12:02
PimDaniel What i need to achieve is simple : i get 2 expressions that when avaluated are each True or False if only one is True i need to return True so i made : return <expr1> || <expr2> and it works as expected but not <expr1> or <expr2>. 12:04
parv PimDaniel, on precedence: docs.raku.org/language/operators#O...precedence 12:05
PimDaniel parv Yess what mease looser precedence? This is actually what i do not understand. 12:06
*means
frost-lab m: say (True || False); say True or False; 12:10
camelia WARNINGS for <tmp>:
True
True
Useless use of constant integer False in sink context (line 1)
frost-lab m: say (False || False); say False or False; 12:11
camelia WARNINGS for <tmp>:
False
False
Useless use of constant integer False in sink context (line 1)
parv m: 5 12:12
camelia WARNINGS for <tmp>:
Useless use of constant integer 5 in sink context (line 1)
ggoebel PimDaniel: looser precedence is the same thing as multiplication coming before addition 12:13
frost-lab m: (say False) or False 12:14
camelia WARNINGS for <tmp>:
False
Useless use of constant integer False in sink context (line 1)
frost-lab say (False or False) 12:15
evalable6 False
frost-lab m: say ((say False) or False) 12:16
camelia False
True
PimDaniel ggoebel ok i see. 12:17
parv why is return value of say is True but not integer? 12:18
PimDaniel parv you do you mean || converts to Integer and brings to a different result? 12:19
ggoebel so addition is looser than multiplication
parv PimDaniel, No. My question is why "$x" in "my $x = say ..." has the value of "True"? 12:21
PimDaniel parv : Sorry: I do not know what code or example you refer to. 12:22
thundergnat say() returns whether it succeeds (True) or fails (Failure)
frost-lab the definition of say is 'multi method say(IO::Handle:D: **@text --> True)' 12:23
thundergnat As long as you are say()ing to $*STDOUT, it almost can't help but succeed, so always returns True.
parv Ah. Thank you, thundergnat & frost-lab. 12:24
PimDaniel okay i think i can see: this is an important point too.
Thank you to all of you. I'll be back later. Good afternoon! 12:25
thundergnat say 0 and say 'loose precedence'; # and is looser (lower precedence) than say 12:26
m: say 0 and say 'loose precedence'; # and is looser (lower precedence) than say
camelia 0
loose precedence
thundergnat m: say 0 && say 'tight precedence';  # && is tighter (higher precedence) than say 12:27
camelia 0
PimDaniel \) 13:48
\O
Hi.
How to check if an instance is created? or NOT? 13:49
A Class instance, i mean.
Created or container attached to a new Class. 13:50
Has an example class A{ has A $!next; } but further in the code $!next is supposed to be assigned to the next A object, but not allways assigned in some circumstances. how to i check if it is not, thank you. 13:53
*As an example
tadzik you can check if it's `defined $!next`, maybe 13:57
PimDaniel Ok i try that... 13:59
tadzik : ok it works, i forgetted .defined; Lack of memory, i mean into my head. 14:03
tadzik: thank you!
tadzik :) 14:04
you're welcome
PimDaniel back later.
whatnext hello all:)  - can anyone help me out with a really basic question? Posted here: perlmonks.org/?node_id=11132158 14:38
El_Che whatnext: it expects an array 14:41
tonyo whatnext: you're right it expects only self.
m: class A { has @.scales is rw; }; my $a = A.new; $a.scales = qw<green blue yello>; $a.scales.say;
camelia [green blue yello]
tonyo use that for assignment ^
even if you call .scales([1,2,3]) you'll get that error except it'll say `but got 2` rather than `but got 4` 14:43
lizmat weekly: perlmonks.org/?node_id=11132158 14:44
notable6 lizmat, Noted! (weekly)
whatnext tonyo - ah thanks! I was being a dimwit. Pythonic style accessors - that didn't occur to me:/ 14:47
oddp Oi! Say i have an array via: `my @arr = [False xx 5] xx 5`. Any idea how i could toggle a rect slice? Tried `@arr[2..4, 2..4] xor= True`, but that doesn't work 15:12
oddp Setting it to either True, for example, via `@arr[2..4, 2..4] = True xx *` works, but i'm looking for a way to toggle them since i have many overlapping rects 15:15
to True*
No other elegant way than the good-old nested looping? 15:16
Altreus m: my @arr = [False xx 5] xx 5; $_ xor= True for @arr[2..4, 2..4]; say @arr
camelia Cannot assign to an immutable value
in block <unit> at <tmp> line 1
Altreus o
I feel like the principal difference is that your xor= attempt doesn't apply a True to each member but to the slice itself 15:17
but i don't know how to spell that in Raku
tonyo i don't think @arr[2..4, 2..4] = True xx * works, it seems like that just confirms it's applying your rhs to the slice itself.. 15:19
oddp `xor=` seems to be problematic, getting `(Any)` values. But this not so sexy approach seems to be good enough for now: `for @arr[2..4; 2..4] <-> $v { $v = !$v }` 15:26
Thanks for your input!
Altreus ah forgot about <-> 15:28
metacookie are captures immutable? i wish to build one incrementally. 17:04
and call a function using that capture. or, can i make a capture from a hash? 17:06
lizmat m: my $c = Capture.new(list => (42,666)); sub a(|c) { dd c }; a |$c 17:11
camelia \(42, 666)
lizmat metacookie ^^
something like that ?
lizmat m: my $c = Capture.new(list => (42,666), hash => { a => "foo", b => "bar" }); sub a(|c) { dd c }; a |$c # also with nameds 17:12
camelia \(42, 666, :a("foo"), :b("bar"))
metacookie yay! thank you 17:13
thundergnat m: my @arr = [False xx 5] xx 5; @arr[2..4; 2..4] »xor=» True; say @arr 17:29
camelia [[False False False False False] [False False False False False] [False False True True True] [False False True True True] [False False True True True]]
thundergnat oddp ^^^ 17:30
oddp damn, looking slick, thundergnat! 17:31
thundergnat Hmm. That may not actually do what you want. It seems to ignore the xor part. 17:33
oddp Yeah, and >>=>> True/False doesn't seem to be working either for when i want to set a rect. Might have to look that up in the docs 17:34
Xliff I see true values. xor= has to be working. Right? 17:35
m: my @arr = [False xx 5] xx 5; @arr[2..4; 2..4] «xor=« True; say @arr 17:36
camelia Lists on either side of non-dwimmy hyperop of infix:<xor> + {assigning} are not of the same length while recursing
left: 9 elements, right: 1 elements
in block <unit> at <tmp> line 1
tonyo m: my @arr = [True xx 5] xx 5; @arr[2..4; 2..4] »xor=» True; say @arr
camelia [[True True True True True] [True True True True True] [True True (Any) (Any) (Any)] [True True (Any) (Any) (Any)] [True True (Any) (Any) (Any)]]
oddp Yeah, that's the problematic part i talked about above
Xliff m: my @arr = [False xx 5] xx 5; @arr[2..4; 2..4] »xor=» True; say @arr
camelia [[False False False False False] [False False False False False] [False False True True True] [False False True True True] [False False True True True]]
oddp that's why i went with $v = !$v
thundergnat I was just going to type that exact line...
oddp m: my @arr = [False xx 5] xx 5; @arr[2..4; 2..4] »^^=» True; say @arr 17:37
camelia [[False False False False False] [False False False False False] [False False True True True] [False False True True True] [False False True True True]]
oddp m: my @arr = [True xx 5] xx 5; @arr[2..4; 2..4] »^^=» True; say @arr
camelia [[True True True True True] [True True True True True] [True True (Any) (Any) (Any)] [True True (Any) (Any) (Any)] [True True (Any) (Any) (Any)]]
tonyo m: my @arr = [True xx 5] xx 5; @arr[2..4; 2..4] »=» (* xor True).so; say @arr 17:39
camelia [[True True True True True] [True True True True True] [True True False False False] [True True False False False] [True True False False False]]
tonyo m: my @arr = [False xx 5] xx 5; @arr[2..4; 2..4] »=» (* xor True).so; say @arr 17:40
camelia [[False False False False False] [False False False False False] [False False False False False] [False False False False False] [False False False False False]]
tonyo hm 17:41
Altreus badger badger badger badger 17:47
thundergnat Interestingly it seems to work correctly for bitwise xor 17:51
m: my @arr = [0 xx 5] xx 5; @arr[2..4; 2..4] »+^=» 1; say @arr; @arr[2..4; 1..3] »+^=» 1; say @arr;
camelia [[0 0 0 0 0] [0 0 0 0 0] [0 0 1 1 1] [0 0 1 1 1] [0 0 1 1 1]]
[[0 0 0 0 0] [0 0 0 0 0] [0 1 0 0 1] [0 1 0 0 1] [0 1 0 0 1]]
lizmat
.oO( snake! )
oddp Interesting! Even `@arr[2..4; 2..4] »=» 1` in that case 17:56
strange that >>=>> 1 is exploding
m: my @arr = [0 xx 5] xx 5; @arr[2..4; 2..4] »=» 1; say @arr;
camelia [[0 0 0 0 0] [0 0 0 0 0] [0 0 1 1 1] [0 0 1 1 1] [0 0 1 1 1]]
oddp m: my @arr = [0 xx 5] xx 5; @arr[2..4; 2..4] >>=>> 1; say @arr;
camelia 5===SORRY!5=== Error while compiling <tmp>
Missing << or >>
at <tmp>:1
------> 3r = [0 xx 5] xx 5; @arr[2..4; 2..4] >>=>7⏏5> 1; say @arr;
expecting any of:
infix
infix stopper
lizmat m: my @arr = [0 xx 5] xx 5; @arr[2..4; 2..4] >> = >> 1; say @arr; 17:57
camelia 5===SORRY!5=== Error while compiling <tmp>
Unsupported use of >> to do right shift. In Raku please use: +> or ~>.
at <tmp>:1
------> 3arr = [0 xx 5] xx 5; @arr[2..4; 2..4] >>7⏏5 = >> 1; say @arr;
lizmat m: my @arr = [0 xx 5] xx 5; @arr[2..4; 2..4] >>=>> 1; say @arr;
camelia 5===SORRY!5=== Error while compiling <tmp>
Missing << or >>
at <tmp>:1
------> 3r = [0 xx 5] xx 5; @arr[2..4; 2..4] >>=>7⏏5> 1; say @arr;
expecting any of:
infix
infix stopper
lizmat yeah, I guess that's a parsing ambiguity with => being interpreted as a Pair constructor
unicode ops FTW 17:58
oddp jesus, just figured out why the rest of program wasn't working; today is full of surprises ;) 17:59
m: say ['12'..'24']
camelia [12 13 14 22 23 24]
oddp not what i expected
but a .map(*.Int) finally fixes the whole thing 18:00
lizmat don't use quotes then :-)
oddp range is coming straight out of $line.comb(
range is coming straight out of $line.comb(/\d+/)
lizmat perhaps make a sub that intifies the endpoints? 18:01
that would make it much more efficient
oddp went with: my ($x1, $y1, $x2, $y2) = $line.comb(/\d+/).map(*.Int);
lizmat ah, yes, that works :-) 18:01
as long as you don't do the .map(*.Int) on the Range with Str endpoints 18:02
ah, and that wouldn't do what you want anyways...
duh
tonyo m: say [12..24] 18:06
camelia [12 13 14 15 16 17 18 19 20 21 22 23 24]
gfldex m: my (Int() $i, Int() $j) = '22', '33'; .WHAT.say for $i, $j; 19:13
camelia (Int)
(Int)
oddp is qqx{raku script.raku}.chomp the most canonical way to use the result of another raku script? 20:53
moon-child EVAL slurp 'script.raku'! 21:00
ugexe docs.raku.org/routine/EVALFILE 21:03
oddp slick, even better than EVAL; thanks both of you! 21:04
ugexe depends though if you want it to be isolated to its own process or not though
i.e. using EVAL could change the state of the program running it, whereas e.g. `say run($*EXECUTABLE, $filename, :out).out.slurp(:close)` will be isolated to its own process 21:05
oddp nah, all good, not doing anything serious. just some advent of code, where part2 depends on the answer from part1
ah, i see what you mean. EVALFILE gives me ambiguous call errors when i have the same subs in part1 and part2. Sticking to qqx then. 21:14