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:09 lizmat joined 01:53 frost joined 06:00 kjp left 06:07 kjp joined 06:08 kjp left 06:09 kjp joined 06:55 frost left 07:38 discord-raku-bot left, discord-raku-bot joined 09:07 Kaipei joined 09:11 Kaiepi left 09:12 frost joined 12:15 m_athias left 12:16 m_athias joined 12:52 Kaipei left 13:04 frost left 13:06 frost joined 13:27 Kaipei joined 13:38 Kaipei left 13:39 Kaipei joined 13:41 Kaipei left 13:42 Kaipei joined 14:01 jgaz joined
yabobay m: my $a = "this"; say $a[0]; 14:05
Nemokosch it's `this`
dang
yabobay what's the function to get the character at a specific index of a string
Nemokosch I admit I'm not completely sure if there is something like that xD 14:07
yabobay docs.raku.org/type/Str
14:07 Kaiepi joined
Nemokosch but you can use substr, or .comb a string into a sequence of characters when not specifying an argument 14:07
yabobay i've been looking at this page for MINUTES
14:08 Kaipei left, Kaiepi left
Nemokosch m: my $a = "this"; say $a.comb[0]; 14:08
m: my $a = "this"; $a.substr-rw(0, 1) = 'w'; say $a; 14:09
14:09 Kaiepi joined
yabobay whis 14:11
Nemokosch what do you think?
yabobay yeah i just wrote the function myself
but it feels weird that this doesn't exist?
Nemokosch perhaps it does
almost as if it was boycotted 14:12
yabobay ? 14:13
Nemokosch what is the question?
yabobay what does this mean?
Nemokosch I don't know if there is a more concise way to say this
yabobay m: my $a = "this"; $a.substr-rw(0, 1) = 'w'; say "i'm gonna take a $a;"
what was boycotted? 14:14
Nemokosch the same thing that doesn't exist? 14:15
yabobay if it doesn't exist then who boycotted it
Nemokosch apparently everyone who could have created it 14:16
idk if this is the right question tbh 14:17
yabobay either i don't know what the word boycott means or you don't know what it means
Nemokosch > to refuse to buy a product or take part in an activity as a way of expressing strong disapproval: 14:18
I think it's clearly understandable
yabobay yeah but that means a product that already exists 14:20
like
if they did add this function to raku, and then people stopped using it
Nemokosch not necessarily
yabobay not making a product isn't boycotting it
Nemokosch > take part in an activity
it's not that difficult really
Rog Semantic argument detected šŸ˜† 14:22
This will lead nowhere
Nemokosch I mean... yes?
yabobay even if you're technically correct, it doesn't make sense to use the word this way
Nemokosch I think it was fine, and you did understand it
yabobay i didn't
that's why i had to ask you what you were talking about
Nemokosch What really doesn't make sense is to split hairs over something that is well understandable
Then I'm gonna say you had a too limited concept of boycotting in mind šŸ¤·
Rog The reason Raku doesnā€™t have string indexing like, say, Python is that we donā€™t want people thinking of strings as mere character arrays
Thereā€™s a lot more complexity to it with unicode
14:23 frost left
yabobay well yes, but having a function for it would be nice 14:24
Rog If you want a character array, youā€™re looking for .comb
Itā€™ll do what you expect
Nemokosch the weird thing is rather the "everything can be a one-element array" nonsense
that you apparently _can_ call postcircumfix [] and it will do something... that you never want
yabobay ohhh i just did the comb thing
that syntactically looks exactly almost right
Nemokosch the other weird-ish thing is that you can even mutate strings with substr-rw, yet you cannot have a direct character access method 14:26
(not slightly as weird as the "everything is a fake array" principle though)
Rog This being how it is is good for various deeper reasons that itā€™s too early in the morning for me to enumerate but the behavior of using indexing on a scalar and getting backā€¦ the scalar is a bit bad
Nemokosch This is clearly something that isn't going away
It just goes to my list of "not sure why someone thought it would be good to build around something like this" 14:28
Like "Failure is Nil" surely
Rog It might be good to have some king of compiler warning if you do something that is almost certainly mistaken
It might be good to have some kind of compiler warning if you do something that is almost certainly mistaken
Like the simplified example above
Nemokosch well it's better than nothing 14:29
tbh I'll have to wait until I'm knowledgeable enough to participate in development 14:30
because there isn't much point in complaining about stuff that 100% no developer would care reworking
On the other hand, I feel that pretending certain stuff is just good the way it is would also be a "radical measure" in the other direction 14:32
elcaro You have direct access with `substr`. I don't know why you we're shown `substr-rw` first. 15:47
```
[0] > 'selection'.substr(4, 1)
c
[1] > 'selection'.substr(1, 5)
elect
[2] > 'selection'.substr(*-2)
on
```
There's also raku.land/zef:raku-community-modul...honic::Str if you like 15:48
m: .substr(.index('.') + 1) given 'filename.txt' 15:51
m: say .substr(.index('.') + 1) given 'filename.txt'
Nemokosch I mean, yes bruh, with a dummy argument for the size 15:53
elcaro I don't follow. Are you referring to the first example, with `(4, 1)`? 15:55
Nemokosch however it's anything but elegant to retrieve a substring if all you wanted was one character
elcaro It depends on your definition of elegant. A character is a substring. It doesn't get special treatment. Raku's design has at times tried to provide generalised functions that cover multiple uses, rather than multiple specialised slightly overlapping functions. Yes, this isn't always the case. 15:57
`substr` is elegant in that it covers all your sub-stringing requirements, whether they be fore single characters or more.
but I admit, it's more _verbose_ than you may like. in which case, `Pythonic::Str` is a reasonable option, particularly for use in WhateverCode 15:59
eg.
`my $acronym = @words.map(*[0]).join`
is terser than
`my $acronym = @words.map(*.sustr(0, 1)).join`
Nemokosch well, let me ask: what do strings consist of?
elcaro I get that
In raku, a string is a single thing.... a _scalar_ 16:01
that's how I perceive it.
Nemokosch that's like avoiding the question 16:02
"how do you explain" lexical ordering, for example? 16:03
elcaro there's no good answer that satisfies everyone... although I think maybe the Raku-ish answer is "grapheme clusters"
`substr` is elegant in that it covers all your sub-stringing requirements, whether they be for single characters or more. 16:08
Just to be clear, that was in response to "what do strings consist of". 16:22
Once again, it's late for me and I need to go to bed.
I hope I don't sound like I'm being indifferent, facetious, or antagonistic... that's not my intent. Raku has things that annoy me, we covered this ground the other day. The good outweighs the bad... and I appreciate that doesn't mean you always accept the status quo.
Lastly, Raku did not form in a void... a lot of early decisions where made when it was called "Perl 6". In good ol' Perl 5... `substr` is the way to get a character, eg:
```
0> substr('selection', 4, 1)
$res[0] = 'c'
```
I'm sure it was probably added to Perl 6 very early on, and everyone just went with it without a second thought. It may not be a good justification for everyone... but it's justifiable.
Just to be clear, that was in response to "what do strings consist of".
Once again, it's late for me and I need to go to bed.
I hope I don't sound like I'm being indifferent, facetious, or antagonistic... that's not my intent. Raku has things that annoy me, we covered this ground the other day. The good outweighs the bad... and I appreciate that doesn't mean you always accept the status quo.
Lastly, Raku did not form in a void... a lot of early decisions where made when it was called "Perl 6". In good ol' Perl 5... `substr` is the way to get a character, eg:
```
0> substr('selection', 4, 1)
$res[0] = 'c'
```
I'm sure it was probably added to Perl 6 very early on, and everyone just went with it without a second thought. That may not be a good justification for everyone... but it's justifiable.
Just to be clear, that was in response to "what do strings consist of".
Once again, it's late for me and I need to go to bed.
I hope I don't sound like I'm being indifferent, facetious, or antagonistic... that's not my intent. Raku has things that annoy me, we covered this ground the other day. The good outweighs the bad... and I appreciate that that doesn't mean you always accept the status quo.
Lastly, Raku did not form in a void... a lot of early decisions where made when it was called "Perl 6". In good ol' Perl 5... `substr` is the way to get a character, eg:
```
0> substr('selection', 4, 1)
$res[0] = 'c'
```
I'm sure it was probably added to Perl 6 very early on, and everyone just went with it without a second thought. That may not be a good justification for everyone... but it's justifiable.
Nemokosch No no, it's fine. Too early for Rog, too late for elcaro, this planet really is too big šŸ˜„ 16:24
elcaro I often wish I didn't need sleep. Could get so much done!
Nemokosch Also I don't have anything against substr, I'm just saying that getting _one character_, as a unit of its own, from a string, makes sense as a thing per se
and it seems too obvious to accidentally forget so I wouldn't be surprised if there were some principles that kept the "character-exclusive" method out 16:26
good night anyway šŸ˜„ 16:28
elcaro Goodnight
gfldex <@297037173541175296> You Sir, are wrong. Raku is not a finalised language. It is a base you are required to start from to build the language you need for the project at hand. Granted, the support for slangs is very lacking right now. I hope this, and a few other things, will be solved with RakuAST. If you need to treat strings as `Positional`s you are free to do so. 17:02
m:```
multi postcircumfix:<[ ]>(Str:D $s, Int:D $idx) {
return substr($idx, 1)
}
multi postcircumfix:<[ ]>(Str:D $s is rw, Int:D $idx, Str:D $store) {
$s.substr-rw($idx, 1) = 'z';
$s
}
multi postcircumfix:<[ ]>(Str:D $s is rw, @idx) {
my @retval;
@retval.push($s.substr($_, 1)) for @idx;
@retval
}
multi postcircumfix:<[ ]>(Str:D $s is rw, @idx, @store) {
for @idx Z @store -> [$i, $c] {
$s.substr-rw($i, 1) = $c
}
}
# sub postcircumfix:<[ ]>(|c) {
# dd c;
yabobay i didn't know that was the philosophy in raku 17:03
does this differ from perl? i don't know a thing about either
gfldex Well, with Perl5 it wasn't really planned to be that way. But giving direct access to the symbol table, will lead to custom syntax eventually. 17:05
yabobay but with raku, it's designed with that in mind?
gfldex With Raku, that was the plan. That's why you can "subclass" a grammar and `augment` a class.
Rakudo is using that flexibility to implement language versions. 17:07
yabobay i don't like the idea of using that for some reason
gfldex see: github.com/rakudo/rakudo/blob/mast...Supply.pm6 17:08
Raku aims to be a 100-year language. To be that it needs to be able to change and allow to get rid of cruft or bad design ideas. 17:09
yabobay no i like the fact that raku is implemented in raku
but the fact that *im* supposed to extend it in order to use it?
gfldex Well, you don't have to if you don't want to. And quite often you don't need to. But if the language designer demands that of you, the designer has to give you the tools to do so. That is hard! What might be the reason why most other languages avoid it. 17:13
Nemokosch because it wasn't most probably 17:15
this is just back-rationalization imo
gfldex That you might want to watch the interviews with Larry.
Nemokosch Raku is not Racket, it just happened to develop in a way that allowed for more and more to be done within it 17:16
And I'd have to say if the idea was to create a meta-language, then Raku isn't doing that well
I also read memorials when Perl6 still wasn't publishable, mind you 17:17
from Carl MƤsak
and from that, I took that the whole self-parsing was rather a clever implementation trick _for Rakudo_ 17:18
that started living its own life
besides, for this concrete scenario: I really see no way to explain why we require a built-in "polymod" method on Int, but not direct character accessing for Str. Other than deliberately staying away from adding the latter. 17:22
gfldex That *is* a lesson learned from Perl. Making string-processing fast is hard. That's why we leave it to C-land, at least for now. 17:40
Nemokosch Slowly is better than not at all 17:50
Rog Now that Iā€™ve had coffee, a thought has come to me 18:09
We generally like to keep operators specific in Raku
ā€œDifferent things should look differentā€
Now, as for why no ā€œget nth characterā€ operator exists whatsoever, Iā€™m not sure 18:11
But this is why postcircumfix [] doesnā€™t and shouldnā€™t ā€œindex intoā€ strings
I do think substring feels verbose for something thatā€™s a pretty common operation 18:12
However doesnā€™t that mostly happen in a loop where youā€™re probably accessing several indices across iterations? 18:13
In which case you may as well call .comb and put that into an array
I think tacking on .comb isnā€™t all that bad especially considering you get all the power of proper indexing, including slices 18:14
m: ```say ā€abcdefghijkā€.comb[0, 2, 4 ā€¦ *]``` 18:16
m: ``` 18:17
say ā€abcdefghijkā€.comb[0, 2, 4 ā€¦ *];
```
No? Okay :(
What the hell am I doing wrong šŸ˜‘ 18:18
Kaiepi m:``` 18:24
say ā€abcdefghijkā€.comb[0, 2, 4 ā€¦ *];
```
<@102059593697361920> space after the : ?
Rog Oh
Kaiepi it's picky
Rog Iā€™ve noticed:P 18:26
Iā€™ve noticed :P
Anyway point is itā€™s not too much more code (just a method call) to get a proper character array and you can then use all the power of normal subscripting 18:29
Well, technically string array 18:30
There is no ā€œcharā€ in raku unless youā€™re talking about native int8
Well, okay, even more technically it will give you a List back
Not an Array
Nemokosch It's clearly not a lot 18:47
but if I had to explain someone why it's like this
I would fail šŸ˜‚
Rog I suppose the simplest way to explain it without going deep is to say ā€œ.comb with no args gives you a list of characters so you can treat it as a listā€ 20:17
Now, having to explain why [0] on a scalar gives you back that scalar, wellā€¦ 20:18
yabobay it's the first scalar of the scalar, duhh 20:19
Nemokosch šŸ¤£ 20:26
20:53 jgaz left 21:51 Kaipei joined 21:53 lizmat_ joined 21:54 Kaiepi left 21:55 alethkit_ joined 21:56 guifa joined 21:58 human_blip joined, Util_ joined, guifa_ left, alethkit left, human-blip left 21:59 lizmat left, deadmarshal left, Util left, alethkit_ is now known as alethkit 22:06 deadmarshal joined