From 7eef1d30f3f606f679f81c17ad77ddcbbfd9dcb8 Mon Sep 17 00:00:00 2001 From: Umur Ozkul Date: Thu, 1 Sep 2022 14:51:20 +0200 Subject: [PATCH] __result__ variable in bindings --- .../__tests__/ReducerProject/ReducerProject_test.res | 4 +++- .../ReducerProject_tutorial_1_test.res | 8 ++++---- .../ReducerProject_tutorial_2_multisource_test.res | 12 ++++++------ .../ReducerProject_tutorial_3_includes_test.res | 2 +- .../Reducer/Reducer_Bindings/Reducer_Bindings.res | 4 ++++ .../Reducer_Dispatch/Reducer_Dispatch_BuiltIn.res | 2 +- 6 files changed, 19 insertions(+), 13 deletions(-) diff --git a/packages/squiggle-lang/__tests__/ReducerProject/ReducerProject_test.res b/packages/squiggle-lang/__tests__/ReducerProject/ReducerProject_test.res index bbed5633..6b15e04d 100644 --- a/packages/squiggle-lang/__tests__/ReducerProject/ReducerProject_test.res +++ b/packages/squiggle-lang/__tests__/ReducerProject/ReducerProject_test.res @@ -16,7 +16,9 @@ let runFetchResult = (project, sourceId) => { let runFetchFlatBindings = (project, sourceId) => { Project.run(project, sourceId) - Project.getBindings(project, sourceId)->InternalExpressionValue.toStringBindings + Project.getBindings(project, sourceId) + ->Bindings.removeResult + ->InternalExpressionValue.toStringBindings } test("setting continuation", () => { diff --git a/packages/squiggle-lang/__tests__/ReducerProject/ReducerProject_tutorial_1_test.res b/packages/squiggle-lang/__tests__/ReducerProject/ReducerProject_tutorial_1_test.res index d6f43904..92a4932f 100644 --- a/packages/squiggle-lang/__tests__/ReducerProject/ReducerProject_tutorial_1_test.res +++ b/packages/squiggle-lang/__tests__/ReducerProject/ReducerProject_tutorial_1_test.res @@ -46,12 +46,12 @@ Case "Running a single source". Getting None means you have forgotten to run the source. */ let result = project->Project.getResult("main") - let bindings = project->Project.getBindings("main") + let bindings = project->Project.getBindings("main")->Bindings.removeResult /* Let's display the result and bindings */ ( result->InternalExpressionValue.toStringResult, - bindings->InternalExpressionValue.IEvBindings->InternalExpressionValue.toString, + bindings->InternalExpressionValue.toStringBindings, )->expect == ("Ok(3)", "@{}") /* You've got 3 with empty bindings. */ }) @@ -61,7 +61,7 @@ Case "Running a single source". Project.setSource(project, "main", "1 + 2") Project.runAll(project) let result = Project.getResult(project, "main") - let bindings = Project.getBindings(project, "main") + let bindings = Project.getBindings(project, "main")->Bindings.removeResult /* Now you have external bindings and external result. */ ( result->InternalExpressionValue.toStringResult, @@ -89,7 +89,7 @@ Case "Running a single source". let (result, bindings) = Project.evaluate("1+2") ( result->InternalExpressionValue.toStringResult, - bindings->InternalExpressionValue.IEvBindings->InternalExpressionValue.toString, + bindings->Bindings.removeResult->InternalExpressionValue.toStringBindings, )->expect == ("Ok(3)", "@{}") }) }) diff --git a/packages/squiggle-lang/__tests__/ReducerProject/ReducerProject_tutorial_2_multisource_test.res b/packages/squiggle-lang/__tests__/ReducerProject/ReducerProject_tutorial_2_multisource_test.res index 4362fcf6..80c73c9e 100644 --- a/packages/squiggle-lang/__tests__/ReducerProject/ReducerProject_tutorial_2_multisource_test.res +++ b/packages/squiggle-lang/__tests__/ReducerProject/ReducerProject_tutorial_2_multisource_test.res @@ -29,11 +29,11 @@ describe("ReducerProject Tutorial", () => { /* And let's check the result and bindings of source3 */ let result3 = Project.getResult(project, "source3") - let bindings3 = Project.getBindings(project, "source3") + let bindings3 = Project.getBindings(project, "source3")->Bindings.removeResult ( result3->InternalExpressionValue.toStringResult, - bindings3->InternalExpressionValue.IEvBindings->InternalExpressionValue.toString, + bindings3->InternalExpressionValue.toStringBindings, )->expect == ("Ok(())", "@{x: 1,y: 2,z: 3}") }) @@ -55,11 +55,11 @@ describe("ReducerProject Tutorial", () => { /* And let's check the result and bindings of source3 */ let result3 = Project.getResult(project, "source3") - let bindings3 = Project.getBindings(project, "source3") + let bindings3 = Project.getBindings(project, "source3")->Bindings.removeResult ( result3->InternalExpressionValue.toStringResult, - bindings3->InternalExpressionValue.IEvBindings->InternalExpressionValue.toString, + bindings3->InternalExpressionValue.toStringBindings, )->expect == ("Ok(())", "@{x: 1,y: 2,z: 3}") }) @@ -91,11 +91,11 @@ describe("ReducerProject Tutorial", () => { This time you are getting all the variables because we are including the other sources Behind the scenes parseIncludes is setting the dependencies */ let result3 = Project.getResult(project, "source3") - let bindings3 = Project.getBindings(project, "source3") + let bindings3 = Project.getBindings(project, "source3")->Bindings.removeResult ( result3->InternalExpressionValue.toStringResult, - bindings3->InternalExpressionValue.IEvBindings->InternalExpressionValue.toString, + bindings3->InternalExpressionValue.toStringBindings, )->expect == ("Ok(())", "@{x: 1,y: 2,z: 3}") /* Doing it like this is too verbose for a storybook diff --git a/packages/squiggle-lang/__tests__/ReducerProject/ReducerProject_tutorial_3_includes_test.res b/packages/squiggle-lang/__tests__/ReducerProject/ReducerProject_tutorial_3_includes_test.res index b10f1ef6..12c14468 100644 --- a/packages/squiggle-lang/__tests__/ReducerProject/ReducerProject_tutorial_3_includes_test.res +++ b/packages/squiggle-lang/__tests__/ReducerProject/ReducerProject_tutorial_3_includes_test.res @@ -147,7 +147,7 @@ Here we will finally proceed to a real life scenario. */ test("recursive includes", () => { ( result->InternalExpressionValue.toStringResult, - bindings->InternalExpressionValue.IEvBindings->InternalExpressionValue.toString, + bindings->Bindings.removeResult->InternalExpressionValue.toStringBindings, )->expect == ("Ok(6)", "@{doubleX: 2,x: 1,y: 2,z: 3}") /* Everything as expected */ }) diff --git a/packages/squiggle-lang/src/rescript/Reducer/Reducer_Bindings/Reducer_Bindings.res b/packages/squiggle-lang/src/rescript/Reducer/Reducer_Bindings/Reducer_Bindings.res index b1127e05..68bc6c3a 100644 --- a/packages/squiggle-lang/src/rescript/Reducer/Reducer_Bindings/Reducer_Bindings.res +++ b/packages/squiggle-lang/src/rescript/Reducer/Reducer_Bindings/Reducer_Bindings.res @@ -183,3 +183,7 @@ let chainTo = (nameSpace: t, previousNameSpaces: array) => { mergeFrom(prevNameSpace, topNameSpace) ) } + +let removeResult = (NameSpace(container): t): t => { + container->Belt.Map.String.remove("__result__")->NameSpace +} diff --git a/packages/squiggle-lang/src/rescript/Reducer/Reducer_Dispatch/Reducer_Dispatch_BuiltIn.res b/packages/squiggle-lang/src/rescript/Reducer/Reducer_Dispatch/Reducer_Dispatch_BuiltIn.res index 1e8b19d0..bead1a93 100644 --- a/packages/squiggle-lang/src/rescript/Reducer/Reducer_Dispatch/Reducer_Dispatch_BuiltIn.res +++ b/packages/squiggle-lang/src/rescript/Reducer/Reducer_Dispatch/Reducer_Dispatch_BuiltIn.res @@ -104,7 +104,7 @@ let callInternal = ( let doDumpBindings = (continuation: nameSpace, value: internalExpressionValue) => { // let _ = Continuation.inspect(continuation, "doDumpBindings") - accessors.states.continuation = continuation + accessors.states.continuation = continuation->Bindings.set("__result__", value) value->Ok }