Commit | Line | Data |
7a63380c |
1 | #!perl |
2 | |
3 | use Test::More tests => 10; |
4 | |
5 | use warnings FATAL => 'all'; |
6 | use strict; |
7 | |
8 | use Function::Parameters; |
9 | |
10 | fun id_1($x) { $x } |
11 | |
12 | fun id_2 |
13 | ( |
14 | $x |
15 | ) |
5bf140a1 |
16 | : #hello |
7a63380c |
17 | ( |
18 | $ |
19 | ) |
5bf140a1 |
20 | {@_ == 1 or return; |
7a63380c |
21 | $x |
22 | } |
23 | |
24 | fun id_3 ## |
25 | ( $x ## |
5bf140a1 |
26 | ) ##AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA |
7a63380c |
27 | { ## |
28 | $x ## |
29 | } ## |
30 | |
31 | fun add($x, $y) { |
32 | $x + $y |
33 | } |
34 | |
35 | fun mymap($fun, @args) :(&@) { |
36 | my @res; |
37 | for (@args) { |
38 | push @res, $fun->($_); |
39 | } |
40 | @res |
41 | } |
42 | |
43 | fun fac_1($n) { |
44 | $n < 2 ? 1 : $n * fac_1 $n - 1 |
45 | } |
46 | |
47 | fun fac_2($n) :($) { |
48 | $n < 2 ? 1 : $n * fac_2 $n - 1 |
49 | } |
50 | |
51 | ok id_1 1; |
52 | ok id_1(1), 'basic sanity'; |
53 | ok id_2 1, 'simple prototype'; |
54 | ok id_3(1), 'definition over multiple lines'; |
55 | is add(2, 2), 4, '2 + 2 = 4'; |
56 | is add(39, 3), 42, '39 + 3 = 42'; |
57 | is_deeply [mymap { $_ * 2 } 2, 3, 5, 9], [4, 6, 10, 18], 'mymap works'; |
58 | is fac_1(5), 120, 'fac_1'; |
59 | is fac_2 6, 720, 'fac_2'; |
60 | is fun ($x, $y) { $x . $y }->(fun ($foo) { $foo + 1 }->(3), fun ($bar) { $bar * 2 }->(1)), '42', 'anonyfun'; |