diff --git a/packages/squiggle-lang/__tests__/Reducer/Reducer_Peggy/Reducer_Peggy_TestHelpers.res b/packages/squiggle-lang/__tests__/Reducer/Reducer_Peggy/Reducer_Peggy_TestHelpers.res index 44218a4b..39c3492e 100644 --- a/packages/squiggle-lang/__tests__/Reducer/Reducer_Peggy/Reducer_Peggy_TestHelpers.res +++ b/packages/squiggle-lang/__tests__/Reducer/Reducer_Peggy/Reducer_Peggy_TestHelpers.res @@ -25,7 +25,7 @@ let expectToExpressionToBe = (expr, answer, ~v="_", ()) => { ->Result.flatMap(expr => Expression.reduceExpression( expr, - ReducerInterface_DefaultExternalBindings.defaultInternalBindings, + ReducerInterface_StdLib.internalStdLib, ExpressionValue.defaultEnvironment, ) ) diff --git a/packages/squiggle-lang/__tests__/Reducer/Reducer_TestHelpers.res b/packages/squiggle-lang/__tests__/Reducer/Reducer_TestHelpers.res index 092ccc9f..2c7dfb21 100644 --- a/packages/squiggle-lang/__tests__/Reducer/Reducer_TestHelpers.res +++ b/packages/squiggle-lang/__tests__/Reducer/Reducer_TestHelpers.res @@ -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) diff --git a/packages/squiggle-lang/src/rescript/Reducer/Reducer.res b/packages/squiggle-lang/src/rescript/Reducer/Reducer.res index 36fe3cd6..dfedffc7 100644 --- a/packages/squiggle-lang/src/rescript/Reducer/Reducer.res +++ b/packages/squiggle-lang/src/rescript/Reducer/Reducer.res @@ -24,4 +24,4 @@ let foreignFunctionInterface = ( let defaultEnvironment = ExpressionValue.defaultEnvironment -let defaultExternalBindings = ReducerInterface_DefaultExternalBindings.defaultExternalBindings +let defaultExternalBindings = ReducerInterface_StdLib.externalStdLib 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 066a68b2..6b4168c3 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 @@ -116,14 +116,20 @@ let evaluateUsingOptions = ( ~externalBindings: option, code: string, ): result => { - 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 diff --git a/packages/squiggle-lang/src/rescript/ReducerInterface/ReducerInterface_DefaultExternalBindings.res b/packages/squiggle-lang/src/rescript/ReducerInterface/ReducerInterface_DefaultExternalBindings.res deleted file mode 100644 index 2e8abee4..00000000 --- a/packages/squiggle-lang/src/rescript/ReducerInterface/ReducerInterface_DefaultExternalBindings.res +++ /dev/null @@ -1,6 +0,0 @@ -module Bindings = Reducer_Category_Bindings - -let defaultInternalBindings = Bindings.emptyBindings->SquiggleLibrary_Math.makeBindings - -@genType -let defaultExternalBindings = defaultInternalBindings->Bindings.toRecord diff --git a/packages/squiggle-lang/src/rescript/ReducerInterface/ReducerInterface_StdLib.res b/packages/squiggle-lang/src/rescript/ReducerInterface/ReducerInterface_StdLib.res new file mode 100644 index 00000000..f341f9e2 --- /dev/null +++ b/packages/squiggle-lang/src/rescript/ReducerInterface/ReducerInterface_StdLib.res @@ -0,0 +1,6 @@ +module Bindings = Reducer_Category_Bindings + +let internalStdLib = Bindings.emptyBindings->SquiggleLibrary_Math.makeBindings + +@genType +let externalStdLib = internalStdLib->Bindings.toRecord