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.
masukomi re our discussion about prefixing imported methods, and how it looked like lizmat's "from" module could prolly be hacked to do it. I looked at it but it was beyond my newb abilities, so i asked liz 00:53
> I’m thinking something like
> use from "Foo" prefix => ‘f’
> And then Foo::bar-method becomes callable as f-bar-method.
> (+ current functionality of specifying methods to import)
> Is that possible?
and she said
> A named argument in a "use" statement, is currently interpreted by the system as an indicator for EXPORT::DEFAULT namespace. So you would have to specify it as a positional Pair, so
> "prefix" => "f"
> rather than
> prefix => "f"
> But yeah, you could look at any semantics you'd want.
so ... yeah. Maybe <@724421839924756480> would be interested in tackling that. I would, but I don't understand enough ... yet. 😉
guifa_ masukomi: editing that would be pretty easy 01:12
The from module is just a about a dozen lines of code
github.com/lizmat/from/blob/97a7c0...akumod#L12 <-- for instance, this just passes through a Map. It would be fairly trivial to to modify it to prefix the keys 01:15
Basically (untested) Map.new: ("use $distro; MY::<@exports[]>:p".EVAL).map({Pair.new: $prefix ~ .key, .value}) 01:18
The main question is how you'd want to pass in the prefix (perhaps `use prefix-from <Module::Name prefix-value- symbolA symbolB symbolC>`) 01:20
Doing it that way just changes the EXPORT sub to `sub EXPORT($distro, $prefix, *@exports is copy) { … }` 01:44
01:56 frost joined 03:30 Kaiepi left 03:31 Kaiepi joined 05:05 Oshawott left
yabobay can hashes have Int indices? 07:02
07:54 razetime joined 08:33 m_athias left 08:35 m_athias joined 08:43 discord-raku-bot left, discord-raku-bot joined 09:00 frost left 09:03 frost joined
guifa_ yes, but you need to declare them slightly differently, otherwise upon assingmnent they'll be autocoerced into Str 09:33
m: my Str %foo{Int}; %foo{5} = 'a'; say %foo.keys.head.WHAT 09:35
camelia (Int)
guifa_ For scalared vars: 09:37
m: my Hash[Str,Int] $foo .= new; $foo{5} = 'a'; say $foo.keys.head.WHAT;
camelia (Int)
09:59 razetime left 10:00 razetime joined
yabobay i got confused before cause i was doing %foo<$_> which is completely the wrong thing 11:03
i didn't read about the angle brackets yet so that was my fault
Nemokosch `%foo<<$_>>` could work if `$_` is a string, I think 11:11
but yeah, `%foo{$_}` is better
yabobay what does %foo<<$_>> mean? 11:17
Nemokosch << is word quoting with variable interpolation 11:19
so it's kinda like %foo{"$_"} in this case 11:20
yabobay can i have ranges that are descending? 12:03
m: say $_ for 10 .. 0
whyyy
Nemokosch There are multiple ways 12:04
the simplest would be to just use the sequence operator instead of the range operator 12:05
m: .say for 10 ... 0
yabobay what's the difference with that?
Nemokosch a range is a different type to begin with
yabobay a sequence is what?
Nemokosch "An iterable, potentially lazy sequence of values" according to the docs 12:07
yabobay huh
isn't that what a range is
Nemokosch absolutely not
yabobay a range is supposed to superficially look like a sequence? 12:08
Nemokosch "Interval of ordered values"
yabobay ohhh
so a sequence can be whatever
but a range has to be ordered 12:09
Nemokosch it has a step of "one"
> Iterating a range (or calling the list method) uses the same semantics as the ++ prefix and postfix operators, i.e., it calls the succ method on the start point, and then the generated elements.
yabobay i think i get it 12:11
why not just use a sequence for the same things?
why have ranges exist
Nemokosch I suppose because 1) ranges have a common and well-defined purpose 2) they can be effectively checked for with smartmatch 12:13
12:43 discord-raku-bot left, discord-raku-bot joined
Kaiepi sequences are pretty dynamic compared to a range. a range is able to smartmatch and behave as a full-blown `Positional` given its bounds alone 13:24
what you write after `...` is not the end of the sequence, but a condition to terminate the sequence on. it doesn't know the end until the entire thing is computed 13:26
m:```
say 1...(10 but role { method ACCEPTS(Mu \x) { dd x; callsame } })
```
yabobay so sequences cannot be lazy 13:27
Kaiepi they can be
is `&dd` stderr? 13:28
m:``` 13:29
say 1...(10 but role { method ACCEPTS(Mu \x) { say x; callsame } }) # should have correct order
```
`&say` wants the entire list, so it's reified eagerly here 13:30
13:31 frost left
yabobay i dont even know what any of that is 13:32
the fact there;s a but keyword is kinda funny
Kaiepi `ACCEPTS` is the method backing a smartmatch. starting a sequence with a number will try to increment until that terminating smartmatch succeeds. i'm trying to show how it goes about calculating its elements 13:36
`but` is a runtime mixin. `ACCEPTS` is being overridden on `10` 13:38
`but` makes a runtime mixin. `ACCEPTS` is being overridden on `10`
14:24 jgaz joined 15:04 razetime left 20:56 jgaz left
Nemokosch Can I do something like... a parameter that can be a Map or a List, in case of a List, it should be turned into a Map using .pairs semantics? 20:59
I mean eventually I can but with some type annotation magic 21:01
gfldex <@297037173541175296> ^^^ 22:03
m:```
multi foo(Map $wanna) {
say „got $wanna“;
}
multi foo(*@okish) {
foo @okish.pairs.Map;
}
foo 1,2,3,4;
```
Nemokosch the annoying thing is that it's really one argument out of 4 22:22
23:50 discord-raku-bot left, discord-raku-bot joined