[t/spec] A few wilder tests for nesting.
[pugs.git] / examples / overloading.pl
blob00a98506115f59f172e61c91fdb9fc705771a61a
1 # plays with some fun operator overloading.
3 # Please remember to update t/examples/examples.t and rename
4 # examples/output/overloading if you rename/move this file.
6 use v6;
8 multi postfix:<!> ($x) { [*] 1..$x }
9 multi postfix:<!> (@x) { [*] @x }
11 multi infix:<z> (@x, @y) { each(@x;@y) }
12 multi infix:<z> (Str $x, Str $y) { $x ~ $y }
14 my @x = 1..5;
15 my @y = 6..10;
17 (@x z @y).perl.say;
18 my $test = "hello" z "goodbye";
19 $test.perl.say;
21 $test = 10!; $test.perl.say;
23 my @test = (1..5);
24 $test = @test!;
25 $test.perl.say;
27 multi sub postfix:<%> ($_) { $_ / 100 }
28 multi sub infix:<of> ($x,$y) {$x * $y}
29 say 50% of 100;
31 sub base (Int $M, Int $N) {
32 return $M if ($M < $N);
33 my $t = $M % $N;
34 return base(int($M/$N),$N) ~ $t;
37 multi sub infix:<base> ($x,$y) {base($x,$y)}
38 say $_ base 2 for (1..5);
40 # Commented so this file can be used in example.t.
41 # multi sub infix:<<.?.>> ($low,$high) { int( ($high - $low).rand + $low ) + 1; };
42 # say 1 .?. 5;
43 # say 10 .?. 20;