kind of silly - quick fractions
This commit is contained in:
@@ -111,6 +111,24 @@ class Kiss {
|
|||||||
// These work with (apply) because they are added as "opAliases" in Macros.kiss:
|
// These work with (apply) because they are added as "opAliases" in Macros.kiss:
|
||||||
"min" => Symbol("Prelude.min"),
|
"min" => Symbol("Prelude.min"),
|
||||||
"max" => Symbol("Prelude.max"),
|
"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: [
|
identAliases: [
|
||||||
// These ones won't conflict with variables and might commonly be used with (apply)
|
// These ones won't conflict with variables and might commonly be used with (apply)
|
||||||
|
|||||||
@@ -85,6 +85,25 @@ class Macros {
|
|||||||
// These shouldn't be ident aliases because they are common variable names
|
// These shouldn't be ident aliases because they are common variable names
|
||||||
"min" => "Prelude.min",
|
"min" => "Prelude.min",
|
||||||
"max" => "Prelude.max",
|
"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:
|
// These can't be ident aliases because they would supercede the typed call macros that wrap them:
|
||||||
"zip" => "Prelude.zipThrow",
|
"zip" => "Prelude.zipThrow",
|
||||||
"zipThrow" => "Prelude.zipThrow",
|
"zipThrow" => "Prelude.zipThrow",
|
||||||
|
|||||||
@@ -161,6 +161,33 @@ class Prelude {
|
|||||||
public static var lesserEqual:Function = Reflect.makeVarArgs(_comparison.bind("<="));
|
public static var lesserEqual:Function = Reflect.makeVarArgs(_comparison.bind("<="));
|
||||||
public static var areEqual: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<T>(a:Array<T>, ?comp:(T, T) -> Int):kiss.List<T> {
|
public static function sort<T>(a:Array<T>, ?comp:(T, T) -> Int):kiss.List<T> {
|
||||||
if (comp == null)
|
if (comp == null)
|
||||||
comp = Reflect.compare;
|
comp = Reflect.compare;
|
||||||
|
|||||||
@@ -359,6 +359,11 @@ class BasicTestCase extends Test {
|
|||||||
function testInsertUTestCase() {
|
function testInsertUTestCase() {
|
||||||
_testInsertUTestCase();
|
_testInsertUTestCase();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function testQuickFractions() {
|
||||||
|
_testQuickFractions();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -681,3 +681,7 @@ From:[(assert false (+ \"false \" \"should \" \"have \" \"been \" \"true\"))]" m
|
|||||||
// The test here is that this was inserted by insertUTestCase :)
|
// The test here is that this was inserted by insertUTestCase :)
|
||||||
(function _testInsertUTestCase []
|
(function _testInsertUTestCase []
|
||||||
(Assert.pass))
|
(Assert.pass))
|
||||||
|
|
||||||
|
(function _testQuickFractions []
|
||||||
|
(Assert.equals 0.5 (fHalf 1))
|
||||||
|
(Assert.equals 0 (iHalf 1)))
|
||||||
|
|||||||
Reference in New Issue
Block a user