This channel is intended for people just starting with the Raku Programming Language ( Logs are available at
Set by lizmat on 8 June 2022.
00:40 archenoth left 01:57 frost joined 03:40 Heptite left 08:00 dakkar joined 08:40 archenoth joined 08:59 frost left
jaguart ll 10:00
10:57 frost joined
stevied is there any good reason I can do `$str.chop(1)` but not `$str.trans('a' => 'b')` 12:50
the former changes the string in place, the latter does not. Trying to figure out what the reason for the inconsistency is so I can remember it
Kaiepi that's surprising 12:52
my $s = "chopped\n";
$s.chop: 1;
print $s
yabobay i don't remember which language this was, but there is one language where str.method() doesn't modify the string in place, but str.!method() does (...or something like that, where you put some punctuation somewhere in the method name) 12:54
stevied i think ruby does that
yabobay yea probably that 12:55
Kaiepi this could be a break
yabobay i wonder how it's done in ruby. do they just have multiple functions, or maybe it's just syntactic sugar for just assigning to the same variable 12:56
Kaiepi no bisectable in here, but there is in #raku
stevied oh, wait, my bad. $name.chop(1) does not modify $name 13:00
I was reading the code I had wrong. sorry 😦
Kaiepi ah right, shell prints % or whatever w/o the newline 13:02
lizmat m: my $a = "foo"; $a .= chop; dd $a 13:18
camelia Str $a = "fo"
lizmat ^^ to do it in place
14:11 kueppo joined 14:15 frost left 14:43 Heptite joined 14:52 Heptite left 15:04 Heptite joined, kueppo left
Rog Yeah afaik nothing actually changes strings in place except smartmatch with destructive substitution 16:08
And even that doesn’t mutate the original string technically I think
In the sense that the underlying data is not shuffled around, just a new value generated and stuck in the container 16:09
16:40 dakkar left 19:54 archenoth left, archenoth joined 20:34 Oshawott joined 20:35 Oshawott left 20:37 archenoth left
guifa Rog: that's correct. Strings are immutable in Raku. If you try to do the in place substitution on a bound variable, you'll have issues. 23:45
m: my $a = 'foo'; $a ~~ s/f/F/; say $a; # no problems
camelia Foo
guifa m: my $a := 'foo'; $a ~~ s/f/F/; say $a; # oops
camelia Cannot modify an immutable Str (foo)
in block <unit> at <tmp> line 1