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,9 +415,10 @@ 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
->E.A2.fmap(fn => fn.definitions->E.A2.fmap(definitions => (fn, definitions)))
->E.A.concatMany
let allDefinitionsWithFns =
r
->E.A2.fmap(fn => fn.definitions->E.A2.fmap(definitions => (fn, definitions)))
->E.A.concatMany
let functionsWithFnNames =
allDefinitionsWithFns
->E.A2.fmap(((fn, def)) => {
@ -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

@ -9,4 +9,4 @@ let fnList = Belt.Array.concatMany([
])
let registry = FunctionRegistry_Core.Registry.make(fnList)
let dispatch = FunctionRegistry_Core.Registry.dispatch(registry)
let dispatch = FunctionRegistry_Core.Registry.dispatch(registry)

View File

@ -19,13 +19,17 @@ 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 )"
doSth gets dispatched to the correct module because of the type signature. You get function and operator abstraction for free. You don't need to combine different implementations into one type. That would be duplicating the repsonsibility of the dispatcher.
*/
*/

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)