From ba104e4dfea682094ddfcfdd8e5cbb9587198d19 Mon Sep 17 00:00:00 2001 From: Umur Ozkul Date: Mon, 2 May 2022 15:22:01 +0200 Subject: [PATCH] Catching unreduced values. This is not a lazy language --- .../__tests__/Reducer/Reducer_functionTricks_test.res | 5 +++-- .../Reducer/Reducer_Expression/Reducer_Expression.res | 7 ++++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/packages/squiggle-lang/__tests__/Reducer/Reducer_functionTricks_test.res b/packages/squiggle-lang/__tests__/Reducer/Reducer_functionTricks_test.res index 23b4eaba..9e3e25c2 100644 --- a/packages/squiggle-lang/__tests__/Reducer/Reducer_functionTricks_test.res +++ b/packages/squiggle-lang/__tests__/Reducer/Reducer_functionTricks_test.res @@ -33,8 +33,9 @@ describe("Arity check", () => { describe("function trics", () => { testEvalToBe("f(x)=x(y); f(f)", "Error(y is not defined)") testEvalToBe("f(x)=x; f(f)", "Ok(lambda(x=>internal code))") - testEvalToBe("f(x)=x(y); f(z)", "Error(y is not defined)") - MySkip.testEvalToBe("f(x)=x(y); f(2)", "????") //prevent js error + testEvalToBe("f(x)=x(y); f(z)", "Error(z is not defined)") + testEvalToBe("f(x)=x(y); f(2)", "Error(y is not defined)") + MySkip.testEvalToBe("f(x)=x(1); f(2)", "????") MySkip.testEvalToBe("f(x)=f(y)=2; f(2)", "????") //prevent multiple assignment MySkip.testEvalToBe("f(x)=x+1; g(x)=f(x)+1;g(2)", "????") //TODO: f is not found MySkip.testEvalToBe("y=2;g(x)=y+1;g(2)", "????") //TODO : y is not found diff --git a/packages/squiggle-lang/src/rescript/Reducer/Reducer_Expression/Reducer_Expression.res b/packages/squiggle-lang/src/rescript/Reducer/Reducer_Expression/Reducer_Expression.res index 5eeb51c7..bb201985 100644 --- a/packages/squiggle-lang/src/rescript/Reducer/Reducer_Expression/Reducer_Expression.res +++ b/packages/squiggle-lang/src/rescript/Reducer/Reducer_Expression/Reducer_Expression.res @@ -79,7 +79,12 @@ and reduceValueList = (valueList: list, environment): result< | list{EvLambda(lamdaCall), ...args} => Lambda.doLambdaCall(lamdaCall, args, environment, reduceExpression) - | _ => valueList->Belt.List.toArray->ExpressionValue.EvArray->Ok + | _ => + valueList + ->Lambda.checkIfReduced + ->Result.flatMap(reducedValueList => + reducedValueList->Belt.List.toArray->ExpressionValue.EvArray->Ok + ) } let evalUsingBindingsExpression_ = (aExpression, bindings, environment): result<