From 1557c197a0165de12e2d205bf64129a993183724 Mon Sep 17 00:00:00 2001 From: Umur Ozkul Date: Fri, 20 May 2022 17:11:32 +0200 Subject: [PATCH] renamed internal variables starting with $ so that they are not overriden by $ variables in Squigle --- .../Reducer_Dispatch_BuiltInMacros_test.res | 20 ++++----- .../Reducer_Peggy_Parse_test.res | 42 +++++++++---------- .../Reducer_Peggy_ToExpression_test.res | 38 ++++++++--------- .../Reducer/Reducer_externalBindings_test.res | 2 +- .../Reducer_functionAssignment_test.res | 4 +- .../Reducer/Reducer_functionTricks_test.res | 2 +- .../Reducer_Dispatch_BuiltIn.res | 12 +++--- .../Reducer_Dispatch_BuiltInMacros.res | 12 +++--- .../Reducer_Expression_ExpressionBuilder.res | 2 +- .../Reducer_Peggy_GeneratedParser.js | 10 ++--- .../Reducer_Peggy_GeneratedParser.peggy | 10 ++--- 11 files changed, 77 insertions(+), 77 deletions(-) diff --git a/packages/squiggle-lang/__tests__/Reducer/Reducer_Dispatch/Reducer_Dispatch_BuiltInMacros_test.res b/packages/squiggle-lang/__tests__/Reducer/Reducer_Dispatch/Reducer_Dispatch_BuiltInMacros_test.res index 993eff10..f1acfd3a 100644 --- a/packages/squiggle-lang/__tests__/Reducer/Reducer_Dispatch/Reducer_Dispatch_BuiltInMacros_test.res +++ b/packages/squiggle-lang/__tests__/Reducer/Reducer_Dispatch/Reducer_Dispatch_BuiltInMacros_test.res @@ -19,7 +19,7 @@ describe("bindStatement", () => { testMacro( [], eBindStatement(eBindings([]), exampleStatementY), - "Ok((:$setBindings {} :y 1) context: {})", + "Ok((:$_setBindings_$ {} :y 1) context: {})", ) // Then it answers the bindings for the next statement when reduced testMacroEval([], eBindStatement(eBindings([]), exampleStatementY), "Ok({y: 1})") @@ -27,7 +27,7 @@ describe("bindStatement", () => { testMacro( [], eBindStatement(eBindings([("x", EvNumber(2.))]), exampleStatementX), - "Ok((:$setBindings {x: 2} :y 2) context: {x: 2})", + "Ok((:$_setBindings_$ {x: 2} :y 2) context: {x: 2})", ) // An expression does not return a binding, thus error testMacro([], eBindStatement(eBindings([]), exampleExpression), "Assignment expected") @@ -35,7 +35,7 @@ describe("bindStatement", () => { testMacro( [("z", EvNumber(99.))], eBindStatementDefault(exampleStatementY), - "Ok((:$setBindings {z: 99} :y 1) context: {z: 99})", + "Ok((:$_setBindings_$ {z: 99} :y 1) context: {z: 99})", ) }) @@ -50,7 +50,7 @@ describe("bindExpression", () => { testMacro( [], eBindExpression(eBindings([("x", EvNumber(2.))]), exampleStatementY), - "Ok((:$exportBindings (:$setBindings {x: 2} :y 1)) context: {x: 2})", + "Ok((:$_exportBindings_$ (:$_setBindings_$ {x: 2} :y 1)) context: {x: 2})", ) // Now let's reduce that expression testMacroEval( @@ -71,20 +71,20 @@ describe("block", () => { testMacro([], eBlock(list{exampleExpression}), "Ok((:$$_bindExpression_$$ 1))") testMacroEval([], eBlock(list{exampleExpression}), "Ok(1)") // Block with a single statement - testMacro([], eBlock(list{exampleStatementY}), "Ok((:$$_bindExpression_$$ (:$let :y 1)))") + testMacro([], eBlock(list{exampleStatementY}), "Ok((:$$_bindExpression_$$ (:$_let_$ :y 1)))") testMacroEval([], eBlock(list{exampleStatementY}), "Ok({y: 1})") // Block with a statement and an expression testMacro( [], eBlock(list{exampleStatementY, exampleExpressionY}), - "Ok((:$$_bindExpression_$$ (:$$_bindStatement_$$ (:$let :y 1)) :y))", + "Ok((:$$_bindExpression_$$ (:$$_bindStatement_$$ (:$_let_$ :y 1)) :y))", ) testMacroEval([], eBlock(list{exampleStatementY, exampleExpressionY}), "Ok(1)") // Block with a statement and another statement testMacro( [], eBlock(list{exampleStatementY, exampleStatementZ}), - "Ok((:$$_bindExpression_$$ (:$$_bindStatement_$$ (:$let :y 1)) (:$let :z :y)))", + "Ok((:$$_bindExpression_$$ (:$$_bindStatement_$$ (:$_let_$ :y 1)) (:$_let_$ :z :y)))", ) testMacroEval([], eBlock(list{exampleStatementY, exampleStatementZ}), "Ok({y: 1,z: 1})") // Block inside a block @@ -98,7 +98,7 @@ describe("block", () => { testMacro( [], eBlock(list{eLetStatement("z", eBlock(list{eBlock(list{exampleExpressionY})}))}), - "Ok((:$$_bindExpression_$$ (:$let :z (:$$_block_$$ (:$$_block_$$ :y)))))", + "Ok((:$$_bindExpression_$$ (:$_let_$ :z (:$$_block_$$ (:$$_block_$$ :y)))))", ) testMacroEval( [], @@ -107,7 +107,7 @@ describe("block", () => { ) // Empty block testMacro([], eBlock(list{}), "Ok(:undefined block)") //TODO: should be an error - // :$$_block_$$ (:$$_block_$$ (:$let :y (:add :x 1)) :y)" + // :$$_block_$$ (:$$_block_$$ (:$_let_$ :y (:add :x 1)) :y)" testMacro( [], eBlock(list{ @@ -116,7 +116,7 @@ describe("block", () => { eSymbol("y"), }), }), - "Ok((:$$_bindExpression_$$ (:$$_block_$$ (:$let :y (:add :x 1)) :y)))", + "Ok((:$$_bindExpression_$$ (:$$_block_$$ (:$_let_$ :y (:add :x 1)) :y)))", ) testMacroEval( [("x", EvNumber(1.))], diff --git a/packages/squiggle-lang/__tests__/Reducer/Reducer_Peggy/Reducer_Peggy_Parse_test.res b/packages/squiggle-lang/__tests__/Reducer/Reducer_Peggy/Reducer_Peggy_Parse_test.res index 84957dff..3c2381cb 100644 --- a/packages/squiggle-lang/__tests__/Reducer/Reducer_Peggy/Reducer_Peggy_Parse_test.res +++ b/packages/squiggle-lang/__tests__/Reducer/Reducer_Peggy/Reducer_Peggy_Parse_test.res @@ -49,8 +49,8 @@ describe("Peggy parse", () => { testParse("-1", "{(::unaryMinus 1)}") testParse("!true", "{(::not true)}") testParse("1 + -1", "{(::add 1 (::unaryMinus 1))}") - testParse("-a[0]", "{(::unaryMinus (::$atIndex :a 0))}") - testParse("!a[0]", "{(::not (::$atIndex :a 0))}") + testParse("-a[0]", "{(::unaryMinus (::$_atIndex_$ :a 0))}") + testParse("!a[0]", "{(::not (::$_atIndex_$ :a 0))}") }) describe("multiplicative", () => { @@ -75,7 +75,7 @@ describe("Peggy parse", () => { "1 * 2 - 3 * 4^5^6", "{(::subtract (::multiply 1 2) (::multiply 3 (::pow (::pow 4 5) 6)))}", ) - testParse("1 * -a[-2]", "{(::multiply 1 (::unaryMinus (::$atIndex :a (::unaryMinus 2))))}") + testParse("1 * -a[-2]", "{(::multiply 1 (::unaryMinus (::$_atIndex_$ :a (::unaryMinus 2))))}") }) describe("multi-line", () => { @@ -95,23 +95,23 @@ describe("Peggy parse", () => { }) describe("arrays", () => { - testParse("[]", "{(::$constructArray ())}") - testParse("[0, 1, 2]", "{(::$constructArray (0 1 2))}") - testParse("['hello', 'world']", "{(::$constructArray ('hello' 'world'))}") - testParse("([0,1,2])[1]", "{(::$atIndex (::$constructArray (0 1 2)) 1)}") + testParse("[]", "{(::$_constructArray_$ ())}") + testParse("[0, 1, 2]", "{(::$_constructArray_$ (0 1 2))}") + testParse("['hello', 'world']", "{(::$_constructArray_$ ('hello' 'world'))}") + testParse("([0,1,2])[1]", "{(::$_atIndex_$ (::$_constructArray_$ (0 1 2)) 1)}") }) describe("records", () => { - testParse("{a: 1, b: 2}", "{(::$constructRecord ('a': 1 'b': 2))}") - testParse("{1+0: 1, 2+0: 2}", "{(::$constructRecord ((::add 1 0): 1 (::add 2 0): 2))}") // key can be any expression - testParse("record.property", "{(::$atIndex :record 'property')}") + testParse("{a: 1, b: 2}", "{(::$_constructRecord_$ ('a': 1 'b': 2))}") + testParse("{1+0: 1, 2+0: 2}", "{(::$_constructRecord_$ ((::add 1 0): 1 (::add 2 0): 2))}") // key can be any expression + testParse("record.property", "{(::$_atIndex_$ :record 'property')}") }) describe("post operators", () => { //function call, array and record access are post operators with higher priority than unary operators testParse("a==!b(1)", "{(::equal :a (::not (::b 1)))}") - testParse("a==!b[1]", "{(::equal :a (::not (::$atIndex :b 1)))}") - testParse("a==!b.one", "{(::equal :a (::not (::$atIndex :b 'one')))}") + testParse("a==!b[1]", "{(::equal :a (::not (::$_atIndex_$ :b 1)))}") + testParse("a==!b.one", "{(::equal :a (::not (::$_atIndex_$ :b 'one')))}") }) describe("comments", () => { @@ -158,8 +158,8 @@ describe("Peggy parse", () => { testParse("a && b<=c || d", "{(::or (::and :a (::smallerEq :b :c)) :d)}") testParse("a && b>c || d", "{(::or (::and :a (::larger :b :c)) :d)}") testParse("a && b { describe("pipe", () => { testParse("1 -> add(2)", "{(::add 1 2)}") testParse("-1 -> add(2)", "{(::add (::unaryMinus 1) 2)}") - testParse("-a[1] -> add(2)", "{(::add (::unaryMinus (::$atIndex :a 1)) 2)}") + testParse("-a[1] -> add(2)", "{(::add (::unaryMinus (::$_atIndex_$ :a 1)) 2)}") testParse("-f(1) -> add(2)", "{(::add (::unaryMinus (::f 1)) 2)}") testParse("1 + 2 -> add(3)", "{(::add 1 (::add 2 3))}") testParse("1 -> add(2) * 3", "{(::multiply (::add 1 2) 3)}") @@ -198,11 +198,11 @@ describe("Peggy parse", () => { testParse("-1 to -2", "{(::credibleIntervalToDistribution (::unaryMinus 1) (::unaryMinus 2))}") // lower than unary testParse( "a[1] to a[2]", - "{(::credibleIntervalToDistribution (::$atIndex :a 1) (::$atIndex :a 2))}", + "{(::credibleIntervalToDistribution (::$_atIndex_$ :a 1) (::$_atIndex_$ :a 2))}", ) // lower than post testParse( "a.p1 to a.p2", - "{(::credibleIntervalToDistribution (::$atIndex :a 'p1') (::$atIndex :a 'p2'))}", + "{(::credibleIntervalToDistribution (::$_atIndex_$ :a 'p1') (::$_atIndex_$ :a 'p2'))}", ) // lower than post testParse("1 to 2 + 3", "{(::add (::credibleIntervalToDistribution 1 2) 3)}") // higher than binary operators testParse( @@ -231,21 +231,21 @@ describe("Peggy parse", () => { ) testParse( "myadd(x,y)=x+y; z=[myadd]; z", - "{:myadd = {|:x,:y| {(::add :x :y)}}; :z = {(::$constructArray (:myadd))}; :z}", + "{:myadd = {|:x,:y| {(::add :x :y)}}; :z = {(::$_constructArray_$ (:myadd))}; :z}", ) testParse( "myaddd(x,y)=x+y; z={x: myaddd}; z", - "{:myaddd = {|:x,:y| {(::add :x :y)}}; :z = {(::$constructRecord ('x': :myaddd))}; :z}", + "{:myaddd = {|:x,:y| {(::add :x :y)}}; :z = {(::$_constructRecord_$ ('x': :myaddd))}; :z}", ) testParse("f({|x| x+1})", "{(::f {|:x| {(::add :x 1)}})}") testParse("map(arr, {|x| x+1})", "{(::map :arr {|:x| {(::add :x 1)}})}") testParse( "map([1,2,3], {|x| x+1})", - "{(::map (::$constructArray (1 2 3)) {|:x| {(::add :x 1)}})}", + "{(::map (::$_constructArray_$ (1 2 3)) {|:x| {(::add :x 1)}})}", ) testParse( "[1,2,3]->map({|x| x+1})", - "{(::map (::$constructArray (1 2 3)) {|:x| {(::add :x 1)}})}", + "{(::map (::$_constructArray_$ (1 2 3)) {|:x| {(::add :x 1)}})}", ) }) }) diff --git a/packages/squiggle-lang/__tests__/Reducer/Reducer_Peggy/Reducer_Peggy_ToExpression_test.res b/packages/squiggle-lang/__tests__/Reducer/Reducer_Peggy/Reducer_Peggy_ToExpression_test.res index 9e857db5..2c676c8f 100644 --- a/packages/squiggle-lang/__tests__/Reducer/Reducer_Peggy/Reducer_Peggy_ToExpression_test.res +++ b/packages/squiggle-lang/__tests__/Reducer/Reducer_Peggy/Reducer_Peggy_ToExpression_test.res @@ -53,48 +53,48 @@ describe("Peggy to Expression", () => { testToExpression("-1", "(:$$_block_$$ (:unaryMinus 1))", ~v="-1", ()) testToExpression("!true", "(:$$_block_$$ (:not true))", ~v="false", ()) testToExpression("1 + -1", "(:$$_block_$$ (:add 1 (:unaryMinus 1)))", ~v="0", ()) - testToExpression("-a[0]", "(:$$_block_$$ (:unaryMinus (:$atIndex :a 0)))", ()) + testToExpression("-a[0]", "(:$$_block_$$ (:unaryMinus (:$_atIndex_$ :a 0)))", ()) }) describe("multi-line", () => { - testToExpression("x=1; 2", "(:$$_block_$$ (:$let :x (:$$_block_$$ 1)) 2)", ~v="2", ()) + testToExpression("x=1; 2", "(:$$_block_$$ (:$_let_$ :x (:$$_block_$$ 1)) 2)", ~v="2", ()) testToExpression( "x=1; y=2", - "(:$$_block_$$ (:$let :x (:$$_block_$$ 1)) (:$let :y (:$$_block_$$ 2)))", + "(:$$_block_$$ (:$_let_$ :x (:$$_block_$$ 1)) (:$_let_$ :y (:$$_block_$$ 2)))", ~v="{x: 1,y: 2}", (), ) }) describe("variables", () => { - testToExpression("x = 1", "(:$$_block_$$ (:$let :x (:$$_block_$$ 1)))", ~v="{x: 1}", ()) + testToExpression("x = 1", "(:$$_block_$$ (:$_let_$ :x (:$$_block_$$ 1)))", ~v="{x: 1}", ()) testToExpression("x", "(:$$_block_$$ :x)", ~v=":x", ()) //TODO: value should return error - testToExpression("x = 1; x", "(:$$_block_$$ (:$let :x (:$$_block_$$ 1)) :x)", ~v="1", ()) + testToExpression("x = 1; x", "(:$$_block_$$ (:$_let_$ :x (:$$_block_$$ 1)) :x)", ~v="1", ()) }) describe("functions", () => { testToExpression( "identity(x) = x", - "(:$$_block_$$ (:$let :identity (:$$_lambda_$$ [x] (:$$_block_$$ :x))))", + "(:$$_block_$$ (:$_let_$ :identity (:$$_lambda_$$ [x] (:$$_block_$$ :x))))", ~v="{identity: lambda(x=>internal code)}", (), ) // Function definitions become lambda assignments testToExpression("identity(x)", "(:$$_block_$$ (:identity :x))", ()) // Note value returns error properly - testToExpression("f(x) = x> 2 ? 0 : 1; f(3)", "(:$$_block_$$ (:$let :f (:$$_lambda_$$ [x] (:$$_block_$$ (:$$_ternary_$$ (:larger :x 2) 0 1)))) (:f 3))", ~v="0", ()) + testToExpression("f(x) = x> 2 ? 0 : 1; f(3)", "(:$$_block_$$ (:$_let_$ :f (:$$_lambda_$$ [x] (:$$_block_$$ (:$$_ternary_$$ (:larger :x 2) 0 1)))) (:f 3))", ~v="0", ()) }) describe("arrays", () => { - testToExpression("[]", "(:$$_block_$$ (:$constructArray ()))", ~v="[]", ()) - testToExpression("[0, 1, 2]", "(:$$_block_$$ (:$constructArray (0 1 2)))", ~v="[0,1,2]", ()) + testToExpression("[]", "(:$$_block_$$ (:$_constructArray_$ ()))", ~v="[]", ()) + testToExpression("[0, 1, 2]", "(:$$_block_$$ (:$_constructArray_$ (0 1 2)))", ~v="[0,1,2]", ()) testToExpression( "['hello', 'world']", - "(:$$_block_$$ (:$constructArray ('hello' 'world')))", + "(:$$_block_$$ (:$_constructArray_$ ('hello' 'world')))", ~v="['hello','world']", (), ) testToExpression( "([0,1,2])[1]", - "(:$$_block_$$ (:$atIndex (:$constructArray (0 1 2)) 1))", + "(:$$_block_$$ (:$_atIndex_$ (:$_constructArray_$ (0 1 2)) 1))", ~v="1", (), ) @@ -103,19 +103,19 @@ describe("Peggy to Expression", () => { describe("records", () => { testToExpression( "{a: 1, b: 2}", - "(:$$_block_$$ (:$constructRecord (('a' 1) ('b' 2))))", + "(:$$_block_$$ (:$_constructRecord_$ (('a' 1) ('b' 2))))", ~v="{a: 1,b: 2}", (), ) testToExpression( "{1+0: 1, 2+0: 2}", - "(:$$_block_$$ (:$constructRecord (((:add 1 0) 1) ((:add 2 0) 2))))", + "(:$$_block_$$ (:$_constructRecord_$ (((:add 1 0) 1) ((:add 2 0) 2))))", (), ) // key can be any expression - testToExpression("record.property", "(:$$_block_$$ (:$atIndex :record 'property'))", ()) + testToExpression("record.property", "(:$$_block_$$ (:$_atIndex_$ :record 'property'))", ()) testToExpression( "record={property: 1}; record.property", - "(:$$_block_$$ (:$let :record (:$$_block_$$ (:$constructRecord (('property' 1))))) (:$atIndex :record 'property'))", + "(:$$_block_$$ (:$_let_$ :record (:$$_block_$$ (:$_constructRecord_$ (('property' 1))))) (:$_atIndex_$ :record 'property'))", ~v="1", (), ) @@ -180,7 +180,7 @@ describe("Peggy to Expression", () => { // Like lambdas they have a local scope. testToExpression( "y=99; x={y=1; y}", - "(:$$_block_$$ (:$let :y (:$$_block_$$ 99)) (:$let :x (:$$_block_$$ (:$let :y (:$$_block_$$ 1)) :y)))", + "(:$$_block_$$ (:$_let_$ :y (:$$_block_$$ 99)) (:$_let_$ :x (:$$_block_$$ (:$_let_$ :y (:$$_block_$$ 1)) :y)))", ~v="{x: 1,y: 99}", (), ) @@ -196,19 +196,19 @@ describe("Peggy to Expression", () => { ) testToExpression( "f={|x| x}", - "(:$$_block_$$ (:$let :f (:$$_block_$$ (:$$_lambda_$$ [x] (:$$_block_$$ :x)))))", + "(:$$_block_$$ (:$_let_$ :f (:$$_block_$$ (:$$_lambda_$$ [x] (:$$_block_$$ :x)))))", ~v="{f: lambda(x=>internal code)}", (), ) testToExpression( "f(x)=x", - "(:$$_block_$$ (:$let :f (:$$_lambda_$$ [x] (:$$_block_$$ :x))))", + "(:$$_block_$$ (:$_let_$ :f (:$$_lambda_$$ [x] (:$$_block_$$ :x))))", ~v="{f: lambda(x=>internal code)}", (), ) // Function definitions are lambda assignments testToExpression( "f(x)=x ? 1 : 0", - "(:$$_block_$$ (:$let :f (:$$_lambda_$$ [x] (:$$_block_$$ (:$$_ternary_$$ :x 1 0)))))", + "(:$$_block_$$ (:$_let_$ :f (:$$_lambda_$$ [x] (:$$_block_$$ (:$$_ternary_$$ :x 1 0)))))", ~v="{f: lambda(x=>internal code)}", (), ) diff --git a/packages/squiggle-lang/__tests__/Reducer/Reducer_externalBindings_test.res b/packages/squiggle-lang/__tests__/Reducer/Reducer_externalBindings_test.res index b780a537..c47879b3 100644 --- a/packages/squiggle-lang/__tests__/Reducer/Reducer_externalBindings_test.res +++ b/packages/squiggle-lang/__tests__/Reducer/Reducer_externalBindings_test.res @@ -5,7 +5,7 @@ open Reducer_TestHelpers describe("Eval with Bindings", () => { testEvalBindingsToBe("x", list{("x", ExpressionValue.EvNumber(1.))}, "Ok(1)") testEvalBindingsToBe("x+1", list{("x", ExpressionValue.EvNumber(1.))}, "Ok(2)") - testParseToBe("y = x+1; y", "Ok((:$$_block_$$ (:$let :y (:$$_block_$$ (:add :x 1))) :y))") + testParseToBe("y = x+1; y", "Ok((:$$_block_$$ (:$_let_$ :y (:$$_block_$$ (:add :x 1))) :y))") testEvalBindingsToBe("y = x+1; y", list{("x", ExpressionValue.EvNumber(1.))}, "Ok(2)") testEvalBindingsToBe("y = x+1", list{("x", ExpressionValue.EvNumber(1.))}, "Ok({x: 1,y: 2})") }) diff --git a/packages/squiggle-lang/__tests__/Reducer/Reducer_functionAssignment_test.res b/packages/squiggle-lang/__tests__/Reducer/Reducer_functionAssignment_test.res index 6dacbdd2..2bd1498a 100644 --- a/packages/squiggle-lang/__tests__/Reducer/Reducer_functionAssignment_test.res +++ b/packages/squiggle-lang/__tests__/Reducer/Reducer_functionAssignment_test.res @@ -2,8 +2,8 @@ open Jest open Reducer_TestHelpers describe("Parse function assignment", () => { - testParseToBe("f(x)=x", "Ok((:$$_block_$$ (:$let :f (:$$_lambda_$$ [x] (:$$_block_$$ :x)))))") - testParseToBe("f(x)=2*x", "Ok((:$$_block_$$ (:$let :f (:$$_lambda_$$ [x] (:$$_block_$$ (:multiply 2 :x))))))") + testParseToBe("f(x)=x", "Ok((:$$_block_$$ (:$_let_$ :f (:$$_lambda_$$ [x] (:$$_block_$$ :x)))))") + testParseToBe("f(x)=2*x", "Ok((:$$_block_$$ (:$_let_$ :f (:$$_lambda_$$ [x] (:$$_block_$$ (:multiply 2 :x))))))") //MathJs does not allow blocks in function definitions }) diff --git a/packages/squiggle-lang/__tests__/Reducer/Reducer_functionTricks_test.res b/packages/squiggle-lang/__tests__/Reducer/Reducer_functionTricks_test.res index 2a82f510..ba29e920 100644 --- a/packages/squiggle-lang/__tests__/Reducer/Reducer_functionTricks_test.res +++ b/packages/squiggle-lang/__tests__/Reducer/Reducer_functionTricks_test.res @@ -51,7 +51,7 @@ describe("call and bindings", () => { ) testParseToBe( "f=99; g(x)=f; g(2)", - "Ok((:$$_block_$$ (:$let :f (:$$_block_$$ 99)) (:$let :g (:$$_lambda_$$ [x] (:$$_block_$$ :f))) (:g 2)))", + "Ok((:$$_block_$$ (:$_let_$ :f (:$$_block_$$ 99)) (:$_let_$ :g (:$$_lambda_$$ [x] (:$$_block_$$ :f))) (:g 2)))", ) testEvalToBe("f=99; g(x)=f; g(2)", "Ok(99)") testEvalToBe("f(x)=x; g(x)=f(x); g(2)", "Ok(2)") 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 4a47b49a..203d2c37 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 @@ -130,12 +130,12 @@ let callInternal = (call: functionCall, environment, reducer: ExpressionT.reduce } switch call { - | ("$atIndex", [EvArray(aValueArray), EvNumber(fIndex)]) => arrayAtIndex(aValueArray, fIndex) - | ("$atIndex", [EvRecord(dict), EvString(sIndex)]) => recordAtIndex(dict, sIndex) - | ("$constructArray", [EvArray(aValueArray)]) => EvArray(aValueArray)->Ok - | ("$constructRecord", [EvArray(arrayOfPairs)]) => constructRecord(arrayOfPairs) - | ("$exportBindings", [EvRecord(externalBindings)]) => doExportBindings(externalBindings) - | ("$setBindings", [EvRecord(externalBindings), EvSymbol(symbol), value]) => + | ("$_atIndex_$", [EvArray(aValueArray), EvNumber(fIndex)]) => arrayAtIndex(aValueArray, fIndex) + | ("$_atIndex_$", [EvRecord(dict), EvString(sIndex)]) => recordAtIndex(dict, sIndex) + | ("$_constructArray_$", [EvArray(aValueArray)]) => EvArray(aValueArray)->Ok + | ("$_constructRecord_$", [EvArray(arrayOfPairs)]) => constructRecord(arrayOfPairs) + | ("$_exportBindings_$", [EvRecord(externalBindings)]) => doExportBindings(externalBindings) + | ("$_setBindings_$", [EvRecord(externalBindings), EvSymbol(symbol), value]) => doSetBindings(externalBindings, symbol, value) | ("inspect", [value, EvString(label)]) => inspectLabel(value, label) | ("inspect", [value]) => inspect(value) diff --git a/packages/squiggle-lang/src/rescript/Reducer/Reducer_Dispatch/Reducer_Dispatch_BuiltInMacros.res b/packages/squiggle-lang/src/rescript/Reducer/Reducer_Dispatch/Reducer_Dispatch_BuiltInMacros.res index 12fb7ddc..f0fd08b3 100644 --- a/packages/squiggle-lang/src/rescript/Reducer/Reducer_Dispatch/Reducer_Dispatch_BuiltInMacros.res +++ b/packages/squiggle-lang/src/rescript/Reducer/Reducer_Dispatch/Reducer_Dispatch_BuiltInMacros.res @@ -25,7 +25,7 @@ let dispatchMacroCall = ( ): result => { let doBindStatement = (bindingExpr: expression, statement: expression, environment) => switch statement { - | ExpressionT.EList(list{ExpressionT.EValue(EvCall("$let")), symbolExpr, statement}) => { + | ExpressionT.EList(list{ExpressionT.EValue(EvCall("$_let_$")), symbolExpr, statement}) => { let rExternalBindingsValue = reduceExpression(bindingExpr, bindings, environment) rExternalBindingsValue->Result.flatMap(externalBindingsValue => { @@ -34,7 +34,7 @@ let dispatchMacroCall = ( // Js.log( // `bindStatement ${Bindings.toString(newBindings)}<==${ExpressionT.toString( // bindingExpr, - // )} statement: $let ${ExpressionT.toString(symbolExpr)}=${ExpressionT.toString( + // )} statement: $_let_$ ${ExpressionT.toString(symbolExpr)}=${ExpressionT.toString( // statement, // )}`, // ) @@ -43,7 +43,7 @@ let dispatchMacroCall = ( rNewStatement->Result.map(newStatement => ExpressionWithContext.withContext( eFunction( - "$setBindings", + "$_setBindings_$", list{newBindings->Bindings.toExternalBindings->eRecord, symbolExpr, newStatement}, ), newBindings, @@ -59,7 +59,7 @@ let dispatchMacroCall = ( errorValue, > => switch statement { - | ExpressionT.EList(list{ExpressionT.EValue(EvCall("$let")), symbolExpr, statement}) => { + | ExpressionT.EList(list{ExpressionT.EValue(EvCall("$_let_$")), symbolExpr, statement}) => { let rExternalBindingsValue = reduceExpression(bindingExpr, bindings, environment) rExternalBindingsValue->Result.flatMap(externalBindingsValue => { @@ -68,10 +68,10 @@ let dispatchMacroCall = ( rNewStatement->Result.map(newStatement => ExpressionWithContext.withContext( eFunction( - "$exportBindings", + "$_exportBindings_$", list{ eFunction( - "$setBindings", + "$_setBindings_$", list{ newBindings->Bindings.toExternalBindings->eRecord, symbolExpr, diff --git a/packages/squiggle-lang/src/rescript/Reducer/Reducer_Expression/Reducer_Expression_ExpressionBuilder.res b/packages/squiggle-lang/src/rescript/Reducer/Reducer_Expression/Reducer_Expression_ExpressionBuilder.res index 761dc901..cdf3425b 100644 --- a/packages/squiggle-lang/src/rescript/Reducer/Reducer_Expression/Reducer_Expression_ExpressionBuilder.res +++ b/packages/squiggle-lang/src/rescript/Reducer/Reducer_Expression/Reducer_Expression_ExpressionBuilder.res @@ -51,7 +51,7 @@ let eList = (list: list): expression => list->BExpressionT.EList let eBlock = (exprs: list): expression => eFunction("$$_block_$$", exprs) let eLetStatement = (symbol: string, valueExpression: expression): expression => - eFunction("$let", list{eSymbol(symbol), valueExpression}) + eFunction("$_let_$", list{eSymbol(symbol), valueExpression}) let eBindStatement = (bindingExpr: expression, letStatement: expression): expression => eFunction("$$_bindStatement_$$", list{bindingExpr, letStatement}) diff --git a/packages/squiggle-lang/src/rescript/Reducer/Reducer_Peggy/Reducer_Peggy_GeneratedParser.js b/packages/squiggle-lang/src/rescript/Reducer/Reducer_Peggy/Reducer_Peggy_GeneratedParser.js index f6608aa6..c797ff15 100644 --- a/packages/squiggle-lang/src/rescript/Reducer/Reducer_Peggy/Reducer_Peggy_GeneratedParser.js +++ b/packages/squiggle-lang/src/rescript/Reducer/Reducer_Peggy/Reducer_Peggy_GeneratedParser.js @@ -35,9 +35,9 @@ } var postOperatorToFunction = { - '.': '$atIndex', + '.': '$_atIndex_$', '()': '$$_applyAll_$$', - '[]': '$atIndex', + '[]': '$_atIndex_$', } function nodeBlock(statements) {return{type: 'Block', statements: statements}} @@ -405,9 +405,9 @@ function peg$parse(input, options) { var peg$f29 = function(args, statements, finalExpression) { statements.push(finalExpression) return nodeLambda(args, nodeBlock(statements)) }; var peg$f30 = function(args, finalExpression) { return nodeLambda(args, nodeBlock([finalExpression])) }; - var peg$f31 = function() { return makeFunctionCall('$constructArray', [nodeExpression([])])}; - var peg$f32 = function(args) { return makeFunctionCall('$constructArray', [nodeExpression(args)])}; - var peg$f33 = function(args) { return makeFunctionCall('$constructRecord', [nodeExpression(args)])}; + var peg$f31 = function() { return makeFunctionCall('$_constructArray_$', [nodeExpression([])])}; + var peg$f32 = function(args) { return makeFunctionCall('$_constructArray_$', [nodeExpression(args)])}; + var peg$f33 = function(args) { return makeFunctionCall('$_constructRecord_$', [nodeExpression(args)])}; var peg$f34 = function(key, value) { return nodeKeyValue(key, value)}; var peg$currPos = 0; diff --git a/packages/squiggle-lang/src/rescript/Reducer/Reducer_Peggy/Reducer_Peggy_GeneratedParser.peggy b/packages/squiggle-lang/src/rescript/Reducer/Reducer_Peggy/Reducer_Peggy_GeneratedParser.peggy index 38561598..7f47c761 100644 --- a/packages/squiggle-lang/src/rescript/Reducer/Reducer_Peggy/Reducer_Peggy_GeneratedParser.peggy +++ b/packages/squiggle-lang/src/rescript/Reducer/Reducer_Peggy/Reducer_Peggy_GeneratedParser.peggy @@ -31,9 +31,9 @@ } var postOperatorToFunction = { - '.': '$atIndex', + '.': '$_atIndex_$', '()': '$$_applyAll_$$', - '[]': '$atIndex', + '[]': '$_atIndex_$', } function nodeBlock(statements) {return{type: 'Block', statements: statements}} @@ -275,9 +275,9 @@ lambda arrayConstructor 'array' = '[' _nl ']' - { return makeFunctionCall('$constructArray', [nodeExpression([])])} + { return makeFunctionCall('$_constructArray_$', [nodeExpression([])])} / '[' _nl args:array_elements _nl ']' - { return makeFunctionCall('$constructArray', [nodeExpression(args)])} + { return makeFunctionCall('$_constructArray_$', [nodeExpression(args)])} array_elements = head:expression tail:(_ ',' _nl @expression)* @@ -285,7 +285,7 @@ arrayConstructor 'array' recordConstructor 'record' = '{' _nl args:array_recordArguments _nl '}' - { return makeFunctionCall('$constructRecord', [nodeExpression(args)])} + { return makeFunctionCall('$_constructRecord_$', [nodeExpression(args)])} array_recordArguments = head:keyValuePair tail:(_ ',' _nl @keyValuePair)*