This channel is intended for people just starting with the Raku Programming Language ( Logs are available at
Set by lizmat on 8 June 2022.
05:10 KOTP left 09:08 dakkar joined 12:20 dano joined
dano Hi, how would I count the number of tab characters at the beginning of a string? 12:20
I wrote a pretty straighforward implementation of a sub that does this but I had surprising trouble 12:22
I would have thought something like this would work
nemokosch m: my $str = "\t" x 8 ~ 'blasda' ~ "\t" x 10; $str.match(/^ <( \t * )> /).chars.say 12:23
Raku eval 8
nemokosch that's one way
dano my Int $counter = 0; for 0..$str.chars() { last if not ($str[$_] eq '\t'); ++$counter; } return $counter; 12:24
nemokosch m: my $str = "\t" x 8 ~ 'blasda' ~ "\t" x 10; $str.comb.toggle(* eq "\t").elems.say 12:25
Raku eval 8
nemokosch I think this should also work
checking yours 12:26
oh yeah, indexing won't work on strings 12:27
at least not in any sensible way
dano Yeah, I noticed that
nemokosch m: my $str = "\t" x 8 ~ 'blasda' ~ "\t" x 10; $str[0].say; $str[1].say
Raku eval blasda Exit code: 1 Index out of range. Is: 1, should be in 0..0 in block <unit> at main.raku line 1
nemokosch okay, so what is your question? 12:28
rcmlz m: my $str = "\t" x 8 ~ "blasda" ~ "\t" x 10; dd $str.comb[0,1,8..12] 12:57
Raku eval ("\t", "\t", ("b", "l", "a", "s", "d"))
lizmat m: my $s = "\t\t\t\tfoo\t"; say +$s.comb.grep({ $_ eq "\t" || last }) 12:59
camelia 4
lizmat m: my $s = "\t\t\t\tfoo\t"; say ($s ~~ /^ \t* /).chars 13:14
camelia 4
lizmat the regex solution is more efficient 13:15
dano Is there a simple procedural way to do it? Regex seems like overkill 13:20
13:21 KOTP joined
dano And in any case, is there a way to access characters in a string? Assuming it is all ascii in the 0-127 range 13:21
lizmat dano: to access all chars separately, use .comb 13:22
it creates a Seq of all characters, whether they'd be ASCII or not 13:23
dano Ok, I will have a look, thanks 13:24
What does :D mean in a function argument signature? E.g. sub comb(Str:D $matcher)
nemokosch DEFINITE, so basically a real value of that type 13:35
In Raku, types are also instances, and they are... their own type? if that makes sense 13:36
m: 'almafa'.WHAT.say; Str.WHAT.say;
Raku eval (Str) (Str)
nemokosch the difference is that the former is an Str:D (a DEFINITE value of Str) 13:37
and the latter is an Str:U (well, not a DEFINITE value of Str)
so the signature of comb says that type objects are not welcome, they cannot be combed 13:38
m: comb(IntStr)
Raku eval Exit code: 1 ===SORRY!=== Error while compiling main.raku Calling comb(IntStr) will never work with signature of the proto ($, $, $?, *%) at main.raku:1 ------> <BOL>⏏comb(IntStr)
13:43 KOTP left
dano Doea Raku have tail call optimisation? 13:48
Thanks for the :D explanation, I understand 13:49
nemokosch This is an implementation detail that I wouldn't know 14:01 this is from 2020 14:02 this one states that MoarVM does have tail-call optimization but honestly I'm not sure Thibault Duponchelle would know 14:04 14:05
in any case, there should be unified communication
dano Thanks 15:07
How can I declare the type of an array of Int? 16:41
For just an Int it would be my Int $i = 0;
lizmat my Int @foo
dano Ah, very nice 16:42
lizmat m: my Int @foo = 1,2,3; dd @foo
camelia Int @foo = Array[Int].new(1, 2, 3)
lizmat m: my Int @foo = 1,2,3,"bar"; dd @foo
camelia Type check failed for an element of @foo; expected Int but got Str ("bar")
in block <unit> at <tmp> line 1
dano Thanks
What do you guys like about Raku?
antononcube @dano That it is very user friendly and it very carefully picks its friends. 16:49
.vushu What I like about Raku is that it is very pragmatic, you can get things done quickly, it has quite unique feature sets. I like the builtin grammar and multiple dispatch where you also can define conditions for those given function which I find pretty cool and there always more to explorer which is fun 😄 17:11
17:33 dakkar left
nemokosch if I were to think of a praising word for Raku, I would say that it's an inspiring language 17:55
you can make it into a lot of things, and you definitely learn about languages, paradigms, algorithms and all that, while you might stay in flow for a long time
having said that, I think it crucially determines your Raku experience what your expectations are or what you are trying to use it for 17:56
dano Thank you for your answers! 18:01
I'm not sure what I'm looking for. I have used Java and C++ professionally for years with some Python for scripting. Over the last year I have taken an interest in other languages and learnt OCaml and Scheme for the functional programming, and now I am learning Raku. 18:28
I suppose I would use it for whatever I would use Python for, scripts and such. My first program is going to take a configuration file and some template files and generate a C++ codebase skeleton 18:33
lizmat sounds like a useful tool to have 18:37
and fun to make :-) 18:42
dano Raku seems like a great language for this. I have only used it for one day, but it seems like it gets a lot of work done in few lines. It has a quirky and fun feeling to it 18:52
It's like a language for intelligent hipsters with good taste and a sense of humor 18:56
.vushu hipster 😂 19:00
antononcube Intelligent hamsters though, stay away grom rakuns 19:11
@dano I actually use Raku a lot for LLM related projects. Work-wise. 19:12
I mean work projects.
nemokosch It makes sense 19:14
dano Nice! 19:22