🦋 Welcome to the MAIN() IRC channel of the Raku Programming Language (raku.org). This channel is logged for the purpose of keeping a history about its development | evalbot usage: 'm: say 3;' or /msg camelia m: ... | Log inspection is getting closer to beta. If you're a beginner, you can also check out the #raku-beginner channel!
Set by lizmat on 25 August 2021.
tonyo codesections: that seems fine to me .. it's not re-binding 'nope' and 'yep'. it's rebinding something currently pointing at 'yep' to 'nope'. 05:19
moritz_ but aren't function params supposed to be ready-only by default? 06:06
putting an "Any" in front should not change that
moon-child m: sub f(Any $x) { $x := 5 }; f my $x = 6; say $x 06:09
camelia 6
moon-child I do not understand why Any changes things, though 06:10
moritz_ it shouldn't, and that's a bug 06:14
MasterDuke committable6: releases sub f(Any $x) { $x := 5 }; f my $x = 6; say $x 08:16
committable6 MasterDuke, ¦releases (58 commits): «6␤»
MasterDuke committable6: releases sub f($x) { $x := 5 }; f my $x = 6; say $x 08:17
committable6 MasterDuke, ¦releases (58 commits): «04===SORRY!04=== Error while compiling /tmp/Bdk9j60ANy␤Cannot use bind operator with this left-hand side␤at /tmp/Bdk9j60ANy:1␤------> 03sub f($x) { $x := 5 08⏏04}; f my $x = 6; say $x␤ «exit code = 1»»
whatnext hello all - quick question about classes and required attributes 12:12
in the docs for the "required" trait here: docs.raku.org/language/typesystem#...s_required it seems to include `submethod BUILD` and pass `$attr` to `$!attr` - I am guessing this is in order to prevent the error message "attr is required but not provided" 12:15
however, this seems a bit ugly (e.g. when compared to Moose). If there are 10 required params then this needs to be done with all 10 (?) Is there a way to avoid having to include that `BUILD` method? 12:17
(ie and still pick up the required param from the input)
? 12:18
lizmat why do you need BUILD? 12:19
tbrowder yep, that looks like a bad example 12:23
whatnext to be honest I don't know that I do
I assumed I could just pass the param in `.new( attr => $attr )` without needing BUILD, but that seems to produce the error "attr required but not provided" 12:24
possibly I have something else wrong
MasterDuke m: class A { has $.b is required }; say A.new(b=>3) 12:26
camelia A.new(b => 3)
MasterDuke m: class A { has $.b is required }; say A.new(b=>3).b
camelia 3
Geth doc: 0a01431977 | (Tom Browder)++ (committed using GitHub Web editor) | doc/Language/typesystem.pod6
Update typesystem.pod6

BUILD not required in that example.
12:27
linkable6 Link: docs.raku.org/language/typesystem
whatnext wait I think I got it - I need to define it as `$.attr` not `$!attr` 12:29
lizmat m: class A { has $.a is required }; A.new 12:31
camelia The attribute '$!a' is required, but you did not provide a value for it.
in block <unit> at <tmp> line 1
lizmat m: class A { has $.a is required }; dd A.new(a => 42)
camelia A.new(a => 42)
lizmat whatnext ^^ must be something else?
oops, should backlog before writing :-) 12:32
whatnext yes I think you would need `BUILD` if you want to keep the attribute private
tbrowder m: class A { has $!a is required}; A.new
camelia The attribute '$!a' is required, but you did not provide a value for it.
in block <unit> at <tmp> line 1
whatnext ok its a relief that this isn't needed! Thanks 12:33
MasterDuke m: class A { has $!b is required }; say A.new(b=>3)
camelia The attribute '$!b' is required, but you did not provide a value for it.
in block <unit> at <tmp> line 1
lizmat also, if you want an attribute to not be specifiable with .new, but you want it to have an accessor 12:35
you can use "is built(False)"
MasterDuke tbrowder: your commit was correct, since the example given used `$.attr`, but it might be good to add an example with `$!attr` and show that it errors unless you have the BUILD
lizmat m: class A { has $.a is built(False) = 42 }; dd A.new.a
camelia 42
lizmat m: class A { has $.a is built(False) = 42 }; dd A.new(a => 666).a 12:36
camelia 42
tbrowder good point (but TWEAK instead...)
codesections and `is built` is doc'ed at docs.raku.org/type/Attribute#index...t_is_built
lizmat vice-versa, if you want something to be specifiable but *not* have an accessor:
m: class A { has $!a is built = 42; method b() { $!a } }; dd A.new(a => 666).b 12:37
camelia 666
MasterDuke tbrowder: no, it has to be BUILD, TWEAK is too late
tbrowder are you sure? 12:38
MasterDuke m: class A { has $!b is required; submethod TWEAK(:$b) { $!b = $b } }; say A.new(b=>3) 12:40
camelia The attribute '$!b' is required, but you did not provide a value for it.
in block <unit> at <tmp> line 1
MasterDuke m: class A { has $!b is required; submethod BUILD(:$b) { $!b = $b } }; say A.new(b=>3)
camelia A.new
tbrowder ok :-) 13:02
Geth doc: fe13e801de | (Tom Browder)++ (committed using GitHub Web editor) | doc/Language/typesystem.pod6
Update typesystem.pod6

Add an example with a private attribute.
13:19
linkable6 Link: docs.raku.org/language/typesystem
tbrowder not finished yet... 13:24
[Coke] I wonder if we should disallow doc edits through the web. :| 13:28
Geth doc: 7c6e458d51 | Coke++ | doc/Language/typesystem.pod6
class keyword is case sensitive; missing }

whitespace cleanup
linkable6 Link: docs.raku.org/language/typesystem
tbrowder [Coke]: i agree with that! it's too inviting or shooting from the hip 13:30
*for
MasterDuke can you make web edits be allowed, but only mergeable via PR? 13:32
[Coke] We could encourage it, not sure if we could enforce it. 13:33
Eh. probably more interesting to consider switching to a regular release schedule on docs (so that edits aren't immediately pushed out) 13:34
(maybe on the same schedule as the release of the software)
codesections I make doc edits through the web UI. I'm happy to stop, but that'd probably mean I'm less inclined to make minor fixes 13:55
(I do usually open a PR, though)
re: a docs release schedule, I thought nothing is currently pushed out automatically – that it all waited on JJ to cut a release. Did that change? 14:00
tbrowder no complaint here, i *usually* do the same (see PR to fix my mess shortly) 14:24
Geth doc: tbrowder++ created pull request #3967:
Clarify effect of 'is required' on a private attribute
14:25
tbrowder i think it would help to add a following note about using a BUILD in either case would quell the error even though the user does not enter an explicit value with new. 14:29
m: class A { has $.a is required; submethod BUILD(:$a) { $!a = $a } }; A.new 14:31
camelia ( no output )
whatnext next question :) : why would I get "Cannot look up attributes in a My::Class type object" ? 14:40
MasterDuke you need an instance of the class 14:41
m: class A { has $.a = 4 }; say A.new.a; say A.a 14:42
camelia 4
Cannot look up attributes in a A type object
in method a at <tmp> line 1
in block <unit> at <tmp> line 1
Altreus whatnext: this confused me for ages. It's a "type object" of My::Class, not a My::Class-type object
codesections m: my Rat $r = 1/3; say $r.denominator 14:43
camelia 3
MasterDuke i wonder why that error doesn't suggest 'are you missing a .new?'? which error does that...?
codesections m: say Rat.denominator
camelia Cannot look up attributes in a Rat type object
in block <unit> at <tmp> line 1
whatnext hm... that would make sense, though I can't seem to make it fit with my situation 14:46
MasterDuke m: class A { has $.a = 4; method foo(A:D:) { say "hi" } }; A.new.foo; A.foo 14:48
camelia hi
Invocant of method 'foo' must be an object instance of type 'A', not a
type object of type 'A'. Did you forget a '.new'?
in method foo at <tmp> line 1
in block <unit> at <tmp> line 1
MasterDuke ^^^ that's what i was thinking of
whatnext I think I do have an instance of the class. I am trying to access e.g. `self.filename` from within a `load` method in an instance of the class 14:52
hm.. it's a good clue though, thanks :) 14:54
codesections you need to use $!filename to access an attribute from inside the class
whatnext I was wondering about that - so `self.filename` is not a good idea? 14:59
Altreus m: class A { has $.a = 4; method foo { say self.a } }; A.new.foo 15:02
camelia 4
Altreus shrug
m: class A { has $!a = 4; method foo { say self.a } }; A.new.\foo
camelia 5===SORRY!5=== Error while compiling <tmp>
Malformed postfix call
at <tmp>:1
------> 3= 4; method foo { say self.a } }; A.new.7⏏5\foo
Altreus pardon me I'm sure 15:03
codesections self.a (or $.a) call the `a` public method on A. Which works when there _is_ an `a` public method (including an auto-generated one) 15:04
and when A has been fully built
Altreus m: class A { has $!a = 4; }; 15:06
camelia ( no output )
Altreus ok it was probably that \ I put in by accident
m: class A { has $!a = 4; method}; A.new.foo
camelia 5===SORRY!5=== Error while compiling <tmp>
Missing block
at <tmp>:1
------> 3class A { has $!a = 4; method7⏏5}; A.new.foo
Altreus ?? where did my method body go
stupid IRC client
anyway
whatnext ok thanks for the clarification :) 15:30
holyghost hi Xliff 17:31
Xliff \o 17:44
[Coke] chuckles at github.com/rottytooth/rot8000 18:42
holyghost lol, elvish rot13 18:59
[Coke] codesections: in www.codesections.com/blog/raku-lisp-impression/ (nice article!) you say IFFE when I think you mean IIFE. 20:14
codesections [Coke] ah, yes, the more obscure Inherently Fabulous Function Expression. (thanks; fixed) 20:47
[Coke] :) 22:43