From b58ce3a7aab67d915784131d3199eeb0d7fd7886 Mon Sep 17 00:00:00 2001 From: paulklint Date: Mon, 23 Oct 2023 21:54:13 +0200 Subject: [PATCH] Status of Rascal compiler project per October 23, 2023 Status of Rascal compiler project (for the benefit of picking this project up in a few weeks/month) - 12 compiled tests (compiled with interpreted compiler) still fail (see below) - All Rascal test files can be compiled by the compiled Rascal compiler - There are still the following glitches in generated code: - rascal.lang.rascal.tests.functionality.$PatternSet1Tests - rascal.lang.rascal.tests.functionality.$PatternList1Tests - 2 x issues in $ParseTree - 2 x issue rascal.lang.manifest.$IO - 1 x issue in rascal.lang.rascal.tests.concrete.$Syntax3 - In $RascalConfig, $T0 = $TF.nodeType() is not sorted correctly (happens intermittently) - More validation is needed of code generated by the interpreted resp. compiled compiler Finally, the bootstrap is not yet complete: the compiled compiled has not yet compiled itself. 12 compiled tests (compiled with interpreted compiler) that still fail: rascal.lang.rascal.tests.basic.$FunctionsTests curryAConstructor_287A8422_287(rascal.lang.rascal.tests.basic.$FunctionsTests) selfApplyCurry_297A8600_297(rascal.lang.rascal.tests.basic.$FunctionsTests) org.rascalmpl.exceptions.Throw: |TODO:///|: AssertionFailed("") returnOfAnInstantiatedGenericFunction_273A8025_273(rascal.lang.rascal.tests.basic.$FunctionsTests) java.lang.NullPointerException rascal.lang.rascal.tests.basic.$IOTests findResourcesWorks_233A6747_233(rascal.lang.rascal.tests.basic.$IOTests) java.lang.UnsupportedOperationException: Opaque URI schemes are not supported; the scheme-specific part must start with a / character. rascal.lang.rascal.tests.basic.$BooleansTests compositeOrCntBTLast_232A4874_232(rascal.lang.rascal.tests.basic.$BooleansTests) org.opentest4j.AssertionFailedError: expected: but was: shortCircuiting_53A1733_53(rascal.lang.rascal.tests.basic.$BooleansTests) org.opentest4j.AssertionFailedError: expected: but was: rascal.lang.rascal.tests.library.$ValueIOTests textParametrizedAdt3_80A2583_80(rascal.lang.rascal.tests.library.$ValueIOTests) org.opentest4j.AssertionFailedError: expected: but was: textParametrizedAdt2_79A2510_79(rascal.lang.rascal.tests.library.$ValueIOTests) org.opentest4j.AssertionFailedError: expected: but was: rascal.lang.rascal.tests.functionality.$StatementTests fail5_207A5845_207(rascal.lang.rascal.tests.functionality.$StatementTests) org.opentest4j.AssertionFailedError: expected: but was: rascal.lang.rascal.tests.functionality.$PatternSet1Tests matchSetLists8_669A16615_669(rascal.lang.rascal.tests.functionality.$PatternSet1Tests) java.lang.Error: Unresolved compilation problem: This method must return a result of type IBool rascal.lang.rascal.tests.functionality.$PatternList1Tests matchListTuples8_700A13749_700(rascal.lang.rascal.tests.functionality.$PatternList1Tests) java.lang.Error: Unresolved compilation problem: This method must return a result of type IBool rascal.lang.rascal.tests.concrete.$Patterns4Tests optionalNotPresentIsFalse_24A304_24(rascal.lang.rascal.tests.concrete.$Patterns4Tests) org.opentest4j.AssertionFailedError: expected: but was: --- .classpath | 3 +- .settings/org.eclipse.core.resources.prefs | 2 + .../core/library/CompileTestSources.rsc | 10 +- .../lang/rascalcore/compile/Examples/Tst0.rsc | 181 ++--------- .../lang/rascalcore/compile/Examples/Tst2.rsc | 2 +- .../lang/rascalcore/compile/Examples/Tst4.rsc | 29 +- .../lang/rascalcore/compile/Examples/Tst5.rsc | 289 ++++-------------- 7 files changed, 108 insertions(+), 408 deletions(-) diff --git a/.classpath b/.classpath index af39e46d..831ce9a9 100644 --- a/.classpath +++ b/.classpath @@ -8,7 +8,7 @@ - + @@ -36,7 +36,6 @@ - diff --git a/.settings/org.eclipse.core.resources.prefs b/.settings/org.eclipse.core.resources.prefs index 7ec1b20e..4e8aa177 100644 --- a/.settings/org.eclipse.core.resources.prefs +++ b/.settings/org.eclipse.core.resources.prefs @@ -1,5 +1,7 @@ eclipse.preferences.version=1 encoding//src/org/rascalmpl/core/library=UTF-8 +encoding//target/generated-test-resources=UTF-8 +encoding//target/generated-test-sources=UTF-8 encoding/=UTF-8 encoding/src=UTF-8 encoding/test=UTF-8 diff --git a/src/org/rascalmpl/core/library/CompileTestSources.rsc b/src/org/rascalmpl/core/library/CompileTestSources.rsc index b002ee16..8d459715 100644 --- a/src/org/rascalmpl/core/library/CompileTestSources.rsc +++ b/src/org/rascalmpl/core/library/CompileTestSources.rsc @@ -137,9 +137,13 @@ void compileTestSources(PathConfig pcfg) { ignored = ["lang::rascal::tests::concrete::Patterns3" //"lang::rascal::tests::extend_function1::M3" - //"lang::rascal::tests::concrete::Syntax4", - //"lang::rascal::tests::concrete::Syntax5", - //"lang::rascal::tests::concrete::FieldProjectionBug", + //"lang::rascal::tests::concrete::Matching // class cast empty set + //"lang::rascal::tests::concrete::Parsing" // class cast empty set + //"lang::rascal::tests::concrete::Syntax1", //class cast empty set + //"lang::rascal::tests::concrete::Syntax4" // parser generator + //"lang::rascal::tests::concrete::Syntax5" // parser generator + //"lang::rascal::tests::concrete::FieldProjectionBug"// parser generator + //"lang::rascal::tests::concrete::Patterns1" // class cast empty set //"lang::rascal::tests::functionality::Range", //"lang::rascal::tests::concrete::ParameterizedNonTerminals", //"lang::rascal::tests::functionality::Interpolation", // check on muCon arg diff --git a/src/org/rascalmpl/core/library/lang/rascalcore/compile/Examples/Tst0.rsc b/src/org/rascalmpl/core/library/lang/rascalcore/compile/Examples/Tst0.rsc index be8b35fd..d72d73b8 100644 --- a/src/org/rascalmpl/core/library/lang/rascalcore/compile/Examples/Tst0.rsc +++ b/src/org/rascalmpl/core/library/lang/rascalcore/compile/Examples/Tst0.rsc @@ -1,154 +1,33 @@ module lang::rascalcore::compile::Examples::Tst0 -//module lang::rascal::tests::basic::Equality - -import util::Math; -import Set; -import Map; -import Type; -import Node; - -// the only way two values can be equal while their run-time types are not is due to conversion between int, real, rat by `==` -test bool canonicalTypes(&T x, &Y y) = x == y ==> (typeOf(x) == typeOf(y)) || size({typeOf(x), typeOf(y)} & {\int(), \real(), \rat()}) > 1; - -test bool canonicalTypesRegression1() = canonicalTypes(0.0, 0); -test bool canonicalTypesRegression2() = canonicalTypes(0r, 0); -test bool canonicalTypesRegression3() = canonicalTypes(0r, 0.0); - -// values have an equivalence relation -test bool reflexEq1(value x) = x == x; -test bool transEq1(value x, value y, value z) = (x == y && y == z) ==> (x == z); -test bool commutativeEq1(value x, value y) = (x == y) <==> (y == x); - -// the matching operator is also an equivalence relation on values: -test bool reflexEq2(value x) = x := x; -test bool transEq2(value x, value y, value z) = (x := y && y := z) ==> (x := z); -test bool commutativeEq2(value x, value y) = (x := y) <==> (y := x); - -// equality subsumes matching, but we focus on nodes to avoid problems with num coercions of `==`: -test bool allEqualValuesMatch(node a, node b) = a == b ==> a := b; -test bool noMatchImpliesUnequal(node a, node b) = !(a := b) ==> a != b; - -test bool matchIsEqualityModuloKeywordFields(node x, node y) - = (unsetRec(x) == unsetRec(y)) <==> x := y; - -// values have an equivalence relation, and by requiring the arguments to have the same types we may trigger bugs sooner: -test bool transEqSame(&Same x, &Same y, &Same z) = (x == y && y == z) ==> (x == z); -test bool commutativeEqSame(&Same x, &Same y) = (x == y) <==> (y == x); - -// values are partially ordered -test bool reflexLTE(value x) = (x <= x); -test bool antiSymmetricLTE(value x, value y) = (x <= y && y <= x) ==> (x == y); -test bool transLTE(value x, value y, value z) = (x <= y && y <= z) ==> x <= z; - -// values are partially ordered, and by requiring the arguments to have the same type we may trigger bugs sooner: -@Ignore -test bool antiSymmetricLTESame(&Same <: node x , &Same <: node y) = (x <= y && y <= x) ==> (x == y); -test bool transLTESame(&Same <: node x, &Same <: node y, &Same <: node z) = (x <= y && y <= z) ==> x <= z; - -@Ignore -test bool antiSymmetricLTEWithKeywordParamsLt1() = antiSymmetricLTESame(""(), ""(x = 3)); -@Ignore -test bool antiSymmetricLTEWithKeywordParamsLt2() = antiSymmetricLTESame(""(x = 2), ""(x = 3)); -@Ignore -test bool antiSymmetricLTEWithKeywordParamsEq() = antiSymmetricLTESame(""(x = 3), ""(x = 3)); - -// numbers are totally ordered -test bool numTotalLTE1(num x, num y) = x <= y || y <= x; -test bool numAntiSymmetricLTE(num x, num y) = (x <= y && y <= x) ==> (x == y); -test bool numTransLTE(num x, num y, num z) = (x <= y && y <= z) ==> (x <= z); -test bool numValueReflex(num x) { value y = x; return x == y && y == x; } - -// ints are totally ordered -test bool intTotalLTE(int x, int y) = x <= y || y <= x; -test bool intAntiSymmetricLTE(int x, int y) = (x <= y && y <= x) ==> (x == y); -test bool intTransLTE(int x, int y, int z) = (x <= y && y <= z) ==> (x <= z); -test bool intValueReflex(int x) { value y = x; return x == y && y == x; } - -// reals are totally ordered -test bool realTotalLTE(real x, real y) = x <= y || y <= x; -test bool realAntiSymmetricLTE(real x, real y) = (x <= y && y <= x) ==> (x == y); -test bool realTransLTE(real x, real y, real z) = (x <= y && y <= z) ==> (x <= z); -test bool realValueReflex(real x) { value y = x; return x == y && y == x; } - -// rat are totally ordered -test bool ratTotalLTE(rat x, rat y) = x <= y || y <= x; -test bool ratAntiSymmetricLTE(rat x, rat y) = (x <= y && y <= x) ==> (x == y); -test bool ratTransLTE(rat x, rat y, rat z) = (x <= y && y <= z) ==> (x <= z); -test bool ratValueReflex(rat x) { value y = x; return x == y && y == x; } - -// strings are totally ordered -test bool numTotalLTE2(str x, str y) = x <= y || y <= x; -test bool strAntiSymmetricLTE(str x, str y) = (x <= y && y <= x) ==> (x == y); -test bool strTransLTE(str x, str y, str z) = (x <= y && y <= z) ==> x <= z; -test bool strValueReflex(rat x) { value y = x; return x == y && y == x; } - -// lists are partially ordered -test bool listReflexLTE(list[value] x) = (x <= x); -test bool listAntiSymmetricLTE(list[value] x, list[value] y) = (x <= y && y <= x) ==> (x == y); -test bool listTransLTE(list[value] x, list[value] y, list[value] z) = (x <= y && y <= z) ==> x <= z; - -// sets are ordered via sub-set relation -test bool subsetOrdering1(set[value] x, set[value] y) = x <= x + y; -test bool subsetOrdering2(set[value] x, set[value] y) = (x <= y) <==> (x == {} || all(e <- x, e in y)); - -// sets are partially ordered -test bool setReflexLTE1(set[value] x) = (x <= x); -test bool setAntiSymmetricLTE1(set[value] x, set[value] y) = (x <= y && y <= x) ==> (x == y); -test bool setTransLTE1(set[value] x, set[value] y, set[value] z) = (x <= y && y <= z) ==> x <= z; - -// map are ordered via sub-map relation - -/*TODO: - -java.lang.Exception: Test submapOrdering1 failed due to - io.usethesource.vallang.type.IntegerType cannot be cast to io.usethesource.vallang.util.TrieMap$CompactMapNode - -Actual parameters: - map[value, value] =>(true:("":[])) - map[value, value] =>("":0.5741726876359169,true:-405555075,639525932r165438573:233378841r1234953134,"M"(true,|tmp:///|):true,|tmp:///|:|tmp:///g7/J|) - -*/ -test bool submapOrdering1(map[value,value] x, map[value,value] y) = x <= y + x; // remember map join is not commutative - -/*TODO: -java.lang.Exception: failed for arguments: (true:"",-1185257414:"1sn"({""()},"冖񓱍资"(|tmp:///|),-304421973r46873778,["R7jZ"()])) - (true:"",$3632-03-24T14:03:39.476+01:00$:["0Xo","",""],|tmp:///|:$2015-08-06T08:23:51.810+01:00$,|tmp:///R66k|:<"h7"()>) +import ParseTree; + +start syntax A = "a"; +layout WS = [\ \t\n\r]*; + +test bool saveAndRestoreParser() { + storeParsers(#start[A], |memory://test-tmp/parsers.jar|); + p = loadParsers(|memory://test-tmp/parsers.jar|); + + x = p(type(\start(sort("A")), ()), "a", |origin:///|); + y = parse(#start[A], "a", |origin:///|); + + return x == y; // (I) +} + +Tree f(Symbol sym, map[Symbol, Production] rules, str input) + = ParseTree::parse(type(sym, rules), input, |todo:///|); // (II) + +/* A catch22: + How to assign a type to a reified type of the form type(...)? + + My current solution: compute the most specific type for the first argument of type(...). + This assigns type Symbol to x + This accepts (II) but fails for (I) with the message "Comparison not defined on `Symbol` and `start[A]`" + + An alternative solution (suggested by comments Jurgen added in CollectExpression): always return value() + This accepts (I) but fails for (II) with the message: + "Cannot instantiate formal parameter type `type[&T \<: Tree]`: Type parameter `T` should be less than `Tree`, but is bound to `value`" + + The question: how to assign a type to type(...) that accepts both these legal cases. */ -test bool submapOrdering2(map[value,value]x, map[value,value] y) = (x <= y) <==> (x == () || all(e <- x, e in y, eq(y[e], x[e]))); - -// maps are partially ordered -test bool setReflexLTE2(map[value,value] x) = (x <= x); -test bool setAntiSymmetricLTE2(map[value,value] x, map[value,value] y) = (x <= y && y <= x) ==> (x == y); -test bool setTransLTE2(map[value,value] x, map[value,value] y, map[value,value] z) = (x <= y && y <= z) ==> x <= z; - -// locs are partially ordered -test bool locReflexLTE(loc x) = (x <= x); -test bool locAntiSymmetricLTE(loc x, loc y) = (x <= y && y <= x) ==> (x == y); -test bool locTransLTE(loc x, loc y, loc z) = (x <= y && y <= z) ==> x <= z; - -// conversions -test bool intToReal1(int i) = i == toReal(i); -test bool ratToReal1(rat r) = r == toReal(r); -test bool intToReal2(int i) = i <= toReal(i); -test bool ratToReal2(rat r) = r <= toReal(r); -test bool intToReal3(int i) = toReal(i) >= i; -test bool ratToReal3(rat r) = toReal(r) >= r; -test bool lessIntReal(int i) = !(i < toReal(i)); -test bool lessRatReal(int i) = !(i < toReal(i)); - -// set containment -test bool differentElements(int i) = size({i, toReal(i), toRat(i,1)}) == 3; // yes, really 3. -test bool differentElement2(int i, rat r) = i == r ==> size({i,r}) == 2; // yes, really 2. -test bool differentElement3(int i, real r) = i == r ==> size({i,r}) == 2; // yes, really 2. - -// map keys -test bool differentKeys1(int i,real r) = ((i:10,r:20)[toReal(i)]?0) == 0; -test bool differentKeys2(int i,rat r) = ((i:10,r:20)[toRat(i,1)]?0) == 0; -test bool differentKeys3(int i) = size((i:10) + (toRat(i,1):20) + (toReal(i):30)) == 3; - -// == vs eq -test bool eqImpliesEquals(value x, value y) = eq(x,y) ==> (x == y); -test bool nonComparabilityImpliesNonEq(value x, value y) = !comparable(typeOf(x),typeOf(y)) ==> !eq(x,y); -test bool comparabilityImpliesEquivalence(value x, value y) = comparable(typeOf(x),typeOf(y)) ==> (eq(x,y) <==> x == y); - diff --git a/src/org/rascalmpl/core/library/lang/rascalcore/compile/Examples/Tst2.rsc b/src/org/rascalmpl/core/library/lang/rascalcore/compile/Examples/Tst2.rsc index 0f9ed1dd..07ab9e1e 100644 --- a/src/org/rascalmpl/core/library/lang/rascalcore/compile/Examples/Tst2.rsc +++ b/src/org/rascalmpl/core/library/lang/rascalcore/compile/Examples/Tst2.rsc @@ -16,6 +16,6 @@ value main() { |project://typepal/src|], libs = [|lib:///| ] ); - msgs = compile("lang::rascalcore::compile::Examples::Tst5", getRascalCorePathConfig(), getRascalCompilerConfig()); + msgs = compile("lang::rascalcore::compile::Examples::Tst0", getRascalCorePathConfig(), getRascalCompilerConfig()); return msgs; } \ No newline at end of file diff --git a/src/org/rascalmpl/core/library/lang/rascalcore/compile/Examples/Tst4.rsc b/src/org/rascalmpl/core/library/lang/rascalcore/compile/Examples/Tst4.rsc index 8da5f46d..a841df8f 100644 --- a/src/org/rascalmpl/core/library/lang/rascalcore/compile/Examples/Tst4.rsc +++ b/src/org/rascalmpl/core/library/lang/rascalcore/compile/Examples/Tst4.rsc @@ -1,29 +1,8 @@ @bootstrapParser module lang::rascalcore::compile::Examples::Tst4 -import Exception; +import ParseTree; +//import lang::rascalcore::check::AType; -value main(){ //test bool higherOrderFunctionCompatibility1() { - // the parameter function is specific to int - int parameter(int _) { return 0; } - - // the higher order function expects to call the - // parameter function with other things too - int hof(int (value) p, value i) { return p(i); } - - // still this is ok, since functions in Rascal - // are partial. This call should simply succeed: - if (hof(parameter, 1) != 0) { - return false; - } - - // but the next call produces a CallFailed, since - // the parameter function is not defined on strings: - try { - // statically allowed! but dynamically failing - hof(parameter, "string"); - return false; - } - catch CallFailed(_): - return true; -} \ No newline at end of file +//value main() = asubtype(\start(aadt("A",[],contextFreeSyntax())), aadt("Symbol",[],dataSyntax())); +value main() = subtype(\start(sort("A")), adt("Symbol",[])); \ No newline at end of file diff --git a/src/org/rascalmpl/core/library/lang/rascalcore/compile/Examples/Tst5.rsc b/src/org/rascalmpl/core/library/lang/rascalcore/compile/Examples/Tst5.rsc index 9c0973e7..253ef4ab 100644 --- a/src/org/rascalmpl/core/library/lang/rascalcore/compile/Examples/Tst5.rsc +++ b/src/org/rascalmpl/core/library/lang/rascalcore/compile/Examples/Tst5.rsc @@ -1,249 +1,86 @@ module lang::rascalcore::compile::Examples::Tst5 +data B = and(B lhs, B rhs) | or(B lhs, B rhs) | t() | f(); -int twice (int n) = 2 * n; -int triple (int n) = 3 * n; -int dup (int n) = n + n; -str dup (str s) = s + s; - -int trip(int n) = n + n + n; -str trip(str s) = s + s + s; - -test bool twiceTriple1(){ - return (twice o triple)(5) == twice(triple(5)); -} - -test bool twiceTriple2(){ - c = twice o triple; - return c(5) == twice(triple(5)); -} - -test bool dupTriple1(){ - return (dup o triple)(5) == dup(triple(5)); -} - -test bool tripleDup1(){ - return (triple o dup)(5) == triple(dup(5)); -} - -test bool dupTrip1(){ - return (dup o trip)(5) == dup(trip(5)); -} - -//test bool dupTrip2(){ -// c = dup o trip; -// return c(5) == dup(trip(5)); -//} - -//test bool dupTrip3(){ -// c = dup o trip; -// return c("abc") == dup(trip("abc")); -//} - -int fib(0) = 0; -int fib(1) = 1; -default int fib(int n) = fib(n-1) + fib(n-2); - -int fact(0) = 1; -int fact(1) = 1; -default int fact(int n) = n*fact(n-1); -str printResult(int n) = " ; "; -str printResult(str s) = s + s; - -int f(0) = 0; -int f(1) = 1; -default int f(int n) = n + 1; - -int g(0) { fail; } -int g(1) = 1; -default int g(int n) = n + 2; - -test bool factorialFibonacci() { - list[int] inputs = [0,1,2,3,4,5,6,7,8,9]; - list[int] outputs1 = [ fact(fib(i)) | int i <- inputs ]; - list[int] outputs2 = [ (fact o fib)(i) | int i <- inputs ]; - return outputs1 == outputs2; -} - -test bool factorialFibonacciPrint1() { - list[int] inputs = [0,1,2,3,4,5,6,7,8,9]; - list[str] outputs1 = [ printResult(fact(fib(i))) | int i <- inputs ]; - list[str] outputs2 = [ (printResult o fact o fib)(i) | int i <- inputs ]; - - return outputs1 == outputs2; -} - -test bool factorialFibonacciPrint2() { - list[int] inputs = [0,1,2,3,4,5,6,7,8,9]; - list[str] outputs1 = [ printResult(fact(fib(i))) | int i <- inputs ]; - - // associativity check of the 'o' operator - list[str] outputs3 = [ ( (printResult o fact) o fib)(i) | int i <- inputs ]; - return outputs1 == outputs3; -} - -test bool factorialFibonacciPrint3() { - list[int] inputs = [0,1,2,3,4,5,6,7,8,9]; - list[str] outputs1 = [ printResult(fact(fib(i))) | int i <- inputs ]; - - // associativity check of the 'o' operator - - list[str] outputs4 = [ (printResult o (fact o fib))(i) | int i <- inputs ]; - return outputs1 == outputs4; -} - -test bool anonymousFunctionComposition() { - list[int] inputs = [0,1,2,3,4,5,6,7,8,9]; - list[int] outputs1 = [ int (int n) { switch(n) { case 0: return 1; case 1: return 1; case int m: return m*(m-1); default: return -1;} } /* renamed n to m*/ - ( int (int n) { switch(n) { case 0: return 0; case 1: return 1; case int m: return (m-1) + (m-2); default: return -1;} } /* renamed n to m*/ - (i)) - | int i <- inputs ]; - list[int] outputs2 = [ (int (int n) { switch(n) { case 0: return 1; case 1: return 1; case int m: return m*(m-1); default: return -1;} } /* renamed n to m*/ - o int (int n) { switch(n) { case 0: return 0; case 1: return 1; case int m: return (m-1) + (m-2); default: return -1;} }) /* renamed n to m*/ - (i) - | int i <- inputs ]; - return outputs1 == outputs2; -} +value main(){ //test bool curryAConstructor() { + &S(&U) c(&S(&T, &U) f, &T t) = &S (&U u) { + return f(t, u); + }; -test bool composedOverloadedFunctions1() { - return (g o f)(0) == g(f(0)); -} + B (B) f = c(and, t()); -test bool composedOverloadedFunctions2() { - return (g o f)(0) == 2; + return f(t()) == and(t(), t()); } -/* - * The '+' function composition operator - */ - -str h(0) = "0"; -str h(1) = "1"; -default str h(int n) { fail; } +//------------------------------------------ -str i(0) = "1"; -str i(1) = "2"; -default str i(int n) = ""; - -int j0(0) = 0; -int j1(1) = 1; -default int j3(int n) = 2*n; - -default int j4(int n) = 2*n - 1; -int k(int n) { - if(n%2 == 0){ - fail k; - } else { - return 2*n; - } -} - -int l(int n) { - if(n%2 == 0){ - return n*(n-1); - } else { - fail l; - }; -} - -//test bool nonDeterministicChoiceAndNormalComposition11() { -// list[int] inputs = [2,3]; -// list[str] outputs1 = [ i(n) | int n <- inputs ]; -// list[str] outputs2 = [ (h + i)(n) | int n <- inputs ]; -// return outputs1 == outputs2; -//} +//import util::Math; // +//list[&T <: num] abs(list[&T <: num] nums) +// = [abs(n) | n <- nums]; // -//test bool nonDeterministicChoiceAndNormalComposition12() { -// list[int] inputs = [2,3]; -// list[str] outputs1 = [ i(n) | int n <- inputs ]; -// list[str] outputs3 = [ (i + h)(n) | int n <- inputs ]; -// return outputs1 == outputs3; +//(&T<:num) assureRange(&T <: num n, num low, num high) { +// ab = abs(n); +// if (ab >= low && ab <= high) { +// return n; +// } +// if (ab <= high) { +// if (n < 0) { +// return n - low; +// } +// return n + low; +// } +// return makeSmallerThan(n, toInt(high)); //} // -//test bool nonDeterministicChoiceAndNormalComposition13() = -// (h + i)(0) == "0" || (h + i)(0) == "1"; -// -//test bool nonDeterministicChoiceAndNormalComposition14() = -// (h + i)(1) == "1" || (h + i)(1) == "2"; -// -//test bool nonDeterministicChoiceAndNormalComposition15() = -// (i + h)(0) == "0" || (i + h)(0) == "1"; -// -//test bool nonDeterministicChoiceAndNormalComposition16() = -// (i + h)(1) == "1" || (i + h)(1) == "2"; -// -//test bool nonDeterministicChoiceAndNormalComposition21() { -// list[int] inputs = [0,1,2,3,4,5,6,7,8,9,10]; -// list[int] outputs = [ (n%2 == 0) ? n*(n - 1) : 2*n | int n <- inputs ]; -// list[int] outputs1 = [ (k + l)(n) | int n <- inputs ]; +////list[&T <: num] assureRange(list[&T <: num] nums, num low, num high) +//// = [ assureRange(n, low, high) | n <- nums]; // -// return outputs == outputs1; -// } -// -//test bool nonDeterministicChoiceAndNormalComposition22() { -// list[int] inputs = [0,1,2,3,4,5,6,7,8,9,10]; -// list[int] outputs = [ (n%2 == 0) ? n*(n - 1) : 2*n | int n <- inputs ]; -// list[int] outputs2 = [ (l + k)(n) | int n <- inputs ]; -// -// return outputs == outputs2; +//int makeSmallerThanInt(int n, int limit) = n % limit; +//real makeSmallerThanReal(real n, int limit) { +// if (abs(n) < limit) { +// return n; +// } +// f = toInt(n); +// r = n - f; +// return (f % limit) + r; +//} +//rat makeSmallerThanRat(rat n, int limit) { +// if (abs(n) < limit) { +// return n; +// } +// return toRat(1, denominator(n)); //} - -test bool nonDeterministicChoiceAndNormalComposition23() { - list[int] inputs = [0,1,2,3,4,5,6,7,8,9,10]; - list[int] outputs = [ (n%2 == 0) ? n*(n - 1) : 2*n | int n <- inputs ]; - list[int] outputs3 = [ ( (k + l) o (l + k) )(n) | int n <- inputs ]; - list[int] outputs4 = [ n*(n - 1) | int n <- outputs ]; - - return outputs3 == outputs4; -} -// -//test bool nonDeterministicChoiceAndNormalComposition24() { -// list[int] inputs = [0,1,2,3,4,5,6,7,8,9,10]; // -// list[int] outputs5 = [ (j0 + j1 + (k + l) o j3)(n) | int n <- inputs ]; -// list[int] outputs7 = [0,1] + [ 2*n*(2*n - 1) | int n <- inputs - [0,1] ]; -// list[int] outputs9 = [ 2*n*(2*n - 1) | int n <- inputs ]; -// -// return outputs5 == outputs7 || outputs5 == outputs9 ; +//&T <: num makeSmallerThan(&T <: num n, int limit) { +// if (int i := n) { +// return makeSmallerThanInt(i, limit); +// } +// if (real r := n) { +// return makeSmallerThanReal(r, limit); +// } +// if (rat r := n) { +// return makeSmallerThanRat(r, limit); +// } +// throw "Forgot about a different number type "; //} // -//test bool nonDeterministicChoiceAndNormalComposition25() { -// list[int] inputs = [0,1,2,3,4,5,6,7,8,9,10]; -// -// list[int] outputs6 = [ ((k + l) o j4 + j0 + j1)(n) | int n <- inputs ]; -// list[int] outputs8 = [0,1] + [ 2*(2*n-1) | int n <- inputs - [0,1] ]; -// list[int] outputs10 = [ 2*(2*n-1) | int n <- inputs ]; +//list[&T <: num] makeSmallerThan(list[&T <: num] nums, int limit) +// = [ makeSmallerThan(n, limit) | n <- nums]; // -// return outputs6 == outputs8 || outputs6 == outputs10 ; -//} // -//int twiceNotEven(int n) { -// if(n%2 == 0){ -// fail twiceNotEven; -// } else { -// return 2*n; -// } -//} -// -//test bool nonDeterministicChoiceAndNormalComposition26() { -// list[int] inputs = [0,1,2,3,4,5,6,7,8,9,10]; -// -// list[int] outputs8 = [0,1] + [ 2*(2*n-1) | int n <- inputs - [0,1] ]; -// list[int] outputs10 = [ 2*(2*n-1) | int n <- inputs ]; -// list[int] outputs11 = [ (( twiceNotEven + l) o (int (int n) { return 2*n - 1; }) + j0 + j1)(n) | int n <- inputs ]; -// -// return outputs11 == outputs8 || outputs11 == outputs10; -//} +//value main() = assureRange(0, 0.1, 30); + +//------------------------------------------ + +//&T avoidEmpty(list[&T] _) { return 1; } +//&T avoidEmpty(list[&T] _) { throw "this should happen"; } // -//test bool nonDeterministicChoiceAndNormalComposition27() { -// list[int] inputs = [0,1,2,3,4,5,6,7,8,9,10]; -// -// list[int] outputs8 = [0,1] + [ 2*(2*n-1) | int n <- inputs - [0,1] ]; -// list[int] outputs10 = [ 2*(2*n-1) | int n <- inputs ]; -// list[int] outputs11 = [ (( l + twiceNotEven ) o (int (int n) { return 2*n - 1; }) + j0 + j1)(n) | int n <- inputs ]; -// -// return outputs11 == outputs8 || outputs11 == outputs10; +//value main(){ //test bool voidReturnIsNotAllowed() { +// try { +// return avoidEmpty([]); +// } catch "this should happen": +// return true; //}