diff --git a/src/kiss/Macros.hx b/src/kiss/Macros.hx index 6bbdb985..83884742 100644 --- a/src/kiss/Macros.hx +++ b/src/kiss/Macros.hx @@ -249,16 +249,21 @@ class Macros { var uniqueVarName = "_" + Uuid.v4().toShort(); var uniqueVarSymbol = Symbol(uniqueVarName).withPosOf(wholeExp); uniqueVarExps.push(uniqueVarSymbol); - bindingList = bindingList.concat([TypedExp("kiss.Operand", uniqueVarSymbol).withPosOf(wholeExp), exp]); + bindingList = bindingList.concat([ + TypedExp("kiss.Operand", uniqueVarSymbol).withPosOf(wholeExp), + CallExp(Symbol("kiss.Operand.fromDynamic").withPosOf(wholeExp), [exp]).withPosOf(wholeExp) + ]); }; CallExp(Symbol("let").withPosOf(wholeExp), [ ListExp(bindingList).withPosOf(wholeExp), - CallExp(Symbol("Lambda.fold").withPosOf(wholeExp), [ - ListExp(uniqueVarExps.slice(1)).withPosOf(wholeExp), - Symbol(func).withPosOf(wholeExp), - uniqueVarExps[0] - ]).withPosOf(wholeExp) + CallExp(Symbol("kiss.Operand.toDynamic").withPosOf(wholeExp), [ + CallExp(Symbol("Lambda.fold").withPosOf(wholeExp), [ + ListExp(uniqueVarExps.slice(1)).withPosOf(wholeExp), + Symbol(func).withPosOf(wholeExp), + uniqueVarExps[0] + ]).withPosOf(wholeExp) + ]).withPosOf(wholeExp), ]).withPosOf(wholeExp); }; } diff --git a/src/kiss/Operand.hx b/src/kiss/Operand.hx index c278cac7..69b93c57 100644 --- a/src/kiss/Operand.hx +++ b/src/kiss/Operand.hx @@ -18,13 +18,21 @@ abstract Operand(Either>) from Either>) from Either { - return switch (this) { - case Right(Left(i)): i; - case Right(Right(f)): f; - case Left(str): str; - } + // This wasn't working as an implicit conversion in conjunction with Lambda.fold() + + /* @:to */ + public static function toDynamic(o:Dynamic):Null { + return if (Std.isOfType(o, Either)) { + var o:Operand = cast o; + switch (o) { + case Right(Left(i)): i; + case Right(Right(f)): f; + case Left(str): str; + }; + } else { + o; + }; } } diff --git a/src/kiss/Prelude.hx b/src/kiss/Prelude.hx index 73575a22..c9ab2067 100644 --- a/src/kiss/Prelude.hx +++ b/src/kiss/Prelude.hx @@ -72,11 +72,11 @@ class Prelude { }; } - public static function mod(bottom:Operand, top:Operand):Operand { + public static function mod(bottom:Operand, top:Operand):Float { return top.toFloat() % bottom.toFloat(); } - public static function pow(exponent:Operand, base:Operand):Operand { + public static function pow(exponent:Operand, base:Operand):Float { return Math.pow(base.toFloat(), exponent.toFloat()); } @@ -97,7 +97,7 @@ class Prelude { } public static function areEqual(a:Operand, b:Operand):Operand { - return if (a.toDynamic() == b.toDynamic()) a else Right(Right(Math.NaN)); + return if (Operand.toDynamic(a) == Operand.toDynamic(b)) a else Right(Right(Math.NaN)); } public static function groups(a:Array, size, keepRemainder = false) { diff --git a/src/kiss/SpecialForms.hx b/src/kiss/SpecialForms.hx index 7c705d44..4fdbd3da 100644 --- a/src/kiss/SpecialForms.hx +++ b/src/kiss/SpecialForms.hx @@ -287,7 +287,7 @@ class SpecialForms { return (wholeExp:ReaderExp, args:Array, k:KissState) -> { var callFoldMacroExpr = k.convert(CallExp(Symbol(func).withPosOf(wholeExp), args).withPosOf(wholeExp)); wholeExp.checkNumArgs(1, null); - EBinop(OpEq, k.convert(args[0]), macro ${callFoldMacroExpr}.toDynamic()).withMacroPosOf(wholeExp); + EBinop(OpEq, k.convert(args[0]), macro kiss.Operand.toDynamic($callFoldMacroExpr)).withMacroPosOf(wholeExp); }; } }