modify lambda

This commit is contained in:
Umur Ozkul 2022-04-25 09:17:38 +02:00
parent eba087329f
commit c5e08cfdb6
2 changed files with 5 additions and 5 deletions

View File

@ -91,7 +91,7 @@ let rec reduceExpression = (expression: t, bindings: T.bindings): result<express
switch valueList { switch valueList {
| list{EvCall(fName), ...args} => (fName, args->Belt.List.toArray)->BuiltIn.dispatch | list{EvCall(fName), ...args} => (fName, args->Belt.List.toArray)->BuiltIn.dispatch
// "(lambda(x=>internal) param)" // "(lambda(x=>internal) param)"
| list{EvLambda(parameters, internal), ...args} => | list{EvLambda((parameters, internal)), ...args} =>
applyParametersToLambda(internal, parameters, args) applyParametersToLambda(internal, parameters, args)
| _ => valueList->Belt.List.toArray->ExpressionValue.EvArray->Ok | _ => valueList->Belt.List.toArray->ExpressionValue.EvArray->Ok
} }
@ -121,7 +121,7 @@ let rec reduceExpression = (expression: t, bindings: T.bindings): result<express
let rec reduceExpandedExpression = (expression: t): result<expressionValue, 'e> => let rec reduceExpandedExpression = (expression: t): result<expressionValue, 'e> =>
switch expression { switch expression {
| T.EList(list{T.EValue(EvCall("$lambda")), T.EParameters(parameters), functionDefinition}) => | T.EList(list{T.EValue(EvCall("$lambda")), T.EParameters(parameters), functionDefinition}) =>
EvLambda(parameters, functionDefinition->castExpressionToInternalCode)->Ok EvLambda((parameters, functionDefinition->castExpressionToInternalCode))->Ok
| T.EValue(value) => value->Ok | T.EValue(value) => value->Ok
| T.EList(list) => { | T.EList(list) => {
let racc: result<list<expressionValue>, 'e> = list->Belt.List.reduceReverse(Ok(list{}), ( let racc: result<list<expressionValue>, 'e> = list->Belt.List.reduceReverse(Ok(list{}), (

View File

@ -14,7 +14,7 @@ type rec expressionValue =
| EvBool(bool) | EvBool(bool)
| EvCall(string) // External function call | EvCall(string) // External function call
| EvDistribution(GenericDist_Types.genericDist) | EvDistribution(GenericDist_Types.genericDist)
| EvLambda(array<string>, internalCode) | EvLambda((array<string>, internalCode))
| EvNumber(float) | EvNumber(float)
| EvRecord(Js.Dict.t<expressionValue>) | EvRecord(Js.Dict.t<expressionValue>)
| EvString(string) | EvString(string)
@ -29,7 +29,7 @@ let rec toString = aValue =>
switch aValue { switch aValue {
| EvBool(aBool) => Js.String.make(aBool) | EvBool(aBool) => Js.String.make(aBool)
| EvCall(fName) => `:${fName}` | EvCall(fName) => `:${fName}`
| EvLambda(parameters, _internalCode) => `lambda(${Js.Array2.toString(parameters)}=>internal)` | EvLambda((parameters, _internalCode)) => `lambda(${Js.Array2.toString(parameters)}=>internal)`
| EvNumber(aNumber) => Js.String.make(aNumber) | EvNumber(aNumber) => Js.String.make(aNumber)
| EvString(aString) => `'${aString}'` | EvString(aString) => `'${aString}'`
| EvSymbol(aString) => `:${aString}` | EvSymbol(aString) => `:${aString}`
@ -60,7 +60,7 @@ let toStringWithType = aValue =>
| EvBool(_) => `Bool::${toString(aValue)}` | EvBool(_) => `Bool::${toString(aValue)}`
| EvCall(_) => `Call::${toString(aValue)}` | EvCall(_) => `Call::${toString(aValue)}`
| EvDistribution(_) => `Distribution::${toString(aValue)}` | EvDistribution(_) => `Distribution::${toString(aValue)}`
| EvLambda(_parameters, _internalCode) => `Lambda::${toString(aValue)}` | EvLambda((_parameters, _internalCode)) => `Lambda::${toString(aValue)}`
| EvNumber(_) => `Number::${toString(aValue)}` | EvNumber(_) => `Number::${toString(aValue)}`
| EvRecord(_) => `Record::${toString(aValue)}` | EvRecord(_) => `Record::${toString(aValue)}`
| EvString(_) => `String::${toString(aValue)}` | EvString(_) => `String::${toString(aValue)}`