Changeset 16526
- Timestamp:
- 05/25/07 23:12:48 (18 months ago)
- Files:
-
- 2 modified
-
src/Pugs/Prim.hs (modified) (2 diffs)
-
t/operators/repeat.t (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/Pugs/Prim.hs
r16488 r16526 924 924 | otherwise = VStr str 925 925 926 perlReplicate :: VInt -> a -> [a] 927 perlReplicate i a = if i < 0 928 then genericReplicate 0 a 929 else genericReplicate i a 930 926 931 -- |Implementation of 2-arity primitive operators and functions 927 932 op2 :: String -> Val -> Val -> Eval Val … … 932 937 op2 "/" = op2Divide 933 938 op2 "%" = op2Modulus 934 op2 "x" = op2Cast (\x y -> VStr . concat $ (y :: VInt) ` genericReplicate` x)935 op2 "xx" = op2Cast (\x y -> VList . concat $ (y :: VInt) ` genericReplicate` x)939 op2 "x" = op2Cast (\x y -> VStr . concat $ (y :: VInt) `perlReplicate` x) 940 op2 "xx" = op2Cast (\x y -> VList . concat $ (y :: VInt) `perlReplicate` x) 936 941 op2 "+&" = op2Int (.&.) 937 942 op2 "+<" = op2Int shiftL -
t/operators/repeat.t
r15255 r16526 9 9 =cut 10 10 11 plan 19;11 plan 23; 12 12 13 13 #L<S03/Changes to Perl 5 operators/"x (which concatenates repetitions of a string to produce a single string"> … … 17 17 is(1 x 5, '11111', 'number repeat operator works on number and creates string'); 18 18 is('' x 6, '', 'repeating an empty string creates an empty string'); 19 is('a' x 0, '', 'repeating zero times produces an empty string'); 20 is('a' x -1, '', 'repeating negative times produces an empty string'); 19 21 20 22 #L<S03/Changes to Perl 5 operators/"and xx (which creates a list of repetitions of a list or item)"> … … 24 26 is(+@foo, 10, 'list repeat operator created array of the right size'); 25 27 28 26 29 lives_ok { my @foo2 = undef xx 2; }, 'can repeat undefs'; 27 30 my @foo3 = (1, 2) xx 2; … … 30 33 is(@foo3[2], 1, 'can repeat lists'); 31 34 is(@foo3[3], 2, 'can repeat lists'); 35 36 my @foo4 = 'x' xx 0; 37 is(+@foo4, 0, 'repeating zero times produces an empty list'); 38 39 my @foo5 = 'x' xx -1; 40 is(+@foo5, 0, 'repeating negative times produces an empty list'); 41 32 42 my @foo_2d = [1, 2] xx 2; # should create 2d 33 43 is(@foo_2d[1], [1, 2], 'can create 2d arrays', :todo<bug>); # creates a flat 1d array
