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:18
Manifest0 left
07:52
ab5tract joined
|
|||
:(**@rest, *%rest) | should i use my \MY-CONSTANT = 42; or my constant MY-CONSTANT = 42; | 08:27 | |
Nahita | not exactly interchangable in general, constant evaluates its RHS at compile time | 08:41 | |
:(**@rest, *%rest) | m: (my & = { })() | 08:47 | |
Raku eval | |||
:(**@rest, *%rest) | it timed out? | ||
instead of stack overflowing | 08:48 | ||
hmm | |||
m: my &_ = *.CALL-ME; &_(&_) | 08:49 | ||
Raku eval | Exit code: 1 No such method 'CALL-ME' for invocant of type 'WhateverCode' in block <unit> at main.raku line 2 | ||
:(**@rest, *%rest) | m: my &_ = *(); &_(&_) | ||
Raku eval | Exit code: 1 No such method 'CALL-ME' for invocant of type 'Whatever' in block <unit> at main.raku line 1 | ||
:(**@rest, *%rest) | tf | ||
Zephyr | m: my &f = { _$() }; &f(&f); | 08:50 | |
Raku eval | Exit code: 1 ===SORRY!=== Error while compiling /home/glot/main.raku Two terms in a row at /home/glot/main.raku:1 ------> my &f = { _ā$() }; expecting any of: infix infix stopper statement end statement modifier statement modifier loop | ||
Zephyr | typo | ||
:(**@rest, *%rest) | m: my &_ = { $_(); $_() }; &_(&_) | ||
Zephyr | m: my &f = { $_() }; &f(&f); | ||
Raku eval | Exit code: 1 No such method 'CALL-ME' for invocant of type 'Any' in block <unit> at main.raku line 1 | 08:51 | |
Zephyr | m: my &f = -> &g { &g(); } &f(&f); | ||
Raku eval | Exit code: 1 Too few positionals passed; expected 1 argument but got 0 in block <unit> at main.raku line 1 | ||
:(**@rest, *%rest) | m: my &_ = { &_ }; _ | 08:52 | |
Raku eval | |||
:(**@rest, *%rest) | m: my &_ = { _ }; _ | ||
Raku eval | |||
Zephyr | it ran successfully without errors, just that doesn't invoke a function call if I'm right | ||
:(**@rest, *%rest) | m: sub forever { forever } forever | 08:53 | |
Raku eval | |||
Zephyr | m: my &_ = { &_() }; _() | ||
Raku eval | |||
Zephyr | oh huh | ||
it doesn't show timeout message? | |||
:(**@rest, *%rest) | yeah mb | ||
Zephyr | weird, maybe glot.io's API doesn't return anything on timeout/resource overuse | 08:54 | |
I ran that on my repl and it used up all resources pretty quick | |||
:(**@rest, *%rest) | does it overflow stack? | 08:55 | |
Zephyr | all my CPU & RAM was used before it could overflow it seems | 08:56 | |
as it should be known I'm nowhere near fluent in Raku so I'm not sure about the specifics, apologies | 08:57 | ||
08:57
Manifest0 joined
|
|||
:(**@rest, *%rest) | how maybe raku's stack in unbound | 08:58 | |
09:13
dakkar joined
11:07
raschip joined
14:10
m_athias left,
camelia left
14:11
m_athias joined
14:17
camelia joined
|
|||
stevied | I'm trying to get more comfortable with using trait_mod . But I really don't understand the syntax: docs.raku.org/type/Sub#index-entry...eclarator) | 15:11 | |
"It is declared with the trait_mod declarator followed by a colon and a string literal containing the name of the trait. " | |||
so I don't understand what the role of :<is> is for one | 15:15 | ||
Nemokosch | well, it's just a name | 15:16 | |
stevied | name of what? | ||
Nemokosch | the trait | ||
has $!blah is built | |||
there is your is | |||
there is also does | 15:17 | ||
stevied | i always considred "is built" or maybe "built" to be the trait | ||
Nemokosch | technically, it's a dispatch of is | ||
stevied | docs.raku.org/syntax/is | 15:18 | |
"The trait is accepts a type object to be added as a parent class of a class in its definition. " | 15:19 | ||
read that 5 times, still can't figure it out | |||
Nemokosch | also, this is like only one candidate | 15:20 | |
I think this genuinely seems to be a horrible way to say: you can use is to declare the base class of a class | |||
class Array is List | 15:21 | ||
like this | |||
stevied | ok | ||
so I understand a trait adds a hook at compile time | 15:22 | ||
:(**@rest, *%rest) | m: sub trait-mod:<sucks-at>($o, $what) { $o = āI suck at $whatā; } $a sucks-at math; say $a; | ||
Raku eval | Exit code: 1 ===SORRY!=== Error while compiling /home/glot/main.raku Cannot add tokens of category 'trait-mod' at /home/glot/main.raku:1 ------> sub trait-mod:<sucks-at>ā($o, $what) { | ||
:(**@rest, *%rest) | m: sub trait_mod:<sucks-at>($o, $what) { $o = āI suck at $whatā; } $a sucks-at math; say $a; | 15:23 | |
Raku eval | Exit code: 1 ===SORRY!=== Error while compiling /home/glot/main.raku Variable '$a' is not declared at /home/glot/main.raku:5 ------> <BOL>ā$a sucks-at math; | ||
:(**@rest, *%rest) | m: sub trait_mod:<sucks-at>($o, $what) { $o = āI suck at $whatā; } my $a sucks-at math; say $a; | ||
Raku eval | Exit code: 1 ===SORRY!=== Error while compiling /home/glot/main.raku Two terms in a row at /home/glot/main.raku:5 ------> my $aā sucks-at math; expecting any of: infix infix stopper statement end statement modifier statement modifier loop | ||
:(**@rest, *%rest) | what | ||
stevied | os the :<is> part can be called anything? | ||
:(**@rest, *%rest) | trait name | ||
what am i wrong at @Nemokosch | 15:24 | ||
Nemokosch | what did you even change? | 15:27 | |
stevied | i don't think you can just pick any random name to replace <is> | ||
Nemokosch | probably not | ||
but it doesn't help that we see three completely ad-hoc errors for three similar codes | 15:28 | ||
:(**@rest, *%rest) | - i defined a custom trait, now what? - two terms in a row | 15:29 | |
Nemokosch | > Cannot add tokens of category 'trait-mod' | ||
but why the other error | |||
what did you change? | 15:30 | ||
:(**@rest, *%rest) | trait-mod becomes trait_mod | 15:31 | |
and raku only lets you define is does handles i think | |||
Nemokosch | it doesn't say it would be invalid to define a new one, then | 15:32 | |
iirc | 15:33 | ||
15:39
Guest3742 joined,
ab5tract left
|
|||
stevied | ok, so it seems like trait_mod adds in a multi subroutine for the "is" trait | 15:44 | |
Guest3742 | Hi all. I'm trying to pass list literals into a code block: for a, b, c -> @in { ...}, where a b & c are each lists of integers. If I write the lists as "(1, 2, ...)" all's good. If I write the lists as "<1 2 3>" it also works UNLESS the list has exactly one element, in which case I get a type check error: Type check failed in binding to parameter | 15:45 | |
'@in'; expected Positional but got IntStr (IntStr.new(10, "10")) | |||
Is there some way I've missed to handle this case? | |||
stevied | lists are created by commas | ||
so you gotta do "1, " for a one element list | 15:46 | ||
Guest3742 | Hmm ... so no way to use angle quotes here? Ok. Thanks! | 15:47 | |
15:48
ab5tract joined
|
|||
stevied | can't see your function sig but I'm guessing you should be using slurpy args | 15:48 | |
Nemokosch | actually, the parens don't wrap their content at all | ||
(1) also wouldn't be a List | |||
and even though [1] would be an Array, it would be an Array "for the wrong reason" and [[1]] would be the very same Array | 15:49 | ||
what parens tend to do is a kind of conversion | 15:50 | ||
Guest3742 | I did see that [1] works where (1) doesn't. | 15:51 | |
Nemokosch | that's because [] coerces its argument(!) into an Array | 15:52 | |
and for a non-Iterable, that coercion happens to involve wrapping | |||
Guest3742 | I'm working with a list of literal inputs, where it's convenient to write them with <> rather than futzing with all the commas and parens. So it feels weird to have to use different syntax for one element inputs. NBD. | ||
Thanks again | 15:53 | ||
15:53
Guest3742 left
|
|||
Nemokosch | actually, .words would do "the right thing" | 15:53 | |
stevied | m: say <1>.list.WHAT; | 15:54 | |
Raku eval | (List) | ||
Nemokosch | .list would also work I guess | 15:55 | |
I guess the rationale was more or less related to the other parens: what should happen if the argument doesn't look like an array at all? | |||
stevied | m: say <1>.WHAT; | ||
Raku eval | (IntStr) | ||
Nemokosch | if it's the comma that creates the list, one might as well say that it's the separating whitespace for the <> version | 15:56 | |
having said that, I don't know why <foo > (mind the space) can't create a one-element list, at least | |||
having said that... for a, b, c -> @in { ...} looks like a very bad pattern to begin with | 15:58 | ||
16:42
Guest2085 joined
|
|||
stevied | what am I missing here: | 17:06 | |
m: class Circle { multi method new(:$diam) { say 'here' } multi method new(:$radius) { say 'blah' } } Circle.new( radius => 3 ); | |||
Raku eval | here | ||
stevied | why is the first method etting called when I'm passing in "radius" named arg? | ||
i gotta imagine it's the dreated *%_ extra argument slurpy rearing its head | 17:07 | ||
ok, yeah, this works: | 17:09 | ||
m: | |||
m: class Circle { multi method new(:$diam, *% ()) { say 'here' } multi method new(:$radius, *% ()) { say 'blah' } } Circle.new( radius => 3 ); | |||
Raku eval | blah | ||
17:18
snonux joined
17:19
snonux_ joined,
ab5tract left
17:36
dakkar left
|
|||
Nemokosch | @stevied remember to make named arguments mandatory | 17:37 | |
m: class Circle { multi method new(:$diam!) { say 'here' } multi method new(:$radius!) { say 'blah' } } Circle.new( radius => 3 ); | |||
Raku eval | blah | ||
17:49
snonux left
17:50
snonux_ left
18:00
ab5tract joined
18:01
ab5tract left
18:13
Guest3794 joined
18:15
Guest3794 left
18:22
Guest2085 left
|
|||
nHail | Syntax: CStruct representation only handles attributes of type: (u)int8, (u)int16, (u)int32, (u)int64, (u)long, (u)longlong, num32, num64, (s)size_t, bool, Str and types with representation: CArray, CPointer, CStruct, CPPStruct and CUnion But the original c has mpv_event_id event_id;, and mpv_event_id is enum. | 18:23 | |
Nahita | some integer type should do probably int32, enums are integrals. | 19:14 | |
19:17
snonux joined,
snonux_ joined
19:37
Guest2085 joined
19:54
raschip left
20:27
snonux left
20:28
snonux_ left
21:23
snonux joined
21:24
snonux_ joined
21:25
Guest2085 left
|
|||
p6steve | you can use my @a = <1>; since the list assignment will coerce rhs to a list ... | 21:38 | |
Nemokosch | yeah that's like [<1>] | 21:39 | |
p6steve | ^^ that too | 21:41 | |
or '|<1>' maybe | 21:44 | ||
21:44
ab5tract joined
22:17
Guest2085 joined
22:27
Guest2085 left
23:15
ab5tract left
23:54
Manifest0 left
|