Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 80 lines (69 sloc) 2.045 kb
ff2f9de @sorear Prototype of the Array class
authored
1 # vim: ft=perl6
2 use Test;
9f1bf0e @sorear Implement &sort
authored
3 use MONKEY_TYPING;
ff2f9de @sorear Prototype of the Array class
authored
4
ea8058e @sorear Add leg et al, &grep, &map, infix:<x>
authored
5 sub infix:<x>($str, $ct) {
6 my $i = +$ct;
7 my $j = ''; # XXX use strbuf
8 while $i >= 1 {
9 $i--;
10 $j ~= $str;
11 }
12 $j;
a6766cd @sorear Starts on the TODO...
authored
13 }
14
ea8058e @sorear Add leg et al, &grep, &map, infix:<x>
authored
15 sub grep($filter, *@items) { @items.grep($filter) }
16 sub map($callback, *@items) { @items.map($callback) }
6393299 @sorear Implement slurpy hashes
authored
17
ea8058e @sorear Add leg et al, &grep, &map, infix:<x>
authored
18 sub infix:<leg>($s1, $s2) {
19 Q:CgOp { (box Num (cast num (strcmp (unbox str (@ {$s1.Str})) (unbox str (@ {$s2.Str}))))) }
c6bd89e @sorear Implement nextsame
authored
20 }
21
ea8058e @sorear Add leg et al, &grep, &map, infix:<x>
authored
22 sub infix:<ge>($s1, $s2) { ($s1 leg $s2) >= 0 }
23 sub infix:<gt>($s1, $s2) { ($s1 leg $s2) > 0 }
24 sub infix:<le>($s1, $s2) { ($s1 leg $s2) <= 0 }
25 sub infix:<lt>($s1, $s2) { ($s1 leg $s2) < 0 }
26
9f1bf0e @sorear Implement &sort
authored
27 augment class Any {
28 method sort($cmp = &infix:<leg>) {
29 my $l = self.list.eager;
30 Q:CgOp {
31 (letn n (obj_newblank (obj_llhow (@ {List})))
32 (setslot flat (l n) (bool 1))
33 (setslot items (l n) (vvarlist_sort (@ {$cmp})
34 (getslot items vvarlist (@ {$l}))))
35 (setslot rest (l n) (vvarlist_new_empty))
36 (newrwlistvar (l n)))
37 }
38 }
39 }
40
41 sub sort(*@bits) { @bits.sort }
42
ea8058e @sorear Add leg et al, &grep, &map, infix:<x>
authored
43 ok 'cow' le 'sow', 'cow le sow';
44 ok !('sow' le 'cow'), 'sow !le cow';
45 ok 'row' lt 'tow', 'row lt tow';
46 ok 'how' gt 'bow', 'how gt bow';
47 ok 'yow' ge 'yow', 'yow ge yow';
9f1bf0e @sorear Implement &sort
authored
48 is join("|", sort <c f d z a>), 'a|c|d|f|z', '&sort works';
49 is join("|", <a3 b2 c1 d0>.sort({ substr($^a,1) leg substr($^b,1) })),
50 'd0|c1|b2|a3', '.sort with callback works';
ea8058e @sorear Add leg et al, &grep, &map, infix:<x>
authored
51
0fa6f23 @sorear Fix Foo::Bar regression
authored
52 #is $?FILE, 'test.pl', '$?FILE works';
53 #is $?ORIG.substr(0,5), '# vim', '$?ORIG works';
54
55 # {
56 # {
57 # our $x = 5; #OK
58 # }
59 # ok $::x == 5, '$::x finds our variable';
60 #
61 # package Fao { our $y = 6; } #OK
62 # ok $::Fao::y == 6, '$::Fao::y works as $Fao::y';
63 #
64 # { class Mao { } }
65 # ok ::Mao.new.defined, 'can use classes via ::Mao';
66 # }
67 #
68 # {
69 # my $x = 7; #OK
70 # ok $::x == 7, '$::x can find lexicals';
71 # class A3 {
72 # method moo { 42 }
73 # class B4 {
74 # ok ::A3.moo, '::A3 can find outer classes';
75 # }
76 # }
77 # }
ae2e557 @sorear Implement control operators next, redo, last, return
authored
78
ff2f9de @sorear Prototype of the Array class
authored
79 done-testing;
Something went wrong with that request. Please try again.