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.
07:27 frost joined 07:37 Da-ding joined
Da-ding Hi folks 07:54
Why does `for` treat a hash's value as singular, while `map` treats it as plural?
```
> my %h = A => (1,2)
{A => (1 2)}
> for %h<A> {.say}
(1 2)
> %h<A>.map({.say})
1
2
(True True)
```
Also, if I wrap the Hash in an array I can't seem to get `map` working with it:
```
> my @a = [{A => (1,2),},];
[{A => (1 2)}]
> for @a { for $_.<A> { say $_ } }
(1 2)
Hi folks 07:55
Why does `for` treat a hash's value as singular, while `map` treats it as plural?
`
> my %h = A => (1,2)
{A => (1 2)}
> for %h<A> {.say}
(1 2)
> %h<A>.map({.say})
1
2
(True True)
`
Also, if I wrap the Hash in an array I can't seem to get `map` working with it:
`
> my @a = [{A => (1,2),},];
[{A => (1 2)}]
> for @a { for $_.<A> { say $_ } }
(1 2)
07:55 discord-raku-bot left 07:56 discord-raku-bot joined 08:04 discord-raku-bot left, discord-raku-bot joined
Nemokosch seems like a lot of "spamming" 08:33
please use github gists (or some other code pasting platorm you prefer) if you want to write multiple lines of code at once
anyway, I think I can answer this one
08:34 Nemokosch joined
Nemokosch so 08:36
m: my %h = A => (1,2); dd %h;
camelia Hash %h = {:A($(1, 2))}
Nemokosch m: my %h = A => (1,2); dd %h<A>;
camelia List %h = $(1, 2)
Nemokosch what does this tell us? That %h<A> is treated as a Scalar.
08:38 frost left
Nemokosch What happens if you treat something as a Scalar? For one, it will be iterated as one entry in a for loop. 08:39
m: .say for $(1, 2, 3, 4)
camelia (1 2 3 4)
Nemokosch On the other hand, the map method only cares whether your stuff is Iterable or not 08:41
08:43 frost joined
Nemokosch m: my $list = (1,2,3,4); dd $list; $list.map: *.say; 08:44
camelia List $list = $(1, 2, 3, 4)
1
2
3
4
Nemokosch I think this is because of this signature: > multi method map(Iterable:D \iterable) 08:45
\iterable indicates that we drop the container altogether and rom that point on, they are all just iterables 08:46
however, this doesn't seem to be the behavior if you use map as a "standalone function"
m: map *.say, $(1, 2, 3, 4) 08:47
camelia (1 2 3 4)
Nemokosch the signature is: > multi sub map(&code, +values) 08:48
And I didn't get this: 08:52
> Also, if I wrap the Hash in an array I can't seem to get map working with it:
I see no map in the example
Da-ding: whatcha say my man ^^ 08:53
08:57 Nemokosch left
Da-ding Excellent, thank you 08:57
Sorry about posting twice. I'll be sure to use Gists etc next time 08:58
Da-ding! I'll play around with `dd` and see how I go solving the second half (with the missing `map`) 09:00
Nemokosch By the way
what are you trying to achieve?
Da-ding! I'm iterating over a block of JSON to parse a bunch of dependencies for another tool. It's an array of packages, which each have an array of dependency IDs 09:02
Because the actual tasks was pretty minimal, I'm trying to stick with just a few nested blocks and using `$_`, which is where my plurality access issues are coming into it 09:03
Nemokosch if you want it to act as a positional (so basically list-like), you can prefix it with @ 09:04
I wonder if the bot works now from this end 09:05
m: say 'Hello'
okay, very nice 09:06
Da-ding! Sweet, that does the job 09:07
I was using `$_.<dependencies[*]` as a workaround but I presume that's much less ideal than `@($_.<dependencies>)` ? 09:08
Nemokosch first off, I think you can get used to just dropping $_ when you make method calls to it 09:09
`.<dependencies>` is just fine
second, I think [*] is a proper slice - if I were to guess, it takes up extra memory - however, you might gave a good idea 09:10
the so-called zen-slice might work here
so `.<dependencies>[]`
I would give it a try
Da-ding! Nice, thank you very much 09:12
Nemokosch from what I know, the zen-slice is also just a kind of context assurance thing
so it doesn't create a copy or anything
no problem 🙂 09:14
09:50 Kaipii left, Kaipii joined 10:32 Da-ding left 10:57 frost left 11:13 frost joined 11:38 frost left 11:42 frost joined 12:46 frost left 12:47 frost joined
stevied anyone having problems getting the grammar preview working in comma IDE? I have the paid version. 12:55
14:31 frost left 21:53 Kaipii left, Kaipii joined 21:59 n1to joined, n1to left 22:14 deadmarshal left 22:18 deadmarshal joined 23:02 Kaipii left 23:57 Kaiepi joined