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:08 deoac joined 00:12 deoac left 01:35 habere-et-disper left 03:23 rf left 04:23 Heptite left 06:22 jacob37 joined 06:25 jacob37 left 06:47 tea3po left 06:48 tea3po joined 06:49 tea3po left, tea3po joined 06:50 tea3po left 06:51 tea3po joined 09:10 dakkar joined 11:10 dakkar left 11:12 dakkar joined
lizmat and yet another Rakudo Weekly News hit the Net: rakudoweekly.blog/2023/03/13/2023-11-ainions/ (yesterday already :-) 14:10
15:17 rf joined 17:05 Heptite joined 17:37 dakkar left 18:40 ToddAndMargo joined
ToddAndMargo regex question.  in the following string "1.2.3.4" where only the dots are consistent and the numbers will vary, how do I  locate the last dot and delete the dot and everything after it? 18:43
This is what I have so far: 18:47
$x="1.2.3.4"; $x~~s/  (.*) $( Q[.] )  /Z/; print $0 ~"\n"; print "$x\n";
1.2.3
Z4
it works, but it is ugly
Have not figured ot how to use "$" to mean the end of the line 18:49
18:50 teatwo joined 18:53 tea3po left
Nahita $s.subst(/ '.' <-[.]>* $$/) is an alternative; it matches a literal dot, followed by anything-but-dot 0 or more times until the end of a line 19:16
$$ marks end-of-line, $ does end-of-string
second argument-less .subst removes what matches, so the last dot and what's after it till the end are gone 19:17
19:18 jgaz joined
the anything-but-dot there helps pinpoint the last dot 19:18
Nemokosch > Have not figured ot how to use "$" to mean the end of the line 19:19
whitespace would help here; $() specifically means "make a Scalar value of it"
19:33 yoreei joined
ToddAndMargo Is there any way to just drop the ` $x~~s/  (.*) $( Q[.] )  /Z/` and grab $0 without first assigning the `s/` to $x? 19:39
20:03 sivoais left 20:16 yoreei left
Nahita well after removing things, what's left is equivalent to $0.Str, no? so $x.subst(/ '.' <-[.]>* $$/) 20:18
or you can match the other part with $x.match(/ .* <?before '.'> /) 20:19
that gives a match object
ToddAndMargo actually I meant with a regex 20:22
Nemokosch these are all regexes
ToddAndMargo Thank you! 20:24
20:30 yoreei joined
ToddAndMargo Found a pretty way! 20:35
my $x="1.2.3.4"; S/ (.*) $( Q[.] ) // given $x; print $0 ~ "\n";
1.2.3
yoreei Hello, I was wondering why specifying a type constraint breaks the following code snippet: 20:39
$_="a,b,c,d";
dd split(',',$_);                 #("a", "b", "c", "d").Seq
my @A=split(',',$_);
dd @A;                           #Array @A = ["a", "b", "c", "d"]
my Array @A2=split(',',$_);
dd @A2;                         #Type check failed for an element of @A2; expected Array but got Str ("a")
                                       # in block <unit> at ./raku.raku line 194
For @A, the Seq is eagered into an Array, but not for @A2. I would have expected that it works in both cases
The error message is also a bit strange. It looks as if it's trying to give only the first element of the Seq to @A2
Can anybody help me make sense of this?
Nemokosch Array @something means an Array whose elements are... Arrays 20:43
m: Array @foo; say @foo.WHAT; 20:44
Raku eval Exit code: 1 ===SORRY!=== Error while compiling /home/glot/main.raku Two terms in a row at /home/glot/main.raku:1 ------> Array⏏ @foo; say @foo.WHAT; expecting any of: infix infix stopper statement end statement modifier statement modifier loop
Nemokosch oops
m: my Array @foo; say @foo.WHAT;
Raku eval (Array[Array])
Nemokosch if you want to specify the type constraint on the symbol itself, use the is trait 20:45
m: my @foo is List; say @foo.WHAT;
Raku eval (List)
yoreei That's interesting. I am reading Learning Perl 6 and they have some examples like: 20:52
    my Int $number;
    $number = 137;
    $number = 'Hamadryas';  # NOPE! Error
So Int here describes the type that the container $number holds, the same way Array described what the array A2 holds?
20:52 ToddAndMargo left
Nemokosch in this analogy, "the array A2" holds multiple things, it doesn't have an identity on its own 20:54
its elements have identities each
actually, you cannot even set a default value for the array - you can set a default value for an individual element of it 20:55
m: my @foo is default(42); say ++@foo[22];
Raku eval 43
yoreei Thanks, Nemokosch, things are clearer now :) 21:00
21:01 jgaz left
Nemokosch no problem, and keep it up ^^ 21:02
21:03 sivoais joined 21:22 yoreei left 21:59 Heptite left 22:31 elcaro left