Catching unreduced values. This is not a lazy language

This commit is contained in:
Umur Ozkul 2022-05-02 15:22:01 +02:00
parent c68138e5f6
commit ba104e4dfe
2 changed files with 9 additions and 3 deletions

View File

@ -33,8 +33,9 @@ describe("Arity check", () => {
describe("function trics", () => { describe("function trics", () => {
testEvalToBe("f(x)=x(y); f(f)", "Error(y is not defined)") 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; f(f)", "Ok(lambda(x=>internal code))")
testEvalToBe("f(x)=x(y); f(z)", "Error(y is not defined)") testEvalToBe("f(x)=x(y); f(z)", "Error(z is not defined)")
MySkip.testEvalToBe("f(x)=x(y); f(2)", "????") //prevent js error 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)=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("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 MySkip.testEvalToBe("y=2;g(x)=y+1;g(2)", "????") //TODO : y is not found

View File

@ -79,7 +79,12 @@ and reduceValueList = (valueList: list<expressionValue>, environment): result<
| list{EvLambda(lamdaCall), ...args} => | list{EvLambda(lamdaCall), ...args} =>
Lambda.doLambdaCall(lamdaCall, args, environment, reduceExpression) 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< let evalUsingBindingsExpression_ = (aExpression, bindings, environment): result<