|
00:37
arkiuat left
00:57
arkiuat joined
01:02
arkiuat left,
mahlay left
01:05
mahlay joined
01:25
arkiuat joined
01:29
arkiuat left
01:31
librasteve_ left
01:57
arkiuat joined
01:58
sibl joined
02:02
arkiuat left
02:18
arkiuat joined
02:23
arkiuat left
02:54
arkiuat joined
02:59
arkiuat left
03:19
arkiuat joined
03:24
arkiuat left
03:56
arkiuat joined
04:01
arkiuat left
04:07
arkiuat joined
04:48
sibl left
05:02
sibl joined
|
|||
| disbot11 | <itsrakanott> Hello, people. I was wondering, if someone would be willing to help. Why does this code deadlocks itself? role Named { has Str $.name = "Unnamed"; } class Entity does Named { method name() { say self.$.name; return; } } my $entity = Entity.new(name => "bob"); $entity.name(); | 06:11 | |
| <shimmerfairy> It's because $.name calls the name method its inside of, so it infinitely recurses. The has Str $.name declaration is actually convenient shorthand for class A { has Str $!name = "Default"; method name { $!name } } | 06:30 | ||
| <shimmerfairy> Redefining the method is completely fine, but you have to access the variable with $!name instead. $.name is shorthand for self.name, and self.$.name actually tries to do something nonsensical. | 06:32 | ||
| <itsrakanott> I knew it was something with the declaration. Thanks. | 06:33 | ||
| <itsrakanott> Another, slightly more convoluted question. Let's say i have this class: class Computer { has &compute_function; } and i instantiate object like that: sub something() { say "something happens!!"; } Computer.new(compute_function => &something); How would i call &compute_function from inside of Computer? I have tried doing &compute_function, &.compute_function, self.&compute_function, etc. Can't seem to get a | 07:10 | ||
| hold of this thing as of yet. | |||
| <itsrakanott> A mistake in my code somehow made it work. &compute_function.() works. Only with a dot. | 07:12 | ||
| <shimmerfairy> class A { has &.foo; method bar { say &!foo(42); say (&.foo)(42); say self.foo()(42); } } A.new(:foo({$_ * 3})).bar This is how I got it to work. The &!foo accesses the attribute directly, while &.foo and self.foo both call the public method foo to get a function object. So when accessing a public function object, you're calling two functions: one to get the object, and one to | 07:24 | ||
| actually invoke it. If you type &.foo(42), that gets read as &(self.foo(42)), which is the wrong function to send the argument to. | |||
|
07:32
arkiuat left
08:02
arkiuat joined
08:06
arkiuat left
08:36
arkiuat joined
08:40
arkiuat left
08:43
arkiuat joined
08:49
arkiuat left
08:58
sibl left
09:06
sibl joined
09:11
dakkar joined
09:21
arkiuat joined
09:26
arkiuat left
09:36
sibl left
09:41
sibl joined
09:56
arkiuat joined
10:04
sibl left
10:05
arkiuat left
10:35
arkiuat joined
10:40
arkiuat left
10:50
arkiuat joined
11:49
arkiuat left
12:11
sibl joined
12:19
arkiuat joined
12:24
arkiuat left
12:46
arkiuat joined
12:51
arkiuat left
13:19
arkiuat joined
13:24
sibl left,
arkiuat left
13:46
librasteve_ joined
13:47
arkiuat joined
13:52
arkiuat left
14:21
arkiuat joined
14:26
arkiuat left
14:48
arkiuat joined
14:52
arkiuat left
15:20
arkiuat joined
15:25
arkiuat left
15:42
arkiuat joined
16:09
arkiuat left
16:22
human-blip left
16:24
human-blip joined
16:31
human-blip left
16:34
human-blip joined
16:49
human-blip left
16:51
human-blip joined
17:28
human-blip left
17:30
human-blip joined
17:37
dakkar left
19:36
stanrifkin joined
20:46
habere-et-disper joined
20:59
habere-et-disper left
21:06
habere-et-disper joined
21:18
habere-et-disper left
21:23
habere-et-disper joined
21:51
habere-et-disper left
22:19
habere-et-disper joined
23:40
habere-et-disper left
|
|||