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
rf joined
00:48
Manifest0 left
|
|||
rf | Is there a good example anywhere of adding attributes to a class via meta programming? | 01:03 | |
lucs | (Might as well ask this here, I feel like a beginner not knowing how to do this.) : sub foo ($a, $b) { $a + $b } my @c = [1, 2]; say foo(@c); # What should that 「@c」 be (expecting "3" as output)? | 01:04 | |
rf | try |@c | 01:07 | |
foo(|@c); | |||
could also do sub foo(($a, $b)) ... notice the double parens | |||
But that will change signature of foo to take a positional | |||
lucs | The prefix "|". sigh I knew that, but I forgot. | 01:10 | |
My memory is not improving with age, wouldn't you know. | 01:11 | ||
rf | Lol, it's called the slip operator it's fairly useful :D | 01:12 | |
lucs | Well, thanks 🙂 | 01:14 | |
02:07
rf left
02:10
rf joined
03:06
rf_ joined
03:15
rf left,
saint- left
03:27
saint- joined
05:29
Heptite left
|
|||
el gatito (** advocate) | m: sub fibonacci($n) { state @fib = 0, 1, ->($i, $j) { $i + $j } ... Inf; @fib[$n] } say fibonacci(10); | 08:27 | |
Raku eval | Exit code: 1 Cannot unpack or Capture `1`. To create a Capture, add parentheses: \(...) If unpacking in a signature, perhaps you needlessly used parentheses? -> ($x) {} vs. -> $x {} or missed `:` in signature unpacking? -> &c:(Int) {} in sub fibonacci at main.raku line 2 in block <unit> at main.raku line 6 | ||
el gatito (** advocate) | m: sub fibonacci($n) { state @fib = (0, 1, ->($i, $j) { $i + $j } ... Inf); @fib[$n] } say fibonacci(10); | 08:28 | |
Raku eval | Exit code: 1 Cannot unpack or Capture `1`. To create a Capture, add parentheses: \(...) If unpacking in a signature, perhaps you needlessly used parentheses? -> ($x) {} vs. -> $x {} or missed `:` in signature unpacking? -> &c:(Int) {} in sub fibonacci at main.raku line 2 in block <unit> at main.raku line 6 | ||
el gatito (** advocate) | m: sub fibonacci($n) { state @fib = (0, 1, -> $i, $j { $i + $j } ... Inf); @fib[$n] } say fibonacci(10); | ||
Raku eval | 55 | ||
el gatito (** advocate) | why are parens not allowed hmm | 08:29 | |
Nemokosch | Because they imply a subsignature I guess | 08:31 | |
el gatito (** advocate) | in this case they shouldn't bcs there is no space | 08:32 | |
Nemokosch | Well I'm surprised it even compiled | 08:34 | |
By the way, maybe you know now who jnthn is 😛 | |||
el gatito (** advocate) | who? | 08:35 | |
Nemokosch | Well you complained that nobody responds to your issue on github | 08:36 | |
el gatito (** advocate) | oh i checked | 08:37 | |
oh he gave a response to that | 08:39 | ||
basically my ($first, $second) := (1, 2); becomes my ($first, $second); :($first, $second) := (1, 2); | 08:45 | ||
08:55
Manifest0 joined
|
|||
still its surprising that lists cannot be used as destructuring patterns | 09:01 | ||
09:07
dakkar joined
|
|||
Nemokosch | Lists aren't very well suited for describing a shape of something in Raku | 09:08 | |
One reason for that is that the parens don't tell anything about the shape, they just indicate evaluation order | 09:09 | ||
So writing ((1, 2)) is like writing ((1 + 2)) | 09:10 | ||
It looks funky but the extra pair of parens will never do anything | |||
09:25
human-blip joined
|
|||
el gatito (** advocate) | ((1, 2),) | 09:57 | |
11:37
CIAvash left
11:41
CIAvash joined
12:14
CIAvash left
12:37
rf_ left,
rf joined
12:48
CIAvash joined
13:29
Heptite joined
15:16
human-blip left,
human-blip joined
16:22
zashi joined
|
|||
zashi | Hi. How can I include/use/require another raku file that is just sitting besides my current running raku script in the same folder? I've managed to build a module but this is not what I want.. | 16:27 | |
Skarsnik | raku -I . myscrip.raku ? | 16:43 | |
17:30
NemokoschKiwi joined
17:43
dakkar left
18:10
saint- left
18:12
Guest244 joined
18:15
ab5tract left
18:16
NemokoschKiwi left
18:18
Guest244 left
|
|||
rf | Zashi, you can use raku -I. myscript.raku or look into using Mi6 | 18:32 | |
Nemokosch | a .raku file is meant to be run, a .rakumod file is meant to be imported | 18:34 | |
you can tweak it but it will be a tweak at best if you don't follow this principle | |||
p6steve | or you can put this in your script: | 18:35 | |
use lib '.'; use MyModuleName; and in the module unit module MyModuleName; | 18:37 | ||
19:59
Guest5607 joined
|
|||
zashi | use lib "{$*PROGRAM.parent}"; | 20:03 | |
use MyModuleName; | |||
this works ^^ I don't even need unit module MyModuleName.... and it imports everything exported in that file in the current namespace | |||
previous answer on another channel was | 20:05 | ||
require "./MyModule.rakumod" <&hello>; | |||
but it has the serious disadvantage that I have to specifically name what I want to import, and it's a block import so I have to call by &hello() | |||
thanks!!! | |||
Guest5607 | Is there a way to check if an inputted value is an Int? | 20:08 | |
Nahita | you can attempt to coerce to Int and see if it fails maybe | 20:17 | |
$inp.Int ?? "looks like integer" !! "no" | |||
there's a regex way too like / ^^ '-'? \d+ $$ / but .Int is better i guess | 20:18 | ||
Nemokosch | depends on the way to obtain the input as well - prompt attempts to create allomorphs, so if somebody enters a number, that would be received as an IntStr | 20:20 | |
(which I absolutely hate but that's beside the point) | |||
in that case, you could really just check if the value descends from Int, with a smartmatch | 20:21 | ||
zashi | so maybe a stupid question, but ... so rakudo is the compiler of raku which compiles to backend, right? Is there any way to get info at runtime/compile time which backend rakudo is using? | 20:36 | |
I suspect it's moarvm since when I install rakudo I can see it also installs other packages including moarvm | 20:40 | ||
20:43
Simerax joined
|
|||
Simerax | anyone around who could maybe help me with clearing up some confusion i have about `react`? | 20:43 | |
Nemokosch | zashi: simplest case, rakudo -v will tell you | 20:44 | |
but there is also | 20:46 | ||
m: $*RAKU.compiler.backend.say | |||
Raku eval | moar | ||
Nemokosch | Simerax: react is a complex thing - but in the nature of "don't ask to ask", you're never gonna get help unless you actually say what you need help with 😉 | 20:47 | |
I definitely can't promise that I will know the answer - but someone will, and that someone might be around | 20:48 | ||
zashi: one more thing. MoarVM is, one could say, the main implementation. The one that was designed with this language in mind, written in C. | 20:50 | ||
the "JVM" backend is a bit misleading because for all intents and purposes the runtime isn't the JVM - it's a runtime running on JVM | 20:51 | ||
Simerax | well im a little confused on how it works exactly. im familiar with go and it's "select" statement so i thought about react being kind of similar but i don't quite understand under which conditions it blocks and when not. for example here in this code: pastebin.com/n8cXq9Bz react does receive 1 message on each channel but then continues | ||
execution after the react statement even though the blocks inside say "whenever" | |||
Nemokosch | so saying "the backend is JVM" is a bit like saying "the backend is C" or "the backend is native", in the case of MoarVM | ||
Simerax | so i thought "react whenever" is kind of like go's for { select {} } | 20:52 | |
i expected it to block forever (and deadlock in this case) and keep reading messages forever | 20:54 | ||
Nemokosch | I don't know go's for { select {} } (and fwiw my monthly dose of go language I can take is over, lol) | ||
Simerax | well i just thought it might clear up where my mind is coming from :P | 20:55 | |
Nemokosch | well indeed it might, for somebody who knows Go 🙂 | 20:56 | |
one thing I surely know is that react is started immediately, wherever it is, unlike supply | 20:57 | ||
Simerax | the basic question (in my example pastebin) is if i don't call send on $c1 and $c2 react blocks forever (which i think is correct) but then it stops blocking as soon as it received 1 message per "whenever" case. my expectation was "whenever" would block for (possibly) multiple messages | 20:58 | |
how could i achieve it to keep blocking/waiting for more messages on a channel? | |||
i know in my example it would deadlock then | |||
21:00
NemokoschKiwi joined
21:01
NemokoschKiwi left
|
|||
Nemokosch | I get your point, tbh I barely ever used these async structures | 21:03 | |
Simerax | okay no worries :) | 21:04 | |
Nemokosch | there is this monstrous description on the doc site: docs.raku.org/language/concurrency | 21:05 | |
Simerax | im currently going through that :) | 21:07 | |
21:15
systems joined
|
|||
Simerax | okay i fixed it my logic flaw was that i wrote "whenever $c1.receive" instead of "whenever $c1" now it does what i expected :) | 21:16 | |
Nemokosch | oops gotcha | 21:21 | |
lol | |||
zashi | Nemokosch: | 21:39 | |
thank you! | |||
also "it's a runtime running on JVM".. well, it still runs on JVM with extra stuff in between which I guess is required unless you really really wanna make the compiler either too locked in on the JVM or very complicated... | |||
Welcome to Rakudo™ v2022.07. | |||
Implementing the Raku® Programming Language v6.d. | |||
Built on MoarVM version 2022.07. | |||
Nemokosch: | |||
thank you! | |||
also "it's a runtime running on JVM".. well, it still runs on JVM with extra stuff in between which I guess is required unless you really really wanna make the compiler either too locked in on the JVM or very complicated... | |||
- / # raku -v | |||
Welcome to Rakudo™ v2022.07. | |||
Implementing the Raku® Programming Language v6.d. | |||
Built on MoarVM version 2022.07. | |||
21:40
Guest5607 left
|
|||
Simerax | where can i read the source code of the standard library? for example if i want to look at the implementation of IO::Socket::INET | 22:57 | |
elcaro | github.com/rakudo/rakudo/tree/main/src | 22:59 | |
Most will be under `core.c` | |||
Simerax | thanks! | 23:00 | |
elcaro | things added/modified under .d or .e will be under `core.d` or `core.e` | ||
23:00
zashi left
|
|||
elcaro | be warned tho that a lot of the stdlib is written in NQP | 23:01 | |
Simerax | what do you mean by "modified under .d or .e"? what is .d or .e? im very new to raku | ||
elcaro | Ahh, they are major versions | 23:02 | |
Simerax | ah okay :D | ||
elcaro | so .c was the first major release. .d is the current one. .e will be the next | ||
You are likely using .d, which users the stdlib defined under core.c, as well as any modification under core.d | 23:03 | ||
Simerax | ah okay interesting! well i just want to understand a little how the IO::Socket role works and you can't really find that out without seeing its source | ||
Nemokosch | Simerax: if you have a particular call in mind, I like CoreHackers::Sourcery; it doesn't always work well on roles directly, though (because method lookup is a bit different) | 23:10 | |
Simerax | ill have a look at it! | 23:12 | |
23:28
Simerax left
23:55
systems left
|