Camelia
Prev: Method invocation in assignment

Calling a function during assignment

The same can be used with functions so instead of writing my $lower = min($lower, $new_value); you can write $lower min= $new_value;

examples/arrays/assignment_function_shortcuts.p6
#!/usr/bin/env perl6
use v6;


my $lower = 2;
$lower min= 3;
say $lower;         # 2

$lower min= 1;
say $lower;         # 1

This should even work with the comma operator effectively pusing more values on an array but it is not yet implemented in Rakudo

 my @a = (1, 2, 3);
 @a ,= 4;
 @a.say;

Prev: Method invocation in assignment

Table of Contents

Comments

In the comments, please wrap your code snippets within <pre> </pre> tags and use spaces for indentation.
comments powered by Disqus

Perl 6 Tricks and Treats newsletter

Register to the free newsletter now, and get updates and news.
Email:
Name: