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:14
Nemokosch left
01:09
Kaiepi left
01:45
deoac left
02:55
habere-et-disper left
02:56
razetime joined
03:36
razetime left
04:01
razetime joined
04:49
Heptite left
05:57
CIAvash left
06:00
CIAvash joined
06:53
Kaiepi joined
06:59
Kaipei joined
07:02
Kaiepi left
07:54
razetime left
08:26
razetime joined
11:37
habere-et-disper joined
|
|||
habere-et-disper | Can one defined constants together? | 13:29 | |
m: constant ($foo, $bar) = 3, 4 | |||
camelia | ===SORRY!=== Error while compiling <tmp> Missing initializer on constant declaration at <tmp>:1 ------> constant⏏ ($foo, $bar) = 3, 4 |
||
habere-et-disper | s/defined/define :-) | 13:38 | |
Nemokosch | I think it boils down to the behavior of `constant` | 13:45 | |
14:10
codesections joined
14:17
habere-et-disper left
14:21
codesections left
14:30
codesections joined
14:52
deoac joined
|
|||
deoac | Is it possible to have multi-dispatch when there's a 'slurpy' in the signature? | 14:53 | |
``` | 14:54 | ||
our proto foo ( | ) { * } | |||
multi foo (Str $bar!, $*args) { ... } | |||
multi foo (Str $bar!, Str $baz!, $*args) { ... } | |||
``` | |||
BTW, I also like the `forgiven` idea :-) | |||
15:06
Heptite joined
|
|||
Nemokosch | deoac: first off, you know that $*args is a _dynamic variable_, not any sort of slurpy? | 15:45 | |
I think you were thinking of **@args (or *@args, if you want the extra part to be flattened) | |||
16:46
Kaipei left
|
|||
deoac | Yes, sorry about the typo | 17:08 | |
Let me try again... | 17:22 | ||
How can I get the following to work? `$baz` always gets swallowed by `*@args` in the first version of `foo` | 17:24 | ||
`our proto foo ( | ) { * } | |||
multi foo (Str $bar!, *@args) { ... } | |||
multi foo (Str $bar!, Str $baz!, *@args) { ... } ` | |||
17:29
razetime left
17:44
deoac left
|
|||
Nemokosch | Are you sure the order of declaration doesn't matter? I don't know the rules by heart | 17:56 | |
18:17
Heptite left
18:21
Kaipei joined
18:26
Heptite joined
19:55
Kaipei left
19:57
deoac joined
|
|||
deoac | Positional arguments have to go before slurpy arguments. | 19:59 | |
From docs.raku.org/type/Signature#index...y_argument :Note that positional parameters aren't allowed after slurpy (or, in fact, after any type of variadic) parameters: | 20:00 | ||
:(*@args, $last); | |||
# ===SORRY!=== Error while compiling: | |||
# Cannot put required parameter $last after variadic parameters | |||
guifa | So the problem is that the for your foo(), Str Str Int matches BOTH signatures | 20:21 | |
what is the type of things you're slurping into @args ? | 20:22 | ||
If they're Str, it's an ambiguous signature (unless called with a single Str). If there's some way to show what valid values of baz are, you could do Str $baz where { … } which would cause that signature to be more specific, and it would take priority in dispatch | 20:24 | ||
20:46
Kaipei joined
|
|||
deoac | Yes, the `where` idea could work. Thank youu. | 21:00 | |
Nemokosch | I think if it doesn't take priority, the order of declaration would decide | 21:06 | |
(not the order of arguments, mind you) | 21:07 | ||
21:39
deoac left
21:47
guifa_ joined
21:49
Heptite left,
guifa left
21:50
Heptite joined
|
|||
gfldex | m: multi sub foo(Int $a, *@a) { say 1 }; multi sub foo(Int $a, | (Int $b, *@a)) { say 2 }; foo 1,2,3; foo 1, 'zwei', 3; | 21:53 | |
camelia | 2 1 |
||
gfldex | guifa_: please note ^^^ (maybe a bug tho) | 21:54 | |
trentj | How would I initialize an array of 10 zeros without typing `0` ten times? | 21:58 | |
gfldex | m: @a = 0 xx 10; dd @a; | 22:00 | |
camelia | ===SORRY!=== Error while compiling <tmp> Variable '@a' is not declared. Perhaps you forgot a 'sub' if this was intended to be part of a signature? at <tmp>:1 ------> <BOL>⏏@a = 0 xx 10; dd @a; |
||
gfldex | m: my @a = 0 xx 10; dd @a; | ||
camelia | Array @a = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0] | ||
trentj | perfection | 22:02 | |
gfldex | m: my @a is default(0); say @a[^10]; | ||
camelia | (0 0 0 0 0 0 0 0 0 0) | ||
gfldex | you can also initialise without initialising. :) | 22:03 | |
trentj | ah! I was wondering about that too, nice. | 22:04 | |
I wrote a lot of Perl 5 once upon a time but this is a new adventure. | 22:06 | ||
Nemokosch | m: my Numeric @a[10] is default(0); | 22:24 | |
oops, wrong example | 22:25 | ||
this, on the other hand: | |||
m: my Numeric @a[10] = 0 xx * | |||
oh right, this is not the repl... | |||
m: my Numeric @a[10] = 0 xx *; dd @a; | |||
<@541404250668924941> this is, for example, constrained to this particular size | 22:26 | ||
trentj | interesting | 22:31 | |
22:44
Kaipei left
23:00
deoac joined
23:35
habere-et-disper joined
23:39
deoac left
|