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 | is this one long enough? stackoverflow.com/questions/337887...6#66056086 | 00:35 | |
. | 00:37 | ||
separately | |||
i keep getting `expected Associative[Hash] but got Hash` when calling this method `our sub insert-pr(Hash %pr_details, DB::SQLite $db){` | |||
i had something similar earlier with `expected Positional[Array] but got Array` in another method. Anyone know what's going on or what the magic incantation is to make it not expect something I didn't tell it to expect? | |||
guifa_ | masukomi do you intend for pr_details to be a hash of hashes? | 00:40 | |
masukomi | i do not. | 00:41 | |
guifa_ | Okay, there's the issue :-) You've se %pr_details to be an associative whose value type is a Hash (so, a hash of hashes, in effect) | 00:42 | |
either change to | |||
Anton Antonov | <@526609611680120842> Yes, it is long. | ||
guifa_ | our sub insert-pr(Hash $pr_details … ) | ||
or to keep the % sigil | |||
Anton Antonov | <@526609611680120842> Yes, it is long enough. | 00:43 | |
guifa_ | our sub inserst-pr(%pr_details where Hash … ) | 00:44 | |
But I'm going to guess what you really care about is that it's Associative — that is, a set of key values. In that case, the fact that it has a % sigil takes care of it: | |||
masukomi | a) thank you b) I would have never guessed the 2nd syntax. I'd like to keep the `%` because then it'll be more obvious in the method that it's a Hash wherever referenced. | 00:45 | |
guifa_ | m: sub foo(%a) { say "%a is a hash" }; my %b = <a A b B>; foo %b | 00:46 | |
camelia | %a is a hash | ||
guifa_ | m: sub foo(%a) { say "%a is a hash" }; my $b = 5; foo $b | ||
camelia | Type check failed in binding to parameter '%a'; expected Associative but got Int (5) in sub foo at <tmp> line 1 in block <unit> at <tmp> line 1 |
||
guifa_ | Also, the error with Position[Array] but got Array is the same idea. `Array @foo` is a list-y thing (officially Positional) that contains only Array objects. To force it to be an Array, `Array $foo` or `@foo is Array`. But if you don't care whether it's an Array, or a List, or anything else that contains items in a sequence, just use `@foo` and it'll accept any of them | 00:53 | |
masukomi | thanks. | 00:56 | |
01:05
[Coke] left,
[Coke] joined
01:50
[Coke] left
01:53
[Coke]_ joined
|
|||
deoac | Lately, I've been writing code like `$x = foo $x with $x`. Is there a more concise way to write this? | 02:35 | |
`foo` is a sub, not a method | |||
03:00
saint- left
03:27
[Coke]__ joined
03:29
[Coke]_ left
03:34
[Coke]_ joined
03:37
[Coke]__ left
03:51
deoac left
04:02
deoac joined
04:56
archenoth joined
05:04
[Coke] joined
05:06
[Coke]_ left
|
|||
Nemokosch | deoac: what about `$_ = .&foo with $x` ? | 05:45 | |
apparently .= also works with the ampersand | 05:49 | ||
`.=&foo with $x` can work (mind that there is no space between = and & in this case, otherwise it doesn't parse for some reason) | 05:50 | ||
06:41
[Coke]___ joined
06:43
[Coke] left
06:48
[Coke] joined
06:50
[Coke]___ left
|
|||
Nahita | ```raku | 06:55 | |
# new op | |||
sub infix:<?=>(\op1, &op2) { op1 = op2(op1) with op1 }; | |||
# sample | |||
my ($x, $y) = 4; | |||
my &f = * - 7; | |||
$x ?= &f; | |||
$y ?= &f; | |||
say $x, " ", $y; # -3 (Any) | |||
``` | |||
07:56
dakkar joined
08:12
deoac left
08:17
frost joined,
razetime joined
08:18
[Coke]_ joined
08:20
[Coke] left
|
|||
Nemokosch | how do I search a sequence of items in a list? | 09:10 | |
lizmat | you mean finding (3,4,5) in (1,2,3,4,5,6) ? | 09:12 | |
Nemokosch | yes | 09:14 | |
Nahita | $seq.rotor($needle => -$needle .succ).grep(* eqv $needle).so | 09:18 | |
09:22
Oshawott joined
09:23
archenoth left
|
|||
Nemokosch | thank you, this will work with first | 09:23 | |
lizmat | m: my @a = 1..10; my @b = 4,5,6; say @a.grep(@b[0],:k).map({ my $slice := @a[$_ .. $_ + @b.end]; $slice if $slice eqv @b.List }) | 09:25 | |
camelia | ((4 5 6)) | ||
lizmat | this works only if the source is a List / Array | 09:26 | |
the .rotor approach is more general, but probably also a lot more CPU intensive, as it will create lists for *each* element in the source, rather than only when the first element matches in my conceptual version | 09:27 | ||
Nemokosch | I didn't think this would be a problem but... I actually don't want the first match. I want the position of possibly all matches | 09:33 | |
lizmat | m: my @a = 1..10; my @b = 4,5,6; say @a.grep(@b[0],:k).grep({ @a[$_ .. $_ + @b.end] eqv @b.List }) | 09:34 | |
camelia | (3) | ||
lizmat | basically, grep on the first element first, get the positions, and then further grep on matches, and wind up with the positions | 09:35 | |
Nemokosch | my $pos = $list.rotor($latin-name-list => -$latin-name-list .succ).grep(* eqv $latin-name-list, :k) | 09:37 | |
this did work, by the way, but yes it did kinda melt the CPU | |||
09:55
[Coke] joined
09:57
[Coke]_ left
10:03
[Coke]___ joined
10:05
[Coke] left
11:33
[Coke] joined
11:34
[Coke]___ left
13:00
razetime left
13:07
razetime joined
13:11
[Coke]_ joined
13:13
[Coke] left
13:18
[Coke]__ joined
13:20
[Coke]_ left
|
|||
lizmat | and yet another Rakudo Weekly News hits the Net: rakudoweekly.blog/2022/10/03/2022-...g-to-core/ | 13:20 | |
13:23
deoac joined
|
|||
deoac | Nahita: Thanks, that's a good idea. | 13:27 | |
14:50
[Coke]__ left
14:52
[Coke] joined
14:54
razetime left
14:55
razetime joined
14:57
[Coke] left,
deoac left
15:19
razetime left
15:27
razetime joined
15:36
razetime left
15:41
razetime joined
16:01
razetime left
16:02
razetime joined
16:06
razetime_ joined
16:07
razetime left
16:34
dakkar left
17:25
razetime_ left
|
|||
Rog | Wouldn’t this go out of bounds? | 18:08 | |
Say the list’s length is 2 | |||
Take two, advance -3 | |||
Nemokosch | I think that's impossible with rotor, unless you set some option | ||
Rog | m: (1..10).rotor(2 => -3) | ||
Nemokosch | hahaha | ||
gotcha - the code is whitespace sensitive | |||
-$n .succ is -$n + 1 | 18:10 | ||
-$n.succ is -$n - 1 | |||
Rog | Ugh | ||
That feels… kinda bad | |||
Nemokosch | I don't know how this parses tbh | ||
but apparently there is this difference | |||
Rog | It feels inconsistent | ||
I mean if method call binds more tightly than numeric negation, I don’t think whitespace alone ought to change that | |||
Nemokosch | something is definitely very interesting with the parsing | 18:12 | |
Rog | It almost feels intentional but somehow I think it isn’t? | ||
Gosh I really don’t know | |||
Nemokosch | could it be that it's somehow not a method call when the whitespaces are present? | 18:14 | |
if I add whitespaces between the sign and the sigil, that makes no difference | |||
lizmat | yeah, method calls bind more tightly than prefix op | 18:18 | |
also over the years been a long discussion, and that's where we wound up with | |||
the whitespace version has a lower priority, but that was really just a (nice) side-effect | 18:19 | ||
just like natural languages, it depends where you put your comma's :-) | 18:20 | ||
and yes, I've been bitten by that myself :-) | |||
Nemokosch | how is it implemented? I see that 1-$num .succ parses as 1-($num.succ); what's the rule? | 18:25 | |
lizmat | src/Perl6/Grammar.nqp contains the implementation :-) I have no idea where that is exactly implemented, without looking at it in depth | 19:01 | |
22:07
Manifest0 left,
Manifest0 joined
22:37
Manifest0 left,
Manifest0 joined
|