Re: Objects, TWEAK and return

2021-03-22 Thread yary
Agreed! -y On Mon, Mar 22, 2021 at 6:45 PM Ralph Mellor wrote: > On Mon, Mar 22, 2021 at 2:12 PM yary wrote: > > > > It's not good practice to use "map" for side effects only, discarding > > the returned value–which happens here > > I agree. > > > Would [using `for`] also work-around the lack

Re: Objects, TWEAK and return

2021-03-22 Thread Ralph Mellor
On Mon, Mar 22, 2021 at 2:12 PM yary wrote: > > It's not good practice to use "map" for side effects only, discarding > the returned value–which happens here I agree. > Would [using `for`] also work-around the lack of sink context in TWEAK? Yes. > I think it is a cause of the unexpected

Re: Objects, TWEAK and return

2021-03-22 Thread yary
Good to see this investigated down to the details, yet I just realized something that was bothering me about it. Going back to the original post: submethod TWEAK { $!filelist.lines».split(',').map( -> ($a, $b) { @!show.push: ( $a, $b ) }); } It's not good practice to use "map" for side

Re: Objects, TWEAK and return

2021-03-21 Thread Ralph Mellor
On Sun, Mar 21, 2021 at 9:47 PM wrote: > > Waw! :) Following your examples and suggestions, these work: > > > class { submethod TWEAK(-->Nil) { Any.map: {say 99} } }.new; > > class { submethod TWEAK { sink Any.map: {say 99} } }.new; > > class { submethod TWEAK { eager Any.map: {say 99} }

Re: Objects, TWEAK and return

2021-03-21 Thread mimosinnet
Waw! :) Following your examples and suggestions, these work: > class { submethod TWEAK(-->Nil) { Any.map: {say 99} } }.new; > class { submethod TWEAK { sink Any.map: {say 99} } }.new; > class { submethod TWEAK { eager Any.map: {say 99} } }.new; I really appreciate your discussion. Let me know

Re: Objects, TWEAK and return

2021-03-14 Thread Ralph Mellor
On Sun, Mar 14, 2021 at 2:12 AM Brad Gilbert wrote: > > Ralph, the last value in all functions are not sunk by default, > so of course the last one in `TWEAK` is not sunk by default. Right. Thanks for correcting this misleading part of my explanation. > The bug is that the calling code is not

Re: Objects, TWEAK and return

2021-03-13 Thread Brad Gilbert
Ralph, the last value in all functions are not sunk by default, so of course the last one in `TWEAK` is not sunk by default. This is intended behaviour. It is up to the code that calls a function to sink the result if that is the desired behaviour. sub foo { 'a b c'.words».uc.map:

Re: Objects, TWEAK and return

2021-03-13 Thread Ralph Mellor
Here's a golf: class { submethod TWEAK { Any.map: {say 99} } }.new; # class { submethod TWEAK { Any.map: {say 99}; 42 } }.new; # 99 class { submethod TWEAK (--> 42) { Any.map: {say 99} } }.new; # 99 The last line in a `BUILD` or `TWEAK` submethod is not eagerly

Re: Objects, TWEAK and return

2021-03-13 Thread Brad Gilbert
I think that this is caused because it is returning a 「Sequence」 that is not getting sunk. This is because the last value from a function is never sunk in that function. You could also use 「eager」 「sink」 or follow it with 「Nil」 or some other value (instead of 「return」) eager

Re: Objects, TWEAK and return

2021-03-13 Thread Vadim Belman
At the first glance it looks like bug. Possibly a result of over-optimization. Worth opening an issue at https://github.com/rakudo/rakudo/issues Best regards, Vadim Belman > On Mar 13, 2021, at 3:29 PM, mimosin...@gmail.com wrote: > > Hi, > > When working with this week challenge for the

Objects, TWEAK and return

2021-03-13 Thread mimosinnet
Hi, When working with this week challenge for the PerlWeeklyChallenge , I noticed this behaviour with TWEAK: *This does not work:* submethod TWEAK { $!filelist.lines».split(',').map( -> ($a, $b) { @!show.push: ( $a, $b ) }); } *This works:* submethod