Merge pull request #691 from quantified-uncertainty/reducer-modules

fixes #676, closes #170
This commit is contained in:
Ozzie Gooen 2022-06-13 11:02:20 -07:00 committed by GitHub
commit ae3224b25e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 21 additions and 14 deletions

View File

@ -25,7 +25,7 @@ let expectToExpressionToBe = (expr, answer, ~v="_", ()) => {
->Result.flatMap(expr => ->Result.flatMap(expr =>
Expression.reduceExpression( Expression.reduceExpression(
expr, expr,
ReducerInterface_DefaultExternalBindings.defaultInternalBindings, ReducerInterface_StdLib.internalStdLib,
ExpressionValue.defaultEnvironment, ExpressionValue.defaultEnvironment,
) )
) )

View File

@ -29,6 +29,7 @@ let expectEvalError = (expr: string) =>
let expectEvalBindingsToBe = (expr: string, bindings: Reducer.externalBindings, answer: string) => let expectEvalBindingsToBe = (expr: string, bindings: Reducer.externalBindings, answer: string) =>
Reducer.evaluateUsingOptions(expr, ~externalBindings=Some(bindings), ~environment=None) Reducer.evaluateUsingOptions(expr, ~externalBindings=Some(bindings), ~environment=None)
->Reducer_Helpers.rRemoveDefaults
->ExpressionValue.toStringResult ->ExpressionValue.toStringResult
->expect ->expect
->toBe(answer) ->toBe(answer)

View File

@ -24,4 +24,4 @@ let foreignFunctionInterface = (
let defaultEnvironment = ExpressionValue.defaultEnvironment let defaultEnvironment = ExpressionValue.defaultEnvironment
let defaultExternalBindings = ReducerInterface_DefaultExternalBindings.defaultExternalBindings let defaultExternalBindings = ReducerInterface_StdLib.externalStdLib

View File

@ -116,14 +116,20 @@ let evaluateUsingOptions = (
~externalBindings: option<ReducerInterface_ExpressionValue.externalBindings>, ~externalBindings: option<ReducerInterface_ExpressionValue.externalBindings>,
code: string, code: string,
): result<expressionValue, errorValue> => { ): result<expressionValue, errorValue> => {
let anEnvironment = switch environment { let anEnvironment = Belt.Option.getWithDefault(
| Some(env) => env environment,
| None => ReducerInterface_ExpressionValue.defaultEnvironment ReducerInterface_ExpressionValue.defaultEnvironment,
} )
let anExternalBindings = switch externalBindings { let anExternalBindings = switch externalBindings {
| Some(bindings) => bindings | Some(bindings) => {
| None => ReducerInterface_DefaultExternalBindings.defaultExternalBindings 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 let bindings = anExternalBindings->Bindings.fromExternalBindings

View File

@ -1,6 +0,0 @@
module Bindings = Reducer_Category_Bindings
let defaultInternalBindings = Bindings.emptyBindings->SquiggleLibrary_Math.makeBindings
@genType
let defaultExternalBindings = defaultInternalBindings->Bindings.toRecord

View File

@ -0,0 +1,6 @@
module Bindings = Reducer_Category_Bindings
let internalStdLib = Bindings.emptyBindings->SquiggleLibrary_Math.makeBindings
@genType
let externalStdLib = internalStdLib->Bindings.toRecord