Minor cleanup

This commit is contained in:
Ozzie Gooen 2022-07-18 22:21:57 -07:00
parent 173c17e13d
commit 6f25fca814
4 changed files with 12 additions and 9 deletions

View File

@ -274,8 +274,7 @@ module Matcher = {
module Registry = {
let _findExactMatches = (r: registry, fnName: string, args: array<internalExpressionValue>) => {
let functionMatchPairs =
r.functions->E.A2.fmap(l => (l, Function.match(l, fnName, args)))
let functionMatchPairs = r.functions->E.A2.fmap(l => (l, Function.match(l, fnName, args)))
let fullMatch = functionMatchPairs->E.A.getBy(((_, match)) => Match.isFullMatch(match))
fullMatch->E.O.bind(((fn, match)) =>
switch match {
@ -416,7 +415,8 @@ module Registry = {
r.functions->E.A2.fmap(fn => fn.examples->E.A2.fmap(example => (fn, example)))->E.A.concatMany
let buildFnNameDict = (r: array<function>): fnNameDict => {
let allDefinitionsWithFns = r
let allDefinitionsWithFns =
r
->E.A2.fmap(fn => fn.definitions->E.A2.fmap(definitions => (fn, definitions)))
->E.A.concatMany
let functionsWithFnNames =
@ -440,7 +440,7 @@ module Registry = {
cacheAsArray->Js.Dict.fromArray
}
let make = (fns: array<function>):registry => {
let make = (fns: array<function>): registry => {
let dict = buildFnNameDict(fns)
{functions: fns, fnNameDict: dict}
}

View File

@ -19,11 +19,15 @@ let dispatch = (call: InternalExpressionValue.functionCall, environment, chain):
/*
If your dispatch is too big you can divide it into smaller dispatches and pass the call so that it gets called finally.
The final chain(call) invokes the builtin default functions of the interpreter.
Via chain(call), all MathJs operators and functions are available for string, number , boolean, array and record
.e.g + - / * > >= < <= == /= not and or sin cos log ln concat, etc.
// See https://mathjs.org/docs/expressions/syntax.html
// See https://mathjs.org/docs/reference/functions.html
Remember from the users point of view, there are no different modules:
// "doSth( constructorType1 )"
// "doSth( constructorType2 )"

View File

@ -18,6 +18,5 @@ let mathBindings: Bindings.t =
->E.A2.fmap(((name, v)) => (name, ReducerInterface_InternalExpressionValue.IEvNumber(v)))
->Bindings.fromArray
//TODO: This should be in a different place.
let makeBindings = (previousBindings: Bindings.t): Bindings.t =>
previousBindings->Bindings.merge(mathBindings)