Re: How to accomplish a method interpolation?

2017-12-30 Thread clasclin .
Ohhh I see the parens are significant. Now this works :) method !show-item ($msg, $item, $attr) { say " $msg ", %!items{$item}."$attr"() if %!items{$item}:exists; } method show { for { self!show-item(.values.tc, .values, 'amount'); }

Re: How to accomplish a method interpolation?

2017-12-30 Thread Brandon Allbery
Uh, it's a D thing. It's not just a programmatic container representing inventory, but has its own gameplay qualities (in original D, for example, it reduced inventory weight by a lot). I'd guess that currently it's not doing anything special, but might well be intended to do so later --- either

Re: How to accomplish a method interpolation?

2017-12-30 Thread Elizabeth Mattijsen
But that's the kind of semantic that Bag/BagHashes are meant to perform: a "bag of holding”! Or am I missing something? > On 30 Dec 2017, at 12:55, Brandon Allbery wrote: > > I think this is just name collision; this sounds like a dungeon crawler type > thing and it's a

Re: How to accomplish a method interpolation?

2017-12-30 Thread Brandon Allbery
I think this is just name collision; this sounds like a dungeon crawler type thing and it's a "bag of holding". On Sat, Dec 30, 2017 at 6:45 AM, Elizabeth Mattijsen wrote: > > On 30 Dec 2017, at 06:13, clasclin . wrote: > > > > I'm reading a book "Make your

Re: How to accomplish a method interpolation?

2017-12-30 Thread Elizabeth Mattijsen
> On 30 Dec 2017, at 06:13, clasclin . wrote: > > I'm reading a book "Make your own python text adventure" and decided to give > it a try with perl6. So this code works as expected. > > class Bag { > has %.items; > > method show { > say "ropa ",

Re: How to accomplish a method interpolation?

2017-12-30 Thread Siavash
What you want is `%items{$item}."$attr"()`. But if all you want is removing the show's repetition, maybe there are other ways, for example: for %!items:kv { say $^key.tc, ' ', $^value.amount; } or if you want all items: for %!items { say .key.tc, ' ', .value.amount; } On 2017-12-30