01:49 discord-raku-bot left, discord-raku-bot joined 01:53 gfldex left 01:57 gfldex joined 03:05 frost joined 04:21 frost left 04:37 guifa joined 05:23 frost joined 06:37 frost left 06:40 frost joined 07:16 frost left 07:28 frost joined 07:34 frost left 08:07 dakkar joined 10:21 qorg11 left 12:46 destroycomputers left, discord-raku-bot left, discord-raku-bot joined, destroycomputers joined 16:39 dakkar left
stevied what is the comma doing in this line? `my @out = [ [@in.shift], ];` 20:07
MasterDuke make a list of lists, see the single arg rule in the docs 20:08
stevied it's creating an array within an array but I'm not sure how 20:09
MasterDuke the ,
stevied ok, this here: docs.raku.org/syntax/Single%20Argument%20Rule 20:13
haven't seen this before
why doesn't `my @array = [ 1, ];` create an array within the @array? 20:19
MasterDuke there's only one level there, `my @array = [ [1], ];` would make two 20:21
m: my @a = [ [1,2], ]; say @a.elems; say @a[0].elems 20:22
camelia 1
2
stevied i'm confused. why doesn't [ [ 1 ] ] create an array in an array? 20:25
MasterDuke because commas create lists/arrays, not [] or () 20:27
stevied no matter how many square brackets I use, it's always just on element in an array
ok, i see my confusion now. the outer brackets in `[ [@in.shift], ]` are superfluous 20:29
don't need them
thanks 20:30
MasterDuke np
20:43 qorg11 joined
Nemokosch interesting 21:01
stevied ok, got this: 23:03
```
multi blah ($string) {
$string = 3;
}
multi blah (@array) {
@array.shift;
}
my @array = 1, 2, 3;
blah @array;
say @array;
my $string = 'old';
blah $string;
say $string;
the @array is actually changed by the function, which was unexpected 23:04
the string is immutable unless I do `is copy`
why is the array mutable and the string isn't?
guifa that $string = 3 there should fail 23:11
stevied right, it does
guifa @array.shift doesn't change the array in @array, it just tells @array to do something 23:12
m: sub foo(@a) { @a.shift }; my @a = 1,2,3; say @a.WHICH; foo @a; say @a.WHICH; 23:13
camelia Array|5485619587248
Array|5485619587248
stevied the `say @arrary` will print out [2, 3]
so it changed
guifa If I put three balls in a bag, and take one out, is it the same bag?
stevied yes. but why doesn't the bag stop you from taking balls out like with the string? 23:15
the string is read only. I'm wondering why there is a different rule for the array. I can do anything I want to it and it changes outside the function.
I can do @array = 7 inside the `blah` function and it works 23:17
guifa So it's a two part answer. 23:19
But it revolves around the question of what we're changing. 23:20
And then also the assignment type (determined by the sigil)
MasterDuke a very short answer is that an array is a container. you can't change the container itself, it's immutable like the string is in your example, but you can change its contents 23:22
stevied but I thought scalars were also containers 23:23
Nemokosch well, it seems like this abstraction is more disturbing than useful here
at the end of the day, the behavior is exactly the same as it would be in Javascript or Python
guifa Nemokosch: almost
stevied well, it's much different from perl
which is what I'm used to
guifa m: sub foo (@x) {Ā @x = 4,5,6 }; my @y = 1,2,3; foo @y; say @y; 23:24
camelia [4 5 6]
Nemokosch an array is composit, even if you take it as a literal
guifa ^^ that would be different in Javascript or Python, I believe
because they don't distinguish different types of assignments 23:25
Nemokosch I don't think that could change with any sigil
and tbh I wouldn't consider this a feature in this context, more an anomaly
guifa m: sub foo ($x) { $x = 4,5,6 }; my @y = 1,2,3; foo @y; say @y; 23:26
camelia Cannot assign to a readonly variable or a value
in sub foo at <tmp> line 1
in block <unit> at <tmp> line 1
Nemokosch implicit "is rw"
the compiler does warn you about it of course, I mean that the @ sigil is always rw 23:27
is it even possible to make it readonly or something?
guifa You can pass a list
m: sub foo (@x) { @x = 4,5,6 }; my @y is List = 1,2,3; foo @y; say @y; 23:28
camelia Cannot modify an immutable Int (1)
in sub foo at <tmp> line 1
in block <unit> at <tmp> line 1
Nemokosch okay but this fails because of the data passed, right? 23:29
not because of the parameter
guifa @x is read only regardless. The question is whether what's passed into X well allow itself to do anything. 23:30
Nemokosch if it's read only, how come you assign a value to it which it even keeps? 23:31
stevied that was my question, too
Nemokosch which is btw in accordance with what Rakudo says 23:32
guifa Because @foo = is list assignment, and $foo = is scalar assignment, and they're subtly different
well, subtly different except here
Nemokosch ie "you don't have to mark is rw on @ sigilled parameters" 23:33
list assignment again... don't get me started
stevied gotta go eat. I'll check back later. 23:34
Nemokosch eating is caring
I'm yet to see list assignment written down in a positive context 23:36
remember switching @a and @b? 23:38
m: my @a = 1, 2; my @b = 3, 4; (@a, @b) = (@b, @a); dd @a, @b; 23:40
big yikes
and unlike the famous JS [] == ![], this is a perfectly realistic scenario 23:44
m: my $a = [1, 2]; my $b = [3, 4]; ($a, $b) = ($b, $a); dd $a, $b; 23:50
see, it can be done