diff --git a/kiss/src/kiss/Kiss.hx b/kiss/src/kiss/Kiss.hx index 18b23d8c..13259600 100644 --- a/kiss/src/kiss/Kiss.hx +++ b/kiss/src/kiss/Kiss.hx @@ -111,6 +111,24 @@ class Kiss { // These work with (apply) because they are added as "opAliases" in Macros.kiss: "min" => Symbol("Prelude.min"), "max" => Symbol("Prelude.max"), + "iHalf" => Symbol("Prelude.iHalf"), + "iThird" => Symbol("Prelude.iThird"), + "iFourth" => Symbol("Prelude.iFourth"), + "iFifth" => Symbol("Prelude.iFifth"), + "iSixth" => Symbol("Prelude.iSixth"), + "iSeventh" => Symbol("Prelude.iSeventh"), + "iEighth" => Symbol("Prelude.iEighth"), + "iNinth" => Symbol("Prelude.iNinth"), + "iTenth" => Symbol("Prelude.iTenth"), + "fHalf" => Symbol("Prelude.fHalf"), + "fThird" => Symbol("Prelude.fThird"), + "fFourth" => Symbol("Prelude.fFourth"), + "fFifth" => Symbol("Prelude.fFifth"), + "fSixth" => Symbol("Prelude.fSixth"), + "fSeventh" => Symbol("Prelude.fSeventh"), + "fEighth" => Symbol("Prelude.fEighth"), + "fNinth" => Symbol("Prelude.fNinth"), + "fTenth" => Symbol("Prelude.fTenth"), ], identAliases: [ // These ones won't conflict with variables and might commonly be used with (apply) diff --git a/kiss/src/kiss/Macros.hx b/kiss/src/kiss/Macros.hx index a888c92f..70b85491 100644 --- a/kiss/src/kiss/Macros.hx +++ b/kiss/src/kiss/Macros.hx @@ -85,6 +85,25 @@ class Macros { // These shouldn't be ident aliases because they are common variable names "min" => "Prelude.min", "max" => "Prelude.max", + // These might not be common, but playing it safe: + "iHalf" => "Prelude.iHalf", + "iThird" => "Prelude.iThird", + "iFourth" => "Prelude.iFourth", + "iFifth" => "Prelude.iFifth", + "iSixth" => "Prelude.iSixth", + "iSeventh" => "Prelude.iSeventh", + "iEighth" => "Prelude.iEighth", + "iNinth" => "Prelude.iNinth", + "iTenth" => "Prelude.iTenth", + "fHalf" => "Prelude.fHalf", + "fThird" => "Prelude.fThird", + "fFourth" => "Prelude.fFourth", + "fFifth" => "Prelude.fFifth", + "fSixth" => "Prelude.fSixth", + "fSeventh" => "Prelude.fSeventh", + "fEighth" => "Prelude.fEighth", + "fNinth" => "Prelude.fNinth", + "fTenth" => "Prelude.fTenth", // These can't be ident aliases because they would supercede the typed call macros that wrap them: "zip" => "Prelude.zipThrow", "zipThrow" => "Prelude.zipThrow", diff --git a/kiss/src/kiss/Prelude.hx b/kiss/src/kiss/Prelude.hx index 7b0a1a28..1cb1b06d 100644 --- a/kiss/src/kiss/Prelude.hx +++ b/kiss/src/kiss/Prelude.hx @@ -161,6 +161,33 @@ class Prelude { public static var lesserEqual:Function = Reflect.makeVarArgs(_comparison.bind("<=")); public static var areEqual:Function = Reflect.makeVarArgs(_comparison.bind("==")); + // Like quickNths but for division. Support int and float output: + private static function iFraction (num:Float, denom:Float) { + return Std.int(num / denom); + } + public static var iHalf:Float->Int = iFraction.bind(_, 2); + public static var iThird:Float->Int = iFraction.bind(_, 3); + public static var iFourth:Float->Int = iFraction.bind(_, 4); + public static var iFifth:Float->Int = iFraction.bind(_, 5); + public static var iSixth:Float->Int = iFraction.bind(_, 6); + public static var iSeventh:Float->Int = iFraction.bind(_, 7); + public static var iEighth:Float->Int = iFraction.bind(_, 8); + public static var iNinth:Float->Int = iFraction.bind(_, 9); + public static var iTenth:Float->Int = iFraction.bind(_, 10); + private static function fFraction (num:Float, denom:Float) { + return num / denom; + } + public static var fHalf:Float->Float = fFraction.bind(_, 2); + public static var fThird:Float->Float = fFraction.bind(_, 3); + public static var fFourth:Float->Float = fFraction.bind(_, 4); + public static var fFifth:Float->Float = fFraction.bind(_, 5); + public static var fSixth:Float->Float = fFraction.bind(_, 6); + public static var fSeventh:Float->Float = fFraction.bind(_, 7); + public static var fEighth:Float->Float = fFraction.bind(_, 8); + public static var fNinth:Float->Float = fFraction.bind(_, 9); + public static var fTenth:Float->Float = fFraction.bind(_, 10); + + public static function sort(a:Array, ?comp:(T, T) -> Int):kiss.List { if (comp == null) comp = Reflect.compare; diff --git a/kiss/src/test/cases/BasicTestCase.hx b/kiss/src/test/cases/BasicTestCase.hx index 15df7d5d..cc35e9ce 100644 --- a/kiss/src/test/cases/BasicTestCase.hx +++ b/kiss/src/test/cases/BasicTestCase.hx @@ -359,6 +359,11 @@ class BasicTestCase extends Test { function testInsertUTestCase() { _testInsertUTestCase(); } + + function testQuickFractions() { + _testQuickFractions(); + } + } diff --git a/kiss/src/test/cases/BasicTestCase.kiss b/kiss/src/test/cases/BasicTestCase.kiss index 4ee07340..35fbe057 100644 --- a/kiss/src/test/cases/BasicTestCase.kiss +++ b/kiss/src/test/cases/BasicTestCase.kiss @@ -681,3 +681,7 @@ From:[(assert false (+ \"false \" \"should \" \"have \" \"been \" \"true\"))]" m // The test here is that this was inserted by insertUTestCase :) (function _testInsertUTestCase [] (Assert.pass)) + +(function _testQuickFractions [] + (Assert.equals 0.5 (fHalf 1)) + (Assert.equals 0 (iHalf 1)))