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. |
|||
00:05
ab5tract left
01:01
Manifest0 left
01:53
rf joined
02:36
rf left
02:38
discord-raku-bot left
02:39
discord-raku-bot joined
02:59
kjp left
03:06
kjp joined
05:33
Heptite left
05:39
discord-raku-bot left,
discord-raku-bot joined
05:46
discord-raku-bot left,
discord-raku-bot joined
05:54
kjp left
05:56
kjp joined
06:39
discord-raku-bot left,
discord-raku-bot joined
06:43
discord-raku-bot left
06:44
discord-raku-bot joined
06:48
discord-raku-bot left,
discord-raku-bot joined
06:52
discord-raku-bot left
06:53
discord-raku-bot joined
08:39
discord-raku-bot left,
discord-raku-bot joined
09:39
discord-raku-bot left,
discord-raku-bot joined
10:36
Manifest0 joined
10:39
discord-raku-bot left
10:40
discord-raku-bot joined
10:47
ab5tract joined
11:12
ab5tract left
11:20
ab5tract joined
11:30
ab5tract left
11:39
discord-raku-bot left
11:40
discord-raku-bot joined
11:58
ab5tract joined
12:16
ab5tract left
13:39
discord-raku-bot left,
discord-raku-bot joined
13:48
ab5tract joined
13:59
ab5tract left
14:31
ab5tract joined
15:17
ab5tract left
15:40
discord-raku-bot left,
discord-raku-bot joined
15:44
discord-raku-bot left
15:45
discord-raku-bot joined
15:55
rf joined
16:20
ab5tract joined
17:05
jgaz joined
17:10
ab5tract left
17:26
Heptite joined
18:35
n1to joined
|
|||
stevied | why does a `multi method new()` method get called with `Object.new(foo => 'buzz')` | 18:44 | |
Nahita | perhaps because of the %_ | 18:45 | |
a method takes arbitrary number of named parameters by default | |||
to ease inheritance stuff | 18:46 | ||
stevied | huh, didn't know that. what is %_? | ||
Nemokosch | Is it the only candidate that gets called? | 18:47 | |
stevied | no, I have other multi new method if that's what you mean | ||
Nemokosch | Yes | 18:48 | |
Nahita | it gets the extra named parameters into itself in methods implicitly | ||
in normal subroutines it doesn't appear | |||
stevied | ok, I see it here: docs.raku.org/language/functions#A...signatures | 18:49 | |
Nahita | somewhat akin to @_ getting the positional arguments into itself *if* it's explicitly referred within the body of a routine | ||
well in Perl that's the only way of getting implicitly the parameters | |||
except they have introduced signatures recently... finally... | |||
well you know Perl better than me so | 18:50 | ||
Nemokosch | Well, are they used though | ||
stevied | so here's the new method I have: | 18:51 | |
``` | |||
multi method new() { | |||
self.bless(dir => $*CWD); | |||
} | |||
``` | |||
how do I catch if a bad named arg is passed? | |||
Nemokosch | I'd say it's quite bizarre that named arguments can be discarded like that... | ||
stevied | I gotta check %_ I guess? | 18:52 | |
Nahita | well you can explicitly check whether %_ is empty | ||
but there are 2 more ways actually | |||
one is marking the class as `is hidden` | |||
as mentioned, %_ exists for "interface consistency" | |||
like to redirect methods to parents in children | |||
with whatever args they passed | 18:53 | ||
with `class A is hidden { }`, you kill that redispatching mechanism | |||
depending on what's wanted, that might or might not be okay | |||
other solution is to do `*% ()` in the signature of the method | 18:54 | ||
that says "take *any* number of extra named parameters such that they are destructable to... well nothing!" | |||
so it will prevent any extra arguments if that makes sense | |||
maybe there are other ways idk | 18:55 | ||
stevied | huh, interesting | ||
Nahita | the % parameter is unnamed but it can be named like `*%a ()` but since the purpose of its existence there is something different, i.e., prevent extras, it might as well be unnamed to signal that | 18:57 | |
and language fantastically allows unnamed parameters, so | |||
stevied | so I got this: | 18:58 | |
``` | |||
multi method new(*%) { | |||
self.bless(dir => $*CWD); | |||
} | |||
``` | |||
that still allows me to do `new(zzz => 'fuzz')` | |||
oh, wait, read your wrong | |||
ok, works: `*% ()` | 19:00 | ||
weird though. don't quite get it | |||
Nemokosch | Tbh you would almost think this should be the default behavior... | ||
Nahita | `*%` means: slurp *every* extra named parameter you can right? | 19:01 | |
`*%h` means: slurp *every* extra named parameter you can right? | |||
like `*@a` means slurp every positional | |||
lizmat | indeed | ||
stevied | what is the `()` though? | ||
lizmat | and that is always implicit in method signatures | ||
Nemokosch | Perhaps if a missing signature weren't mistaken for an empty signature, the right thing would happen by default | ||
Nahita | that's the destructuring part | ||
that's so cool actually | 19:02 | ||
it applies not only the hashes but arrays too | |||
Nemokosch | <@563790557831495691> you pointed out the inconsistency accurately, by the way: a subsignature doesn't quite work like the signature itself | 19:03 | |
I hope I have that issue somewhere... | |||
Nahita | an example | ||
```py | |||
>>> sub f(@arr ($first, *@rest)) { $first.say; @rest.elems.say } | |||
>>> f ["head", 10, 20, 30] | |||
head | |||
3 | |||
``` | |||
an example | 19:04 | ||
```perl | |||
sub f(@arr ($first, *@rest)) { | |||
$first.say; | |||
@rest.elems.say | |||
} | |||
>>> f ["head", 10, 20, 30] | |||
head | |||
3 | |||
``` | |||
this is an "extension" of `sub f(@arr)` of writing things | |||
i'm expecting a positional allright | |||
and i also destructure it along the way for use in the subroutine | |||
$first and the *@rest | 19:05 | ||
stevied | jesus, I got some more learning to do, I guess | ||
Nahita | i can do `Int $first` there | ||
and all of a sudden i have a requirement that the passed array need its first element to be Integer | |||
so wrapping up with the *% () | |||
stevied | yeah, I see now | 19:06 | |
Nahita | i want everything, anything named to be captured | ||
stevied | cool | ||
Nahita | ok | ||
stevied | the requriement is it's empty | ||
Nahita | yeah :p | ||
everything and nothing | |||
stevied | I didn't know about that "extension" syntax. probably read it, made no sense to me, so I forgot it | 19:07 | |
signatures in raku are GD insane compared to perl. never seen anything like it before. does any language do such similar gymnastics? | 19:08 | ||
19:16
Manifest0 left
|
|||
Nemokosch | Oh right, I found the issue | 19:31 | |
you can pass a pair to a function like a named argument, or like a positional argument | 19:32 | ||
so far so good | |||
how can you pass it like a positional argument, if you have a subsignature? | |||
and the pair should be a part of the subsignature | |||
19:46
n1to left
19:47
n1to joined
20:03
rf left,
rf joined
21:11
Fam joined
21:34
Fam left
23:04
rf_ joined
23:05
rf left
23:30
n1to left
23:36
rf_ left
|