Skip to content

Commit

Permalink
Fix LessThan and GreaterThan
Browse files Browse the repository at this point in the history
LessThan and GreaterThan now handle their arguments the same as everyone else. Also, fixed a bug where prime.fl would crash when given a 1.
  • Loading branch information
Kansattica committed Jan 21, 2020
1 parent bf040b9 commit 855b4f6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
9 changes: 5 additions & 4 deletions Examples/prime.fl
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
Def(Main).Dup().Concat(|": ").Concat()
\.ParseInt().IsPrime()./
Def(Main).Dup().Concat(|": ").Comment("hi there!").Concat()
\.ParseInt().Dup().GreaterThan(|1).MergeIf()./
\.Comment().IsPrime()./

Def(IsPrime, int n).Dup().Infinite().Comment("endless n").DivMod().Com( ).SwitchIn(false)
\.SqrtIfLarge().CountupR().Comment("")./ \.Equals(|0).Any().Not()./


// the square root thing doesn't work if the numbers are less than 10 or so, so
Def(SqrtIfLarge, int n).Dup().LessThan(11).MergeTop().SwitchIn()
Def(SqrtIfLarge, int n).Dup().LessThan(|11).MergeTop().SwitchIn()
\.Dup().Com("just n")./ Up()./
\.Sqrt().Floor().Add(|1)./

Expand Down Expand Up @@ -39,7 +40,7 @@ Def(CountdownR, int n).Dup().Comment("n-1").Add(|-1).MergeTop()


Def(CountupR, int n).Add(|-1).Dup().Comment("n-1 ").MergeBottom() //Notice that the only difference is using Bottom instead of Top!
\.Dup().LessThan(3).Not().MergeIf()./
\.Dup().LessThan(|3).Not().MergeIf()./
\.CountupR().Comment()./

// these were supposed to be named CountdownRestricted and CountupRestricted, since they returna subset of the "full" count
Expand Down
4 changes: 2 additions & 2 deletions Execution/Execution/Functions/BuiltIn/BuiltInFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ public class BuiltInFactory : IFunctionResolver
{"Sqrt", (_, __) => new WrapUnary<int, double>(a => Math.Sqrt(a), FluencyType.Double, "Sqrt")},
{"Floor", (_, __) => new WrapUnary<double, int>(a => (int)a, FluencyType.Int, "Floor")},
{"Equals", (topArgs, bottomArgs) => new WrapBinary<object, object, bool>((a, b) => a.Equals(b), FluencyType.Any, FluencyType.Bool, "Equals", topArgs, bottomArgs)},
{"LessThan", (topArgs, _) => new WrapBinary<int, int, bool>((a, b) => a < b, FluencyType.Int, FluencyType.Bool, "LessThan", _emptyArgs, topArgs)},
{"GreaterThan", (topArgs, _) => new WrapBinary<int, int, bool>((a, b) => a > b, FluencyType.Int, FluencyType.Bool, "GreaterThan", _emptyArgs, topArgs)},
{"LessThan", (topArgs, bottomArgs) => new WrapBinary<int, int, bool>((a, b) => a < b, FluencyType.Int, FluencyType.Bool, "LessThan", topArgs, bottomArgs)},
{"GreaterThan", (topArgs, bottomArgs) => new WrapBinary<int, int, bool>((a, b) => a > b, FluencyType.Int, FluencyType.Bool, "GreaterThan", topArgs, bottomArgs)},
{"And", (_, __) => new WrapBinary<bool, bool, bool>((a, b) => a && b, FluencyType.Bool, FluencyType.Bool, "And", _emptyArgs)},
{"All", (topArgs, _) => new WrapBinaryFold<bool>((a, b) => a && b, FluencyType.Bool, "All", topArgs, _bools[0])},
{"Or", (_, __) => new WrapBinary<bool, bool, bool>((a, b) => a || b, FluencyType.Bool, FluencyType.Bool, "Or", _emptyArgs)},
Expand Down

0 comments on commit 855b4f6

Please sign in to comment.