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.
deoac Thanks, I'll give it a shot! 00:16
00:39 NemokoschKiwi joined 00:43 NemokoschKiwi left 00:58 Manifest0 left 01:13 deoac left
el gatito (** advocate) ik because python doesn't have the idea of a block scope 01:14
for raku it is less excusable 01:15
given that it has blocks 01:17
how is it intended
Nemokosch no block scope? lol 01:20
mfw everything in Python is var, not even a let
still, I wonder why it would need an "excuse" that something is placed in the block that contains it 01:22
rather than the block that is "inside of it". if they have any hierarchy
01:24 ab5tract left
el gatito (** advocate) like for, loop-declared variables are temporary variables that are only meant to bd inside their scope 01:27
Nemokosch there are no for-declared variables 01:29
correct me if you have ever seen one
el gatito (** advocate) sure
still
my point is that loop init variables should only exist inside their scope 01:30
Nemokosch for the record, I don't know why it is exactly the way it is
but I couldn't say it doesn't make sense
because it is the less magic way
you can parenthesize declarations as much as you wish, that does not create scopes 01:31
and apparently the same goes for loop
el gatito (** advocate) scope not in loop's head == less magic smh 01:32
Nemokosch what is "loop's head" even
el gatito (** advocate) i mean the loop's parameters (my $i = 0; $i < 10; $i++) 01:33
Nemokosch Why would they be special?
el gatito (** advocate) this
Nemokosch m: (my $i = 0; $i < 10; $i++) 01:34
Raku eval WARNINGS for /home/glot/main.raku: Useless use of "<" in expression "$i < 10" in sink context (line 1)
Nemokosch it's valid Raku
I'd say as a play on the "surprisingly consistent" label, this is actually more consistent than surprising 01:35
el gatito (** advocate) no i mean loop (my $i = 0; $i < 10; $i++) # <-- this part of the loop statement { }
not this
Nemokosch and in what block does the loop reside? 01:36
el gatito (** advocate) whatever kind of block it is 01:37
Nemokosch well, think of it the simplest, purest way 01:40
loop takes, say, 3 statements of special meaning, and a block
why would it try to inject variables declared in those statements, into the block?
el gatito (** advocate) i think the solution for now is wrapping in another block 😭
Nemokosch yeah, not like you probably shouldn't be using loop˙in the first place 😒 01:41
el gatito (** advocate) because of C smh most importantly, its because from the perspective of the user, the variable is a loop variable that is discarded after the loop is done 01:43
Nemokosch only if the user is coming from C, honestly
otherwise it's not at all obvious in my opinion that the user would want to discard that variable 01:44
by the same chance the user is using this quirky iteration structure, they might as well want to rely on the value of the variable when the loop terminated, for example 01:47
doesn't sound inferior
by the way, for the better or worse, it seems to me that NOT making an appeal to the C legacy was almost a design principle of this language 01:48
el gatito (** advocate) how about making a more "functional" version of loop lmao smth like scheme's do loop(i => (0, { $_ + 1 }), -> :$i { $i < 10 }, -> :$i { #`(do something here) }) 01:52
yeah it looks kinda complicated tho 01:53
Nemokosch well, something like this can be defined within the language for sure
el gatito (** advocate) but i'd imagine it'll be used for more complicated loop conditions
Nemokosch meh, I'm still mourning the first-pass parsing...
I mean, I can actually imagine that first-pass parsing can work for Python 01:54
because Python has a deliberately very simple grammar
might even be CFG
el gatito (** advocate) with a different name smth like doloop, schemeloop or schemedo
most languages are CFG 01:55
Nemokosch not quite
think of the dangling if's
they cannot be clearly parsed without context
el gatito (** advocate) python isn't tho it has indentation sensitivity
Nemokosch indentation is just white spaces really 01:56
el gatito (** advocate) python's trademark feature is context-sensitive
Nemokosch most lexers discard whitespace, Python's lexer won't
but yeah, as we can see, Raku is also whitespace-sensitive 01:57
because allowing/not allowing whitespace here or there is kinda used for disambiguation
el gatito (** advocate) it relies on tracking previous amounts of indentation more complex than raku "not discarding whitespace bcs they matters"
Nemokosch m: say &&
Raku eval Exit code: 1 Index out of range. Is: 1, should be in 0..0 in block <unit> at main.raku line 1 01:58
Nemokosch oh yeah...
m: say &&
Raku eval 3
Nemokosch because whitespace is disallowed in front of indexing
el gatito (** advocate) even then it is pretty CF at the parser level tho 01:59
Nemokosch If it was up to me, I wouldn't allow duplicate sigils for a term at least
the & variable itself seems kinda useless - but why would anyone "cast" that to a Callable, hence creating &&? 02:00
el gatito (** advocate) who knows
what is the default value of a & variable 02:01
Nemokosch m: say &[&&]
Raku eval ((Any) (Any) (Any))
Nemokosch hmmmm
el gatito (** advocate) (Any)
Nemokosch I did manage to index it, after all!
but what can this array be
m: dd [&[&&]] 02:02
Raku eval [proto sub infix:<&&> (|) {*}]
Nemokosch lol
a one-element array of the operator itself
m: dd & # fyi
Raku eval Callable & = Callable
el gatito (** advocate) m: my &dummy; say &dummy;
Raku eval (Callable)
el gatito (** advocate) the default value is undefined
Nemokosch this reminds me to build the latest main branch state
rakubrew triple 😉 02:03
el gatito (** advocate) $ - Any @ - [] % - {} & - Callable
Nemokosch correct
$ and & itemize, @ and % do not 02:04
I definitely don't like that the default value of @ and % is defined, that's for sure...
el gatito (** advocate) yeah it should be undefined 02:05
mfw multiple undefined values
Nemokosch inb4 yeah yeah I don't know the reason and possible consequences if @ and % would be completely treated as kind of containers 02:06
but I do know quite some issues that would solve
including the infamous (@a, @b) = (@b, @a) disaster 02:07
have you seen that one?
I think I borderline mentioned it
el gatito (** advocate) i think it wouldn't work @a will eat all the elements 02:08
Nemokosch - also, I definitely know cases where something was really merely a design decision, and the reasons were indeed just plain unconvincing
cue "negation lifting", "Failures descend from Nil" 02:09
yes and that can look really funny, you know
you get a recursive array that includes itself, like some black hole
and a plain empty array
el gatito (** advocate) binding saves the day my (@a, @b) := (@b, @a); 02:11
m: my @a; @a.push @a; say @a; 02:12
Raku eval Exit code: 1 ===SORRY!=== Error while compiling /home/glot/main.raku Two terms in a row at /home/glot/main.raku:2 ------> @a.push⏏ @a; expecting any of: infix infix stopper statement end statement modifier statement modifier loop
el gatito (** advocate) bruh
Nemokosch well, it kind of does but you cannot meaningfully bind in all circumstances where you could assign 02:13
el gatito (** advocate) m: my @a; @a.push: @a; say @a;
Raku eval (\Array_4285164213632 = [Array_4285164213632])
el gatito (** advocate) actually i think binding should be the default behavior and assignment should be a perl5ism given the not-so-straightforward semantics of assignment 02:16
its too late to change tho 😔
interesting that gist doesn't return a simpler representation for self-referencing array tha this 02:20
Nemokosch you kinda have a point; not sure what happened during the gist call 02:22
I wanted to object - but then I realized: when I was planning to start a Raku tutorial series, I also wanted to start with sigilless variables and binding only 02:23
a simple, pure functional toolset
it definitely seems like a Perl5ism that there are two assignments, and I don't mean binding 02:24
m: my $foo = 1, 2, 3; my @bar = 1, 2, 3; 02:25
Raku eval WARNINGS for /home/glot/main.raku: Useless use of constant integer 2 in sink context (lines 1, 1) Useless use of constant integer 3 in sink context (lines 1, 1)
Nemokosch it already warns
the former statement drops 2 and 3 because it's interpreted as (my $foo = 1), 2, 3; 02:26
item assignment is tighter than the comma, list assignment is looser
guifa /me has actually run into a handful of circumstances where that tighter item assignment is useful (although it's rare and almost always me trying to be fancy with scoping) 02:46
But I don't think it's a Perl-ism. Perl handled that stuff very differently
Nemokosch Eventually I'll have to take your word for it but the way I say it is a Perlism is a bit abstract. It's rather this context-sensitivity as a principle, not the particular manifestation of it 02:47
the sole idea that a $var would have a different assignment from @var 02:48
guifa yeah, that much is true. Although it's based purely on the sigil in Raku, unlike Perl where … yeah 02:50
take a wild guess what the value of $x is in `@foo = ('a', 'b', 'c'); $x = @foo` in Perl 02:51
el gatito (** advocate) 'a' 02:52
think so
guifa 3 02:53
Nemokosch 😆
guifa OTOH, it's 'a' if you say `($x) = @foo`
Nemokosch I mean... I can imagine that it would start making sense at some point 02:54
guifa There's a logic to it, to be fair. But it's also different from Raku's logic
in Perl, you could return different results from subroutines whether you were in an array or scalar assignment
Nemokosch to be honest, I have mixed feelings about sigils in Raku 02:55
I hear the people saying that it was all an appeal to Perl 5
guifa arrays like @foo were always their length in scalar context
so a quick way to grab the length was to do $@foo
Nemokosch this rings a bell 02:56
guifa But a lot of this was predicated on the way that array/scalar context worked in Perl (neither good nor bad, just different) 02:57
for instance, in a subroutine, you could actually know whether you were being called in an array or scalar context and return a value accordingly!
Nemokosch I'd say the concept of containers (Scalar containers in particular) is great in its essence but the details leave a lot of questions unanswered 02:58
el gatito (** advocate) they say sigils allow you to distinguish between arrays and scalars but idk why that can't be solved with naming $foo = foo @foo = foos 02:59
Nemokosch they can but somebody will say that's just ad-hoc Hungarian notation
guifa I actually have a $pattern and %pattern in the file I'm currently editing 03:00
$pattern = string, %pattern = data from parse
The sigils do two things: adjust assignment/list handling, and signal data role type. if you have a set, I sometimes will also call it as $foo when it's more a singular conceptual unit, and %set when I'm more concerned about the individual units. Neither is more correct than the other (just like `if foo { bar }` is no more correct than `bar if foo`), but Raku is all about allowing those more subtle degrees of 03:04
expressiveness. Obviously, you can write Raku 100% with just the scalar sigil, and even eschew containers by binding all the time
el gatito (** advocate) better than a symbol soup ig actually i still use $foo @foos although i know the s is redundant lol
Nemokosch or just use \vars 😈 03:05
el gatito (** advocate) true but its immutable 03:06
Nemokosch just as much as what you bind it to 🧠
guifa not if you say my \foo = $; ;-)
guifa is afk 03:09
el gatito (** advocate) m: # php moment no strict; multi array(**@args) { @args } $a = array(1, 2, 3, 4); say $a[2]; 03:10
Raku eval Exit code: 1 array *must* be parameterized in block <unit> at main.raku line 6
el gatito (** advocate) :cameliathink: 03:11
m: # php moment no strict; multi array(**@args) { @args } $a := array(1, 2, 3, 4); say $a[2];
Raku eval Exit code: 1 array *must* be parameterized in block <unit> at main.raku line 6
el gatito (** advocate) m: # php moment no strict; sub array(**@args) { @args } $a := array(1, 2, 3, 4); say $a[2]; 03:12
Raku eval Exit code: 1 array *must* be parameterized in block <unit> at main.raku line 6
el gatito (** advocate) why must array be parameterized 03:13
guifa array = native array 03:20
m: my int8 @foo = 1,2,3,4; my array $foo = @foo;
camelia ( no output )
guifa because it's native, it HAS to be typed (hence the demand for parameterization) 03:21
that said, there should probably be some warning about the typename / sub overlap there (and I'd think the locally declare sub would take precedence, but I guess not) 03:22
sub Array($foo) { say "in the sub" }; my $a = Array(1,2,3,4); say $a; # at least it's consistent in this 03:23
m: sub Array($foo) { say "in the sub" }; my $a = Array(1,2,3,4); say $a;
camelia [1 2 3 4]
el gatito (** advocate) m: # php moment no strict; sub array(**@args) { @args } $a := &array(1, 2, 3, 4); say $a[2]; 03:24
Raku eval 3
el gatito (** advocate) adding & works 03:25
& = callable namespace
m: sub modify-my-argument($a) { ++$a } say modify-my-argument(2); 08:19
Raku eval Exit code: 1 Cannot resolve caller prefix:<++>(Int:D); the following candidates match the type but require mutable arguments: (Mu:D $a is rw) (Int:D $a is rw --> Int:D) The following do not match for other reasons: (Bool $a is rw) (Mu:U $a is rw) (Num:D $a is rw) (Num:U $a is rw) (int $a is rw --> int) (num $a is rw --> num) in sub modify-my-argument at main.raku line 2
in block <unit> at main.raku line 5
el gatito (** advocate) m: sub modify-my-argument($a) { $a = 3; $a } say modify-my-argument(2); 08:20
Raku eval Exit code: 1 Cannot assign to a readonly variable or a value in sub modify-my-argument at main.raku line 2 in block <unit> at main.raku line 6
el gatito (** advocate) m: sub modify-my-argument($a) { $a := 3; $a } say modify-my-argument(2);
Raku eval Exit code: 1 ===SORRY!=== Error while compiling /home/glot/main.raku Cannot bind to '$a' because it was bound in a signature and variables bound in signatures cannot be rebound unless they were declared with the 'is rw' or 'is copy' traits at /home/glot/main.raku:2 ------> $a := 3⏏;
el gatito (** advocate) m: sub modify-my-argument($a is copy) { $a := 3; $a } say modify-my-argument(2); 08:22
Raku eval 3
08:54 dakkar joined 09:01 Manifest0 joined
Nemokosch Yeah tbh it could have been suspicious that the name array might cause conflicts 😅 09:09
09:30 ab5tract joined 10:07 ab5tract left 11:39 raschip joined
lizmat and yet another Rakudo Weekly News hits the Net: rakudoweekly.blog/2023/02/06/2023-...en-davies/ 11:53
12:59 ab5tract joined
el gatito (** advocate) m: my \a = Set.new(1, 2, 3); my \b = Set.new(3, 4, 5); say a | b; 13:34
Raku eval any(Set(1 2 3), Set(3 4 5))
el gatito (** advocate) oh yeah its a junction
m: my \a = Set.new(1, 2, 3); my \b = Set.new(3, 4, 5); say a (+) b;
Raku eval Bag(1 2 3(2) 4 5)
el gatito (** advocate) set union = bag 13:35
m: my \a = Set.new(1, 2, 3); my \b = Set.new(3, 4, 5); say a (|) b; 13:36
Raku eval Set(1 2 3 4 5)
el gatito (** advocate) the correct set union
Nemokosch yeah it wasn't "set union" 14:02
more like multiset addition or idk, key addition 14:03
*value
14:20 NemokoschKiwi joined 14:35 NemokoschKiwi left 17:39 dakkar left 18:45 gfldex left, gfldex joined 20:57 raschip left 21:47 rf_ joined 21:56 ab5tract left, rf left 21:57 ab5tract joined 22:32 ab5tract left 23:02 stevied_test left, stevied_test joined