Merge pull request #691 from quantified-uncertainty/reducer-modules
fixes #676, closes #170
This commit is contained in:
commit
ae3224b25e
|
@ -25,7 +25,7 @@ let expectToExpressionToBe = (expr, answer, ~v="_", ()) => {
|
|||
->Result.flatMap(expr =>
|
||||
Expression.reduceExpression(
|
||||
expr,
|
||||
ReducerInterface_DefaultExternalBindings.defaultInternalBindings,
|
||||
ReducerInterface_StdLib.internalStdLib,
|
||||
ExpressionValue.defaultEnvironment,
|
||||
)
|
||||
)
|
||||
|
|
|
@ -29,6 +29,7 @@ let expectEvalError = (expr: string) =>
|
|||
|
||||
let expectEvalBindingsToBe = (expr: string, bindings: Reducer.externalBindings, answer: string) =>
|
||||
Reducer.evaluateUsingOptions(expr, ~externalBindings=Some(bindings), ~environment=None)
|
||||
->Reducer_Helpers.rRemoveDefaults
|
||||
->ExpressionValue.toStringResult
|
||||
->expect
|
||||
->toBe(answer)
|
||||
|
|
|
@ -24,4 +24,4 @@ let foreignFunctionInterface = (
|
|||
|
||||
let defaultEnvironment = ExpressionValue.defaultEnvironment
|
||||
|
||||
let defaultExternalBindings = ReducerInterface_DefaultExternalBindings.defaultExternalBindings
|
||||
let defaultExternalBindings = ReducerInterface_StdLib.externalStdLib
|
||||
|
|
|
@ -116,14 +116,20 @@ let evaluateUsingOptions = (
|
|||
~externalBindings: option<ReducerInterface_ExpressionValue.externalBindings>,
|
||||
code: string,
|
||||
): result<expressionValue, errorValue> => {
|
||||
let anEnvironment = switch environment {
|
||||
| Some(env) => env
|
||||
| None => ReducerInterface_ExpressionValue.defaultEnvironment
|
||||
}
|
||||
let anEnvironment = Belt.Option.getWithDefault(
|
||||
environment,
|
||||
ReducerInterface_ExpressionValue.defaultEnvironment,
|
||||
)
|
||||
|
||||
let anExternalBindings = switch externalBindings {
|
||||
| Some(bindings) => bindings
|
||||
| None => ReducerInterface_DefaultExternalBindings.defaultExternalBindings
|
||||
| Some(bindings) => {
|
||||
let cloneLib = ReducerInterface_StdLib.externalStdLib->Reducer_Category_Bindings.cloneRecord
|
||||
Js.Dict.entries(bindings)->Js.Array2.reduce((acc, (key, value)) => {
|
||||
acc->Js.Dict.set(key, value)
|
||||
acc
|
||||
}, cloneLib)
|
||||
}
|
||||
| None => ReducerInterface_StdLib.externalStdLib
|
||||
}
|
||||
|
||||
let bindings = anExternalBindings->Bindings.fromExternalBindings
|
||||
|
|
|
@ -1,6 +0,0 @@
|
|||
module Bindings = Reducer_Category_Bindings
|
||||
|
||||
let defaultInternalBindings = Bindings.emptyBindings->SquiggleLibrary_Math.makeBindings
|
||||
|
||||
@genType
|
||||
let defaultExternalBindings = defaultInternalBindings->Bindings.toRecord
|
|
@ -0,0 +1,6 @@
|
|||
module Bindings = Reducer_Category_Bindings
|
||||
|
||||
let internalStdLib = Bindings.emptyBindings->SquiggleLibrary_Math.makeBindings
|
||||
|
||||
@genType
|
||||
let externalStdLib = internalStdLib->Bindings.toRecord
|
Loading…
Reference in New Issue
Block a user