This channel is intended for people just starting with the Raku Programming Language ( Logs are available at
Set by lizmat on 8 June 2022.
00:09 jgaz joined 00:12 jgaz left 01:29 razetime joined 02:52 frost66 joined 03:14 frost66 left 03:49 deoac joined
deoac my $foo = 1; BEGIN { say $foo; } 03:52
#OUTPUT: (Any)
kjp Because the "$foo = 1" isn't executed until run time, and the code in the BEGIN block is run at compile time. 03:59
04:00 razetime left 04:39 razetime joined
deoac Yet, `say $food` throws an error, not (Any). So BEGIN knows about $foo. 04:59
And `sub foo {say 'Hello'};  BEGIN { foo; };`  prints `Hello` 05:01
so why isn't the assignment recognized?
05:06 Heptite left 05:14 deoac left 05:37 Kaipei joined 05:41 Kaiepi left
Nemokosch I think the reasoning by kjp was legit 06:41
m: constant $foo = 1; BEGIN { say $foo; } # constant is evaluated at compile time 06:43
Just because something is visually one line, it doesn't necessarily mean it is executed all at once, confer Javascript `var`s... 06:45
m: BEGIN { say $foo; }; my $foo = 1;
by the way, your subroutine example doesn't work for me 06:47
m: sub foo {say 'Hello'}; BEGIN { foo; };
lizmat deoc: only the assignment is runtime, the declaration of $foo is also compile time
Nemokosch I can imagine this depends on the way of compilation; it definitely doesn't work for me with `raku -e`
lizmat that's why the $foo is known inside the BEGIN 06:48
Nemokosch I think it's good to clarify that BEGIN is not something you often need. Ironically, it's not a beginner thing 06:51
m: my \foo = 1; BEGIN { say foo; } 07:03
lizmat m: my \foo = 1; BEGIN { say foo; } 07:06
camelia (Mu)
lizmat the reason that shows Mu is that when you declare a variable, it gets declared with a Scalar container already in it 07:07
Nemokosch I was curious about terms because they are bound at declaration 07:10
08:16 razetime left 08:40 razetime joined 08:42 razetime left, razetime joined 10:14 arthur joined, arthur left 13:32 jgaz joined 14:27 jgaz left 14:54 Heptite joined 15:05 samebchase- left 15:31 kueppo joined 17:19 kueppo left 17:41 Manifest0 left 17:43 Manifest0 joined 18:31 jgaz joined 18:50 razetime left 19:43 jgaz left 19:54 jgaz joined 20:01 Kaipei left 21:11 [Coke]___ is now known as [Coke] 21:17 Kaipei joined 21:52 jgaz left 22:00 [Coke]_ joined 22:03 [Coke] left 22:34 [Coke]_ is now known as [Coke]