Fix for functions

This commit is contained in:
Ozzie Gooen 2020-07-31 21:11:24 +01:00
parent 65f1485a55
commit ac0baf94ed
4 changed files with 22 additions and 13 deletions

View File

@ -335,7 +335,7 @@ let toLeaf =
FloatFromDist.operationToLeaf(evaluationParams, distToFloatOp, t)
| `Normalize(t) => Normalize.operationToLeaf(evaluationParams, t)
| `Render(t) => Render.operationToLeaf(evaluationParams, t)
| `Function(t) => Ok(`Function(t))
| `Function(_) => Error("Function must be called with params")
| `Symbol(r) => ExpressionTypes.ExpressionTree.Environment.get(evaluationParams.environment, r) |> E.O.toResult("Undeclared variable " ++ r)
| `FunctionCall(name, args) =>
callableFunction(evaluationParams, name, args)

View File

@ -79,7 +79,8 @@ let fnn =
evaluationParams: ExpressionTypes.ExpressionTree.evaluationParams,
name,
args: array(node),
) =>
) =>{
Js.log3("HERE", name, args);
switch (
name,
ExpressionTypes.ExpressionTree.Environment.get(
@ -120,3 +121,4 @@ let fnn =
| ("to", _) => to_(args)
| _ => Error("Function not found")
};
}

View File

@ -1,3 +1,4 @@
[%%debugger.chrome]
module MathJsonToMathJsAdt = {
type arg =
| Symbol(string)
@ -355,6 +356,7 @@ let fromString2 = str => {
Inside of this function, MathAdtToDistDst is called whenever a distribution function is encountered.
*/
let mathJsToJson = str |> pointwiseToRightLogShift |> Mathjs.parseMath;
Js.log2("HI", mathJsToJson);
let mathJsParse =
E.R.bind(mathJsToJson, r => {
switch (MathJsonToMathJsAdt.run(r)) {
@ -364,6 +366,7 @@ let fromString2 = str => {
});
let value = E.R.bind(mathJsParse, MathAdtToDistDst.run);
Js.log3("HI", mathJsParse, value);
value;
};

View File

@ -35,7 +35,7 @@ module Inputs = {
type inputs = {
distPlusIngredients: ingredients,
samplingInputs: SamplingInputs.t,
environment: ExpressionTypes.ExpressionTree.environment
environment: ExpressionTypes.ExpressionTree.environment,
};
let empty: SamplingInputs.t = {
@ -67,16 +67,14 @@ module Internals = {
};
let addVariable =
(
{samplingInputs, guesstimatorString, environment}: inputs,
str,
node,
)
({samplingInputs, guesstimatorString, environment}: inputs, str, node)
: inputs => {
samplingInputs,
guesstimatorString,
environment:
ExpressionTypes.ExpressionTree.Environment.update(environment, str, _ => Some(node))
ExpressionTypes.ExpressionTree.Environment.update(environment, str, _ =>
Some(node)
),
};
let distPlusRenderInputsToInputs = (inputs: Inputs.inputs): inputs => {
@ -110,14 +108,15 @@ module Internals = {
let runProgram = (inputs: inputs, p: ExpressionTypes.Program.program) => {
let ins = ref(inputs);
p
|> E.A.fmap(statement =>
|> E.A.fmap(statement => {
Js.log2("Running ling", statement);
switch (statement) {
| `Assignment(name, node) =>
ins := addVariable(ins^, name, node);
None;
| `Expression(node) => Some(runNode(ins^, node))
}
)
};
})
|> E.A.O.concatSomes
|> E.A.R.firstErrorOrOpen;
};
@ -125,7 +124,12 @@ module Internals = {
let inputsToShape = (inputs: inputs) => {
MathJsParser.fromString(inputs.guesstimatorString)
|> E.R.bind(_, g => runProgram(inputs, g))
|> E.R.bind(_, r => E.A.last(r) |> E.O.toResult("No rendered lines") |> E.R.fmap(Shape.T.normalize));
|> E.R.bind(_, r =>
E.A.last(r)
|> E.O.toResult("No rendered lines")
|> (e => {Js.log2("EE", e); e})
|> E.R.fmap(Shape.T.normalize)
);
};
let outputToDistPlus = (inputs: Inputs.inputs, shape: DistTypes.shape) => {