on master help sign in
rename: div => (//) and mod => (%)
b183f17Evan Czaplicki
changelog.md+2
@@ -17,6 +17,8 @@
17
17
18#### Breaking Changes:
18#### Breaking Changes:
19
19
20+ * Rename Basics.div to (//)
21+ * Rename Basics.mod to (%)
20 * Rename Maybe.maybe to Maybe.extract
22 * Rename Maybe.maybe to Maybe.extract
21 * Rename Either.either to Either.extract
23 * Rename Either.either to Either.extract
22 * Remove Maybe.justs for (List.filterMap id)
24 * 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 =
418 ]
418 ]
419
419
420 specialOps =
420 specialOps =
421− [ (,) "^" $ \a b -> obj ["Math","pow"] `call` [a,b]
421+ [ (,) "^" $ \a b -> obj ["Math","pow"] `call` [a,b]
422− , (,) "|>" $ flip (<|)
422+ , (,) "|>" $ flip (<|)
423− , (,) "==" $ \a b -> _Utils "eq" `call` [a,b]
423+ , (,) "==" $ \a b -> _Utils "eq" `call` [a,b]
424− , (,) "/=" $ \a b -> PrefixExpr () PrefixLNot (_Utils "eq" `call` [a,b])
424+ , (,) "/=" $ \a b -> PrefixExpr () PrefixLNot (_Utils "eq" `call` [a,b])
425− , (,) "<" $ cmp OpLT 0
425+ , (,) "<" $ cmp OpLT 0
426− , (,) ">" $ cmp OpGT 0
426+ , (,) ">" $ cmp OpGT 0
427− , (,) "<=" $ cmp OpLT 1
427+ , (,) "<=" $ cmp OpLT 1
428− , (,) ">=" $ cmp OpGT (-1)
428+ , (,) ">=" $ cmp OpGT (-1)
429− , (,) "div" $ \a b -> InfixExpr () OpBOr (InfixExpr () OpDiv a b) (IntLit () 0)
429+ , (,) "//" $ \a b -> InfixExpr () OpBOr (InfixExpr () OpDiv a b) (IntLit () 0)
430 ]
430 ]
431
431
432 cmp op n a b = InfixExpr () op (_Utils "cmp" `call` [a,b]) (IntLit () n)
432 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?
22@docs not, (&&), (||), xor, otherwise
22@docs not, (&&), (||), xor, otherwise
23
23
24# Mathematics
24# Mathematics
25−@docs (+), (-), (*), (/), (^), div, rem, mod, abs, sqrt, clamp, logBase, e
25+@docs (+), (-), (*), (/), (^), (//), rem, (%), abs, sqrt, clamp, logBase, e
26
26
27# Trigonometry
27# Trigonometry
28@docs pi, cos, sin, tan, acos, asin, atan, atan2
28@docs pi, cos, sin, tan, acos, asin, atan, atan2
@@ -97,21 +97,29 @@ infixl 7 *
97infixl 7 /
97infixl 7 /
98infixl 8 ^
98infixl 8 ^
99
99
100−infixl 7 `div`
100+infixl 7 //
101−infixl 7 `mod`
101+infixl 7 %
102infixl 7 `rem`
102infixl 7 `rem`
103
103
104{-| Integer division, remainder is discarded. -}
104{-| Integer division, remainder is discarded. -}
105−div : Int -> Int -> Int
105+(//) : Int -> Int -> Int
106−div = Native.Basics.div
106+(//) = Native.Basics.div
107
107
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+-}
109rem : Int -> Int -> Int
113rem : Int -> Int -> Int
110rem = Native.Basics.rem
114rem = Native.Basics.rem
111
115
112−{-| Perform modular arithmetic: ``7 `mod` 2 == 1`` -}
116+{-| Perform [modular arithmetic](http://en.wikipedia.org/wiki/Modular_arithmetic):
117+
118+ 7 % 2 == 1
119+ -1 % 4 == 3
120+-}
113−mod : Int -> Int -> Int
121+(%) : Int -> Int -> Int
114−mod = Native.Basics.mod
122+(%) = Native.Basics.mod
115
123
116{-| Exponentiation: `3^2 == 9` -}
124{-| Exponentiation: `3^2 == 9` -}
117(^) : number -> number -> number
125(^) : number -> number -> number
libraries/Color.elm+1−1
@@ -124,7 +124,7 @@ toRgb color =
124fmod : Float -> Int -> Float
124fmod : Float -> Int -> Float
125fmod f n =
125fmod f n =
126 let integer = floor f
126 let integer = floor f
127− in toFloat (integer `mod` n) + f - toFloat integer
127+ in toFloat (integer % n) + f - toFloat integer
128
128
129rgbToHsl : Int -> Int -> Int -> (Float,Float,Float)
129rgbToHsl : Int -> Int -> Int -> (Float,Float,Float)
130rgbToHsl red green blue =
130rgbToHsl red green blue =
tests/libraries/Test/Array.elm+1−1
@@ -66,7 +66,7 @@ tests =
66 , test "foldr 1" <| assertEqual 15 (Array.foldr (+) 0 (Array.repeat 3 5))
66 , test "foldr 1" <| assertEqual 15 (Array.foldr (+) 0 (Array.repeat 3 5))
67 , test "foldr 2" <| assertEqual [1,2,3] (Array.foldr (::) [] (Array.fromList [1,2,3]))
67 , test "foldr 2" <| assertEqual [1,2,3] (Array.foldr (::) [] (Array.fromList [1,2,3]))
68 , test "foldr 3" <| assertEqual 53 (Array.foldr (-) 54 (Array.fromList [10,11]))
68 , 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]))
70 ]
70 ]
71 nativeTests = suite "Conversion to JS Arrays"
71 nativeTests = suite "Conversion to JS Arrays"
72 [ test "jsArrays" <| assertEqual (Array.fromList [1..1100]) (Native.Array.fromJSArray (Native.Array.toJSArray (Array.fromList [1..1100])))
72 [ 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 =
10 let partitionTests =
10 let partitionTests =
11 let p1 = id
11 let p1 = id
12 p2 x = x < 3
12 p2 x = x < 3
13− isEven n = n `mod` 2 == 0
13+ isEven n = n % 2 == 0
14 in suite "partition Tests" [ test "simple partition" <| assertEqual ([True],[False]) (List.partition p1 [False, True]),
14 in suite "partition Tests" [ test "simple partition" <| assertEqual ([True],[False]) (List.partition p1 [False, True]),
15 test "order check" <| assertEqual ([2,1], [5,6]) (List.partition p2 [2,5,6,1]),
15 test "order check" <| assertEqual ([2,1], [5,6]) (List.partition p2 [2,5,6,1]),
16 test "partition doc check 1" <| assertEqual ([0,1,2], [3,4,5]) (partition p2 [0..5]),
16 test "partition doc check 1" <| assertEqual ([0,1,2], [3,4,5]) (partition p2 [0..5]),