define lambdaValue record as payload

This commit is contained in:
Umur Ozkul 2022-05-02 12:10:31 +02:00
parent 087596ec43
commit c0fad8c668
3 changed files with 16 additions and 12 deletions

View File

@ -26,10 +26,10 @@ let eFunction = (fName: string, lispArgs: list<expression>): expression => {
}
let eLambda = (parameters: array<string>, context, expr) =>
BExpressionValue.EvLambda(
parameters,
context,
expr->castExpressionToInternalCode,
BExpressionValue.EvLambda({
parameters: parameters,
context: context,
body: expr->castExpressionToInternalCode}
)->BExpressionT.EValue
let eNumber = aNumber => aNumber->BExpressionValue.EvNumber->BExpressionT.EValue

View File

@ -30,6 +30,6 @@ let applyParametersToLambda = (
reducer(newExpression, bindings, environment)
}
let doLambdaCall = ((parameters, context, internal), args, environment, reducer) => {
applyParametersToLambda(internal, parameters, args, context, environment, reducer)
let doLambdaCall = (lambdaValue: ExpressionValue.lambdaValue, args, environment, reducer) => {
applyParametersToLambda(lambdaValue.body, lambdaValue.parameters, args, lambdaValue.context, environment, reducer)
}

View File

@ -15,15 +15,19 @@ type rec expressionValue =
| EvBool(bool)
| EvCall(string) // External function call
| EvDistribution(DistributionTypes.genericDist)
| EvLambda((array<string>, record, internalCode))
| EvLambda(lambdaValue)
| EvNumber(float)
| EvRecord(record)
| EvString(string)
| EvSymbol(string)
and record = Js.Dict.t<expressionValue>
and externalBindings = record
and lambdaValue = {
parameters: array<string>,
context: externalBindings,
body: internalCode,
}
@genType
type externalBindings = record
@genType
let defaultExternalBindings: externalBindings = Js.Dict.empty()
@ -41,8 +45,8 @@ let rec toString = aValue =>
}
| EvBool(aBool) => Js.String.make(aBool)
| EvCall(fName) => `:${fName}`
| EvLambda((parameters, _context, _internalCode)) =>
`lambda(${Js.Array2.toString(parameters)}=>internal)`
| EvLambda(lambdaValue) =>
`lambda(${Js.Array2.toString(lambdaValue.parameters)}=>internal code)`
| EvNumber(aNumber) => Js.String.make(aNumber)
| EvString(aString) => `'${aString}'`
| EvSymbol(aString) => `:${aString}`
@ -65,7 +69,7 @@ let toStringWithType = aValue =>
| EvBool(_) => `Bool::${toString(aValue)}`
| EvCall(_) => `Call::${toString(aValue)}`
| EvDistribution(_) => `Distribution::${toString(aValue)}`
| EvLambda((_parameters, _context, _internalCode)) => `Lambda::${toString(aValue)}`
| EvLambda(_) => `Lambda::${toString(aValue)}`
| EvNumber(_) => `Number::${toString(aValue)}`
| EvRecord(_) => `Record::${toString(aValue)}`
| EvString(_) => `String::${toString(aValue)}`