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.
01:35 jgaz left 04:13 MasterDuke left
a12l Thanks! I thought more of how uc("asdf") === "asdf".uc 07:29
In the former case it acts as a subroutine, in the later as a method in the Str class. 07:30
nahita3882 yeah the former is the "free function form" defined here: multi sub uc($s) { $s.uc } all it does is call .uc on the argument The method form is actually defined in 4 places: - in Nil.rakumod to specifically warn about it - in Cool.rakumod because Methods in Cool coerce the invocant to a more specific type, and then call the same method on that type, which in fact does nothing but self.Str.uc - in 07:53
Str.rakumod where it really calls the low-level nqp::uc which performs the upcasing - in allomorphs.rakumod because Allomorphs are a hybrid of a Numeric and a Stringy component, so it gets the Stringy component and then calls .uc on it This co-existence of a functionality in both free-function form and as a method applies for many routines and it is very convenient I think; you can choose to call however you wish. As
an aside, if you have a sub form but not a method, let's say sub f(Str $s) you can still call it as if it's a method via prefixing it with "&", e.g., raku >>> sub fun(Str $s) { $s.lc ~ $s.uc } &fun >>> "Yes".&fun yesYES Here, "Yes".fun won't work because fun is not attached as a method of the Str class but Raku lets you call as if it's one, provided you do it as .&fun instead of .fun
(the signature need not be Str $s to work on strings; it can be bare $s without a type constraint, that was only an example) 07:55
a12l @nahita3882: Thanks for the explanation! 09:07
11:48 lizmat_ joined 11:52 lizmat left 12:02 lizmat_ left, lizmat joined 14:48 jgaz joined 17:27 gfldex left 17:33 gfldex joined 21:15 jgaz left