This commit is contained in:
Umur Ozkul 2022-04-24 18:42:54 +02:00
parent 88b6d49ad3
commit fe4e355fbe
5 changed files with 14 additions and 11 deletions

View File

@ -17,7 +17,10 @@ let expectEvalToBe = (expr: string, answer: string) =>
Reducer.evaluate(expr)->ExpressionValue.toStringResult->expect->toBe(answer)
let expectEvalBindingsToBe = (expr: string, bindings: Reducer.externalBindings, answer: string) =>
Reducer.evaluateUsingExternalBindings(expr, bindings)->ExpressionValue.toStringResult->expect->toBe(answer)
Reducer.evaluateUsingExternalBindings(expr, bindings)
->ExpressionValue.toStringResult
->expect
->toBe(answer)
let expectEvalPartialBindingsToBe = (
expr: string,

View File

@ -10,8 +10,8 @@ open Reducer_TestHelpers
inpsectPerformace(expr, label) will print out the value of expr, the label, and the time it took to evaluate expr.
*/
describe("Debugging", () => {
testEvalToBe("inspect(1)", "Ok(1)")
testEvalToBe("inspect(1, \"one\")", "Ok(1)")
testEvalToBe("inspect(1, \"one\")", "Ok(1)")
testEvalToBe("inspectPerformance(1, \"one\")", "Ok(1)")
testEvalToBe("inspect(1)", "Ok(1)")
testEvalToBe("inspect(1, \"one\")", "Ok(1)")
testEvalToBe("inspect(1, \"one\")", "Ok(1)")
testEvalToBe("inspectPerformance(1, \"one\")", "Ok(1)")
})

View File

@ -44,7 +44,7 @@ let callInternal = (call: functionCall): result<'b, errorValue> => {
}
let inspect = (value: expressionValue) => {
Js.log(`${value->toString}`)
Js.log(value->toString)
value->Ok
}

View File

@ -32,7 +32,7 @@ external castAssignmentNodeWAccessor: node => assignmentNodeWAccessor = "%identi
external castAssignmentNodeWIndex: node => assignmentNodeWIndex = "%identity"
external castBlockNode: node => blockNode = "%identity"
external castConstantNode: node => constantNode = "%identity"
external castFunctionAssignmentNode: node => functionAssignmentNode ="%identity"
external castFunctionAssignmentNode: node => functionAssignmentNode = "%identity"
external castFunctionNode: node => functionNode = "%identity"
external castIndexNode: node => indexNode = "%identity"
external castObjectNode: node => objectNode = "%identity"
@ -123,7 +123,7 @@ let rec toString = (mathJsNode: mathJsNode): string => {
let toStringFunctionAssignmentNode = (faNode: functionAssignmentNode): string => {
let paramNames = Js.Array2.toString(faNode["params"])
`${faNode["name"]} = (${paramNames}) => ${toStringMathJsNode(faNode["expr"])}`
}
}
let toStringFunctionNode = (fnode: functionNode): string =>
`${fnode->nameOfFunctionNode}(${fnode["args"]->toStringNodeArray})`
@ -158,7 +158,7 @@ let rec toString = (mathJsNode: mathJsNode): string => {
`${aNode["object"]->toStringSymbolNode} = ${aNode["value"]->toStringMathJsNode}`
| MjBlockNode(bNode) => `{${bNode["blocks"]->toStringBlocks}}`
| MjConstantNode(cNode) => cNode["value"]->toStringValue
| MjFunctionAssignmentNode(faNode) => faNode->toStringFunctionAssignmentNode
| MjFunctionAssignmentNode(faNode) => faNode->toStringFunctionAssignmentNode
| MjFunctionNode(fNode) => fNode->toStringFunctionNode
| MjIndexNode(iNode) => iNode->toStringIndexNode
| MjObjectNode(oNode) => oNode->toStringObjectNode

View File

@ -106,12 +106,12 @@ let rec fromNode = (mathJsNode: Parse.node): result<expression, errorValue> =>
rValueExpression->Result.flatMap(valueExpression => {
let lispParams = faNode["params"]->Belt.List.fromArray->ExpressionT.EParameters
let rLambda = passToFunction("$lambda", list{lispParams, valueExpression}->Ok)
rLambda -> Result.flatMap( lambda => {
rLambda->Result.flatMap(lambda => {
passToFunction("$let", list{symbol, lambda}->Ok)
})
})
}
let caseArrayNode = aNode => {
aNode["items"]->Belt.List.fromArray->fromNodeList->Result.map(list => ExpressionT.EList(list))
}