on master help sign in
rename: div => (//) and mod => (%)
commitb183f1771864e02a616377036b971062c31664ad authorEvan Czaplicki <info@elm-lang.org> dateTue 12 Aug 2014, 14:24 (12 years ago) parent2868ecd
6 files changed+31−21
changelog.md+2 compiler/Generate/JavaScript.hs+9−9 libraries/Basics.elm+17−9 libraries/Color.elm+1−1 tests/libraries/Test/Array.elm+1−1 tests/libraries/Test/List.elm+1−1
changelog.md+2
@@ -17,6 +17,8 @@
1717
1818#### Breaking Changes:
1919
20+ * Rename Basics.div to (//)
21+ * Rename Basics.mod to (%)
2022 * Rename Maybe.maybe to Maybe.extract
2123 * Rename Either.either to Either.extract
2224 * Remove Maybe.justs for (List.filterMap id)
compiler/Generate/JavaScript.hs+9−9
@@ -418,15 +418,15 @@ binop region func@(Var.Canonical home op) e1 e2 =
418418 ]
419419
420420 specialOps =
421− [ (,) "^" $ \a b -> obj ["Math","pow"] `call` [a,b]
422− , (,) "|>" $ flip (<|)
423− , (,) "==" $ \a b -> _Utils "eq" `call` [a,b]
424− , (,) "/=" $ \a b -> PrefixExpr () PrefixLNot (_Utils "eq" `call` [a,b])
425− , (,) "<" $ cmp OpLT 0
426− , (,) ">" $ cmp OpGT 0
427− , (,) "<=" $ cmp OpLT 1
428− , (,) ">=" $ cmp OpGT (-1)
429− , (,) "div" $ \a b -> InfixExpr () OpBOr (InfixExpr () OpDiv a b) (IntLit () 0)
421+ [ (,) "^" $ \a b -> obj ["Math","pow"] `call` [a,b]
422+ , (,) "|>" $ flip (<|)
423+ , (,) "==" $ \a b -> _Utils "eq" `call` [a,b]
424+ , (,) "/=" $ \a b -> PrefixExpr () PrefixLNot (_Utils "eq" `call` [a,b])
425+ , (,) "<" $ cmp OpLT 0
426+ , (,) ">" $ cmp OpGT 0
427+ , (,) "<=" $ cmp OpLT 1
428+ , (,) ">=" $ cmp OpGT (-1)
429+ , (,) "//" $ \a b -> InfixExpr () OpBOr (InfixExpr () OpDiv a b) (IntLit () 0)
430430 ]
431431
432432 cmp op n a b = InfixExpr () op (_Utils "cmp" `call` [a,b]) (IntLit () n)
libraries/Basics.elm+17−9
@@ -22,7 +22,7 @@ are your tuples so big?
2222@docs not, (&&), (||), xor, otherwise
2323
2424# Mathematics
25−@docs (+), (-), (*), (/), (^), div, rem, mod, abs, sqrt, clamp, logBase, e
25+@docs (+), (-), (*), (/), (^), (//), rem, (%), abs, sqrt, clamp, logBase, e
2626
2727# Trigonometry
2828@docs pi, cos, sin, tan, acos, asin, atan, atan2
@@ -97,21 +97,29 @@ infixl 7 *
9797infixl 7 /
9898infixl 8 ^
9999
100−infixl 7 `div`
101−infixl 7 `mod`
100+infixl 7 //
101+infixl 7 %
102102infixl 7 `rem`
103103
104104{-| Integer division, remainder is discarded. -}
105−div : Int -> Int -> Int
106−div = Native.Basics.div
105+(//) : Int -> Int -> Int
106+(//) = Native.Basics.div
107107
108−{-| Finds the remainder after dividing one number by another: ``4 `rem` 3 == 1`` -}
108+{-| Finds the remainder after dividing one number by another:
109+
110+ 7 `rem` 2 == 1
111+ -1 `rem` 4 == 1
112+-}
109113rem : Int -> Int -> Int
110114rem = Native.Basics.rem
111115
112−{-| Perform modular arithmetic: ``7 `mod` 2 == 1`` -}
113−mod : Int -> Int -> Int
114−mod = Native.Basics.mod
116+{-| Perform [modular arithmetic](http://en.wikipedia.org/wiki/Modular_arithmetic):
117+
118+ 7 % 2 == 1
119+ -1 % 4 == 3
120+-}
121+(%) : Int -> Int -> Int
122+(%) = Native.Basics.mod
115123
116124{-| Exponentiation: `3^2 == 9` -}
117125(^) : number -> number -> number
libraries/Color.elm+1−1
@@ -124,7 +124,7 @@ toRgb color =
124124fmod : Float -> Int -> Float
125125fmod f n =
126126 let integer = floor f
127− in toFloat (integer `mod` n) + f - toFloat integer
127+ in toFloat (integer % n) + f - toFloat integer
128128
129129rgbToHsl : Int -> Int -> Int -> (Float,Float,Float)
130130rgbToHsl red green blue =
tests/libraries/Test/Array.elm+1−1
@@ -66,7 +66,7 @@ tests =
6666 , test "foldr 1" <| assertEqual 15 (Array.foldr (+) 0 (Array.repeat 3 5))
6767 , test "foldr 2" <| assertEqual [1,2,3] (Array.foldr (::) [] (Array.fromList [1,2,3]))
6868 , test "foldr 3" <| assertEqual 53 (Array.foldr (-) 54 (Array.fromList [10,11]))
69− , test "filter" <| assertEqual (Array.fromList [2,4,6]) (Array.filter (\x -> x `mod` 2 == 0) (Array.fromList [1..6]))
69+ , test "filter" <| assertEqual (Array.fromList [2,4,6]) (Array.filter (\x -> x % 2 == 0) (Array.fromList [1..6]))
7070 ]
7171 nativeTests = suite "Conversion to JS Arrays"
7272 [ test "jsArrays" <| assertEqual (Array.fromList [1..1100]) (Native.Array.fromJSArray (Native.Array.toJSArray (Array.fromList [1..1100])))
tests/libraries/Test/List.elm+1−1
@@ -10,7 +10,7 @@ tests =
1010 let partitionTests =
1111 let p1 = id
1212 p2 x = x < 3
13− isEven n = n `mod` 2 == 0
13+ isEven n = n % 2 == 0
1414 in suite "partition Tests" [ test "simple partition" <| assertEqual ([True],[False]) (List.partition p1 [False, True]),
1515 test "order check" <| assertEqual ([2,1], [5,6]) (List.partition p2 [2,5,6,1]),
1616 test "partition doc check 1" <| assertEqual ([0,1,2], [3,4,5]) (partition p2 [0..5]),