Merge branch 'reducer-dev' of github.com:quantified-uncertainty/squiggle into reducer-dev

This commit is contained in:
Sam Nolan 2022-05-02 14:53:32 +00:00
commit 0890607493
4 changed files with 22 additions and 5 deletions

View File

@ -33,10 +33,12 @@ 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(2 is not a function)")
testEvalToBe("f(x)=x(1); f(2)", "Error(2 is not a function)")
MySkip.testParseToBe("f(x)=f(y)=2; 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
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)=inspect(y)+1", "????") //TODO : 666
})

View File

@ -8,6 +8,7 @@ type errorValue =
| REFunctionExpected(string)
| REJavaScriptExn(option<string>, option<string>) // Javascript Exception
| REMacroNotFound(string)
| RENotAFunction(string)
| RERecordPropertyNotFound(string, string)
| RESymbolNotFound(string)
| RESyntaxError(string)
@ -40,6 +41,7 @@ let errorToString = err =>
answer
}
| REMacroNotFound(macro) => `Macro not found: ${macro}`
| RENotAFunction(valueString) => `${valueString} is not a function`
| RERecordPropertyNotFound(msg, index) => `${msg}: ${index}`
| RESymbolNotFound(symbolName) => `${symbolName} is not defined`
| RESyntaxError(desc) => `Syntax Error: ${desc}`

View File

@ -79,7 +79,12 @@ and reduceValueList = (valueList: list<expressionValue>, 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<

View File

@ -1,3 +1,4 @@
module ErrorValue = Reducer_ErrorValue
module ExpressionT = Reducer_Expression_T
module ExpressionValue = ReducerInterface.ExpressionValue
module Result = Belt.Result
@ -67,7 +68,14 @@ and replaceSymbolsOnExpressionList = (bindings, list) => {
}
and replaceSymbolOnValue = (bindings, evValue: expressionValue) =>
switch evValue {
| EvSymbol(symbol) | EvCall(symbol) =>
| EvSymbol(symbol) =>
Belt.Map.String.getWithDefault(bindings, symbol, evValue)->Ok
| EvCall(symbol) =>
Belt.Map.String.getWithDefault(bindings, symbol, evValue)->checkIfCallable
| _ => evValue->Ok
}
and checkIfCallable = (evValue: expressionValue) =>
switch evValue {
| EvCall(_) | EvLambda(_) => evValue->Ok
| _ => ErrorValue.RENotAFunction(ExpressionValue.toString(evValue))->Error
}