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 55611d3a..1e1ba209 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 @@ -197,7 +197,7 @@ describe("Peggy parse", () => { describe("lambda", () => { testParse("{|x| x}", "{{|:x| :x}}") - testParse("f={|x| x}", "{:f = {{|:x| :x}}}") + testParse("f={|x| x}", "{:f = {|:x| :x}}") testParse("f(x)=x", "{:f = {|:x| {:x}}}") // Function definitions are lambda assignments testParse("f(x)=x ? 1 : 0", "{:f = {|:x| {(::$$_ternary_$$ :x 1 0)}}}") // Function definitions are lambda assignments }) 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 cab84681..daeab3f0 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 @@ -135,7 +135,7 @@ describe("Peggy to Expression", () => { describe("lambda", () => { testToExpression("{|x| x}", "{|x| x}", ~v="lambda(x=>internal code)", ()) - testToExpression("f={|x| x}", "f = {{|x| x}}", ()) + testToExpression("f={|x| x}", "f = {|x| x}", ()) testToExpression("f(x)=x", "f = {|x| {x}}", ()) // Function definitions are lambda assignments testToExpression("f(x)=x ? 1 : 0", "f = {|x| {x ? (1) : (0)}}", ()) }) diff --git a/packages/squiggle-lang/__tests__/Reducer/Reducer_test.res b/packages/squiggle-lang/__tests__/Reducer/Reducer_test.res index 2743b51d..381c4a81 100644 --- a/packages/squiggle-lang/__tests__/Reducer/Reducer_test.res +++ b/packages/squiggle-lang/__tests__/Reducer/Reducer_test.res @@ -102,7 +102,7 @@ describe("stacktraces", () => { )->toBe(`Error: There are function matches for add(), but with different arguments: [add(number, number)]; [add(distribution, number)]; [add(number, distribution)]; [add(distribution, distribution)]; [add(date, duration)]; [add(duration, duration)] Stack trace: f at line 4, column 5 - at line 6, column 12 + g at line 6, column 12 h at line 7, column 10 at line 8, column 3 `) 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 10c64283..7bb01c56 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 @@ -7,7 +7,7 @@ start = _nl start:outerBlock _nl finalComment? {return start} -zeroOMoreArgumentsBlockOrExpression = innerBlockOrExpression / lambda +zeroOMoreArgumentsBlockOrExpression = lambda / innerBlockOrExpression outerBlock = statements:array_statements finalExpression: (statementSeparator @expression)? diff --git a/packages/squiggle-lang/src/rescript/Reducer/Reducer_Peggy/helpers.ts b/packages/squiggle-lang/src/rescript/Reducer/Reducer_Peggy/helpers.ts index 6253b875..15597ea0 100644 --- a/packages/squiggle-lang/src/rescript/Reducer/Reducer_Peggy/helpers.ts +++ b/packages/squiggle-lang/src/rescript/Reducer/Reducer_Peggy/helpers.ts @@ -228,7 +228,9 @@ export function nodeLetStatement( value: AnyPeggyNode, location: LocationRange ): NodeLetStatement { - return { type: "LetStatement", variable, value, location }; + const patchedValue = + value.type === "Lambda" ? { ...value, name: variable.value } : value; + return { type: "LetStatement", variable, value: patchedValue, location }; } export function nodeModuleIdentifier(value: string, location: LocationRange) { return { type: "ModuleIdentifier", value, location };