> On 9 Jun 2021, at 12:48, Marc Chantreux <[email protected]> wrote:
>
> hello,
>
> I just saw this and it's very good
>
> https://www.youtube.com/watch?v=elalwvfmYgk
>
> The features he picked are indeed things i really like in raku
> and i learned some interesting details. Other details are still
> bugging me so i have some questions there:
>
> A. if x -> $y with //
>
> For exemple, given a function Foo
>
> sub foo ( Int $x ) { 42 if $x > 5 }
>
> this is awesome you can write
>
> if foo 7 -> $value { say $value }
>
> and even
>
> if foo 7 { say $^value }
>
> but is there a way (adverb?) to match if something is False but defined
> so given this
>
> sub foo ( Int $x ) { 0 if $x > 5 }
>
> i would write something else than
>
> sub foo ( Int $x ) { 0 if $x > 5 }
> sub hello {say "hello $^world"}
> if defined my $value = foo 45 { hello $value }
with foo 7 { say $^value }
or if you want to trigger on *not* defined:
without foo 7 { say $^value }
> B. » vs map
>
> Leon made this slide where i consider as equivalent
>
> @list».abs
> @list.map(*.abs)
>
> someone, some day, told me they are not and i shouldn't use » if
> i don't know what it means. I read the doc and came to the
> (incorrect?) conclusion that
>
> @list».abs
>
> is actually
>
> @list.map(*.abs).hyper
>
> which could have important overloads while creating an HyperSeq.
>
> should i reconsider the whole thing and use » without fear?
You can use the » without fear if there aren't any side-effects.
Consider this:
class Foo {
my int $seen = 0;
method bar() { ++$seen } # side-effect
}
and then doing:
(Foo xx 10000)».bar;
Because the ». *can* be spread over multiple threads, and prefix:<++> is not a
thread-safe construct generally, you would probably *not* see the correct
number of updates.
Another thing to remember is the order in which they are executed:
("a".."z")».&say;
is *not* guaranteed to say the letters of the alphabet in alphabetical order.
Hope this explains :-)
Liz