diff --git a/packages/squiggle-lang/__tests__/Reducer/Reducer_Dispatch/Reducer_Dispatch_BuiltIn_test.res b/packages/squiggle-lang/__tests__/Reducer/Reducer_Dispatch/Reducer_Dispatch_BuiltIn_test.res index 535f9e56..682e1737 100644 --- a/packages/squiggle-lang/__tests__/Reducer/Reducer_Dispatch/Reducer_Dispatch_BuiltIn_test.res +++ b/packages/squiggle-lang/__tests__/Reducer/Reducer_Dispatch/Reducer_Dispatch_BuiltIn_test.res @@ -30,8 +30,12 @@ describe("builtin exception", () => { ) }) -Skip.describe("error reporting from collection functions", () => { - testEval("arr = [normal(3,2)]; map(arr, zarathsuzaWasHere)", "") +describe("error reporting from collection functions", () => { + testEval("arr=[1,2,3]; map(arr, {|x| x*2})", "Ok([2,4,6])") + testEval( + "arr = [normal(3,2)]; map(arr, zarathsuzaWasHere)", + "Error(zarathsuzaWasHere is not defined)", + ) // FIXME: returns "Error(Function not found: map(Array,Symbol))" // Actually this error is correct but not informative }) diff --git a/packages/squiggle-lang/__tests__/Reducer/Reducer_functionTricks_test.res b/packages/squiggle-lang/__tests__/Reducer/Reducer_functionTricks_test.res index ba29e920..fd7485eb 100644 --- a/packages/squiggle-lang/__tests__/Reducer/Reducer_functionTricks_test.res +++ b/packages/squiggle-lang/__tests__/Reducer/Reducer_functionTricks_test.res @@ -25,7 +25,7 @@ describe("Arity check", () => { ) testEvalToBe("f(x)=x; f(f)", "Ok(lambda(x=>internal code))") testEvalToBe( - "f(x,y)=x(y); f(z)", + "f(x,y)=x(y); f(1)", "Error(2 arguments expected. Instead 1 argument(s) were passed.)", ) }) 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 72d599ca..141b4a37 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 @@ -149,8 +149,15 @@ let callInternal = (call: functionCall, environment, reducer: ExpressionT.reduce | ("reduceReverse", [EvArray(aValueArray), initialValue, EvLambda(aLambdaValue)]) => doReduceReverseArray(aValueArray, initialValue, aLambdaValue) | ("reverse", [EvArray(aValueArray)]) => aValueArray->Belt.Array.reverse->EvArray->Ok - | (_, [EvBool(_)]) | (_, [EvNumber(_)]) | (_, [EvString(_)]) | (_, [EvBool(_), EvBool(_)]) | (_, [EvNumber(_), EvNumber(_)]) | (_, [EvString(_), EvString(_)]) => callMathJs(call) - | call => Error(REFunctionNotFound(call->functionCallToCallSignature->functionCallSignatureToString)) // Report full type signature as error + | (_, [EvBool(_)]) + | (_, [EvNumber(_)]) + | (_, [EvString(_)]) + | (_, [EvBool(_), EvBool(_)]) + | (_, [EvNumber(_), EvNumber(_)]) + | (_, [EvString(_), EvString(_)]) => + callMathJs(call) + | call => + Error(REFunctionNotFound(call->functionCallToCallSignature->functionCallSignatureToString)) // Report full type signature as error } } 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 1125c193..6e3c7cab 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 @@ -76,17 +76,30 @@ and reduceValueList = (valueList: list, environment): result< 'e, > => switch valueList { - | list{EvCall(fName), ...args} => - (fName, args->Belt.List.toArray)->BuiltIn.dispatch(environment, reduceExpression) + | list{EvCall(fName), ...args} => { + let rCheckedArgs = switch fName == "$_setBindings_$" { + | false => args->Lambda.checkIfReduced + | true => args->Ok + } + rCheckedArgs->Result.flatMap(checkedArgs => + (fName, checkedArgs->Belt.List.toArray)->BuiltIn.dispatch(environment, reduceExpression) + ) + } | list{EvLambda(_)} => + // TODO: remove on solving issue#558 valueList ->Lambda.checkIfReduced ->Result.flatMap(reducedValueList => reducedValueList->Belt.List.toArray->ExpressionValue.EvArray->Ok ) | list{EvLambda(lamdaCall), ...args} => - Lambda.doLambdaCall(lamdaCall, args, environment, reduceExpression) + args + ->Lambda.checkIfReduced + ->Result.flatMap(checkedArgs => + Lambda.doLambdaCall(lamdaCall, checkedArgs, environment, reduceExpression) + ) + | _ => valueList ->Lambda.checkIfReduced diff --git a/packages/squiggle-lang/src/rescript/ReducerInterface/ReducerInterface_ExpressionValue.res b/packages/squiggle-lang/src/rescript/ReducerInterface/ReducerInterface_ExpressionValue.res index 958b99df..7249b135 100644 --- a/packages/squiggle-lang/src/rescript/ReducerInterface/ReducerInterface_ExpressionValue.res +++ b/packages/squiggle-lang/src/rescript/ReducerInterface/ReducerInterface_ExpressionValue.res @@ -118,9 +118,11 @@ type expresionValueType = | EvtSymbol type functionCallSignature = CallSignature(string, array) -type functionDefinitionSignature = FunctionDefinitionSignature(functionCallSignature, expresionValueType) +type functionDefinitionSignature = + FunctionDefinitionSignature(functionCallSignature, expresionValueType) -let valueToValueType = (value) => switch value { +let valueToValueType = value => + switch value { | EvArray(_) => EvtArray | EvArrayString(_) => EvtArray | EvBool(_) => EvtBool @@ -130,11 +132,13 @@ let valueToValueType = (value) => switch value { | EvNumber(_) => EvtNumber | EvRecord(_) => EvtRecord | EvString(_) => EvtArray - | EvSymbol(_) => EvtSymbol} + | EvSymbol(_) => EvtSymbol + } let functionCallToCallSignature = (functionCall: functionCall): functionCallSignature => { let (fn, args) = functionCall - CallSignature(fn, args->Js.Array2.map(valueToValueType))} + CallSignature(fn, args->Js.Array2.map(valueToValueType)) +} let valueTypeToString = (valueType: expresionValueType): string => switch valueType { @@ -152,4 +156,5 @@ let valueTypeToString = (valueType: expresionValueType): string => let functionCallSignatureToString = (functionCallSignature: functionCallSignature): string => { let CallSignature(fn, args) = functionCallSignature - `${fn}(${args->Js.Array2.map(valueTypeToString)->Js.Array2.toString})`} \ No newline at end of file + `${fn}(${args->Js.Array2.map(valueTypeToString)->Js.Array2.toString})` +}