yarn format
This commit is contained in:
parent
2392002172
commit
92483e66e0
|
@ -10,12 +10,7 @@ describe("Peggy void", () => {
|
|||
// ~v="@{fn: lambda(_=>internal code)}",
|
||||
(),
|
||||
)
|
||||
testToExpression(
|
||||
"fn()=1; fn()",
|
||||
"fn = {|_| {1}}; (fn)(())",
|
||||
~v="1",
|
||||
(),
|
||||
)
|
||||
testToExpression("fn()=1; fn()", "fn = {|_| {1}}; (fn)(())", ~v="1", ())
|
||||
testToExpression(
|
||||
"fn(a)=(); call fn(1)",
|
||||
"fn = {|a| {()}}; _ = {(fn)(1)}",
|
||||
|
|
|
@ -17,10 +17,7 @@ let expectParseToBe = (code: string, answer: string) =>
|
|||
Expression.BackCompatible.parse(code)->ExpressionT.toStringResult->expect->toBe(answer)
|
||||
|
||||
let expectEvalToBe = (code: string, answer: string) =>
|
||||
Expression.BackCompatible.evaluateString(code)
|
||||
->Reducer_Value.toStringResult
|
||||
->expect
|
||||
->toBe(answer)
|
||||
Expression.BackCompatible.evaluateString(code)->Reducer_Value.toStringResult->expect->toBe(answer)
|
||||
|
||||
let expectEvalError = (code: string) =>
|
||||
Expression.BackCompatible.evaluateString(code)
|
||||
|
|
|
@ -2,13 +2,13 @@ open Jest
|
|||
open Expect
|
||||
|
||||
describe("ExpressionValue", () => {
|
||||
test("argsToString", () => expect(
|
||||
[IEvNumber(1.), IEvString("a")]->Reducer_Value.argsToString)->toBe("1,'a'")
|
||||
test("argsToString", () =>
|
||||
expect([IEvNumber(1.), IEvString("a")]->Reducer_Value.argsToString)->toBe("1,'a'")
|
||||
)
|
||||
|
||||
test("toStringFunctionCall", () =>
|
||||
expect(
|
||||
("fn", [IEvNumber(1.), IEvString("a")])->Reducer_Value.toStringFunctionCall)->toBe("fn(1,'a')"
|
||||
expect(("fn", [IEvNumber(1.), IEvString("a")])->Reducer_Value.toStringFunctionCall)->toBe(
|
||||
"fn(1,'a')",
|
||||
)
|
||||
)
|
||||
})
|
||||
|
|
|
@ -48,10 +48,8 @@ Case "Running a single source".
|
|||
let bindings = project->Project.getBindings("main")
|
||||
|
||||
/* Let's display the result and bindings */
|
||||
(
|
||||
result->Reducer_Value.toStringResult,
|
||||
bindings->Reducer_Value.toStringRecord,
|
||||
)->expect == ("Ok(3)", "{}")
|
||||
(result->Reducer_Value.toStringResult, bindings->Reducer_Value.toStringRecord)->expect ==
|
||||
("Ok(3)", "{}")
|
||||
/* You've got 3 with empty bindings. */
|
||||
})
|
||||
|
||||
|
@ -86,10 +84,8 @@ Case "Running a single source".
|
|||
/* If you are running single source without includes and you don't need a custom environment, you can use the shortcut. */
|
||||
/* Examples above was to prepare you for the multi source tutorial. */
|
||||
let (result, bindings) = Project.evaluate("1+2")
|
||||
(
|
||||
result->Reducer_Value.toStringResult,
|
||||
bindings->Reducer_Value.toStringRecord,
|
||||
)->expect == ("Ok(3)", "{}")
|
||||
(result->Reducer_Value.toStringResult, bindings->Reducer_Value.toStringRecord)->expect ==
|
||||
("Ok(3)", "{}")
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
|
@ -30,10 +30,8 @@ describe("ReducerProject Tutorial", () => {
|
|||
let result3 = project->Project.getResult("source3")
|
||||
let bindings3 = project->Project.getBindings("source3")
|
||||
|
||||
(
|
||||
result3->Reducer_Value.toStringResult,
|
||||
bindings3->Reducer_Value.toStringRecord,
|
||||
)->expect == ("Ok(())", "{z: 3}")
|
||||
(result3->Reducer_Value.toStringResult, bindings3->Reducer_Value.toStringRecord)->expect ==
|
||||
("Ok(())", "{z: 3}")
|
||||
})
|
||||
|
||||
test("Depending", () => {
|
||||
|
@ -56,10 +54,8 @@ describe("ReducerProject Tutorial", () => {
|
|||
let result3 = project->Project.getResult("source3")
|
||||
let bindings3 = project->Project.getBindings("source3")
|
||||
|
||||
(
|
||||
result3->Reducer_Value.toStringResult,
|
||||
bindings3->Reducer_Value.toStringRecord,
|
||||
)->expect == ("Ok(())", "{z: 3}")
|
||||
(result3->Reducer_Value.toStringResult, bindings3->Reducer_Value.toStringRecord)->expect ==
|
||||
("Ok(())", "{z: 3}")
|
||||
})
|
||||
|
||||
test("Intro to including", () => {
|
||||
|
@ -91,10 +87,8 @@ describe("ReducerProject Tutorial", () => {
|
|||
let result3 = project->Project.getResult("source3")
|
||||
let bindings3 = project->Project.getBindings("source3")
|
||||
|
||||
(
|
||||
result3->Reducer_Value.toStringResult,
|
||||
bindings3->Reducer_Value.toStringRecord,
|
||||
)->expect == ("Ok(())", "{z: 3}")
|
||||
(result3->Reducer_Value.toStringResult, bindings3->Reducer_Value.toStringRecord)->expect ==
|
||||
("Ok(())", "{z: 3}")
|
||||
/*
|
||||
Doing it like this is too verbose for a storybook
|
||||
But I hope you have seen the relation of setContinues and parseIncludes */
|
||||
|
|
|
@ -144,10 +144,8 @@ Here we will finally proceed to a real life scenario. */
|
|||
let bindings = project->Project.getBindings("main")
|
||||
/* And see the result and bindings.. */
|
||||
test("recursive includes", () => {
|
||||
(
|
||||
result->Reducer_Value.toStringResult,
|
||||
bindings->Reducer_Value.toStringRecord,
|
||||
)->expect == ("Ok(6)", "{a: 6,b: 2}")
|
||||
(result->Reducer_Value.toStringResult, bindings->Reducer_Value.toStringRecord)->expect ==
|
||||
("Ok(6)", "{a: 6,b: 2}")
|
||||
/* Everything as expected */
|
||||
})
|
||||
})
|
||||
|
|
|
@ -3,10 +3,7 @@ open Expect
|
|||
open Reducer_TestHelpers
|
||||
|
||||
let expectEvalToBeOk = (code: string) =>
|
||||
Reducer_Expression.BackCompatible.evaluateString(code)
|
||||
->E.R.isOk
|
||||
->expect
|
||||
->toBe(true)
|
||||
Reducer_Expression.BackCompatible.evaluateString(code)->E.R.isOk->expect->toBe(true)
|
||||
|
||||
let registry = FunctionRegistry_Library.registry
|
||||
let examples = E.A.to_list(FunctionRegistry_Core.Registry.allExamples(registry))
|
||||
|
|
|
@ -26,93 +26,31 @@ let makeFn = (
|
|||
) => makeFnMany(name, [{inputs: inputs, fn: fn}])
|
||||
|
||||
let library = [
|
||||
Make.ff2f(
|
||||
~name="add", // infix + (see Reducer/Reducer_Peggy/helpers.ts)
|
||||
~fn=(x, y) => x +. y,
|
||||
()
|
||||
),
|
||||
Make.ff2f(
|
||||
~name="subtract", // infix -
|
||||
~fn=(x, y) => x -. y,
|
||||
()
|
||||
),
|
||||
Make.ff2f(
|
||||
~name="multiply", // infix *
|
||||
~fn=(x, y) => x *. y,
|
||||
()
|
||||
),
|
||||
Make.ff2f(
|
||||
~name="divide", // infix /
|
||||
~fn=(x, y) => x /. y,
|
||||
()
|
||||
),
|
||||
Make.ff2f(
|
||||
~name="pow", // infix ^
|
||||
~fn=(x, y) => Js.Math.pow_float(~base=x, ~exp=y),
|
||||
()
|
||||
),
|
||||
Make.ff2b(
|
||||
~name="equal", // infix == on numbers
|
||||
~fn=(x, y) => x == y,
|
||||
()
|
||||
),
|
||||
Make.bb2b(
|
||||
~name="equal", // infix == on booleans
|
||||
~fn=(x, y) => x == y,
|
||||
()
|
||||
),
|
||||
Make.ff2b(
|
||||
~name="unequal", // infix != on numbers
|
||||
~fn=(x, y) => x != y,
|
||||
()
|
||||
),
|
||||
Make.ff2b(
|
||||
~name="unequal", // infix != on booleans
|
||||
~fn=(x, y) => x != y,
|
||||
()
|
||||
),
|
||||
Make.ff2b(
|
||||
~name="smaller", // infix <
|
||||
~fn=(x, y) => x < y,
|
||||
()
|
||||
),
|
||||
Make.ff2b(
|
||||
~name="smallerEq", // infix <=
|
||||
~fn=(x, y) => x <= y,
|
||||
()
|
||||
),
|
||||
Make.ff2b(
|
||||
~name="larger", // infix >
|
||||
~fn=(x, y) => x > y,
|
||||
()
|
||||
),
|
||||
Make.ff2b(
|
||||
~name="largerEq", // infix >=
|
||||
~fn=(x, y) => x >= y,
|
||||
()
|
||||
),
|
||||
Make.bb2b(
|
||||
~name="or", // infix ||
|
||||
~fn=(x, y) => x || y,
|
||||
()
|
||||
),
|
||||
Make.bb2b(
|
||||
~name="and", // infix &&
|
||||
~fn=(x, y) => x && y,
|
||||
()
|
||||
),
|
||||
Make.f2f(
|
||||
~name="unaryMinus", // unary prefix -
|
||||
~fn=x => -.x,
|
||||
()
|
||||
),
|
||||
makeFn("not", [FRTypeNumber], inputs => { // unary prefix !
|
||||
Make.ff2f(~name="add", ~fn=(x, y) => x +. y, ()), // infix + (see Reducer/Reducer_Peggy/helpers.ts)
|
||||
Make.ff2f(~name="subtract", ~fn=(x, y) => x -. y, ()), // infix -
|
||||
Make.ff2f(~name="multiply", ~fn=(x, y) => x *. y, ()), // infix *
|
||||
Make.ff2f(~name="divide", ~fn=(x, y) => x /. y, ()), // infix /
|
||||
Make.ff2f(~name="pow", ~fn=(x, y) => Js.Math.pow_float(~base=x, ~exp=y), ()), // infix ^
|
||||
Make.ff2b(~name="equal", ~fn=(x, y) => x == y, ()), // infix == on numbers
|
||||
Make.bb2b(~name="equal", ~fn=(x, y) => x == y, ()), // infix == on booleans
|
||||
Make.ff2b(~name="unequal", ~fn=(x, y) => x != y, ()), // infix != on numbers
|
||||
Make.ff2b(~name="unequal", ~fn=(x, y) => x != y, ()), // infix != on booleans
|
||||
Make.ff2b(~name="smaller", ~fn=(x, y) => x < y, ()), // infix <
|
||||
Make.ff2b(~name="smallerEq", ~fn=(x, y) => x <= y, ()), // infix <=
|
||||
Make.ff2b(~name="larger", ~fn=(x, y) => x > y, ()), // infix >
|
||||
Make.ff2b(~name="largerEq", ~fn=(x, y) => x >= y, ()), // infix >=
|
||||
Make.bb2b(~name="or", ~fn=(x, y) => x || y, ()), // infix ||
|
||||
Make.bb2b(~name="and", ~fn=(x, y) => x && y, ()), // infix &&
|
||||
Make.f2f(~name="unaryMinus", ~fn=x => -.x, ()), // unary prefix -
|
||||
makeFn("not", [FRTypeNumber], inputs => {
|
||||
// unary prefix !
|
||||
switch inputs {
|
||||
| [IEvNumber(x)] => IEvBool(x != 0.)->Ok
|
||||
| _ => Error(impossibleError)
|
||||
}
|
||||
}),
|
||||
makeFn("not", [FRTypeBool], inputs => { // unary prefix !
|
||||
makeFn("not", [FRTypeBool], inputs => {
|
||||
// unary prefix !
|
||||
switch inputs {
|
||||
| [IEvBool(x)] => IEvBool(!x)->Ok
|
||||
| _ => Error(impossibleError)
|
||||
|
@ -157,9 +95,7 @@ let library = [
|
|||
}),
|
||||
makeFn("javascriptraise", [FRTypeAny], inputs => {
|
||||
switch inputs {
|
||||
| [msg] => {
|
||||
Js.Exn.raiseError(msg->Reducer_Value.toString)
|
||||
}
|
||||
| [msg] => Js.Exn.raiseError(msg->Reducer_Value.toString)
|
||||
| _ => Error(impossibleError)
|
||||
}
|
||||
}),
|
||||
|
|
|
@ -17,10 +17,7 @@ module Internals = {
|
|||
->E.A2.fmap(((key, value)) => Wrappers.evArray([IEvString(key), value]))
|
||||
->Wrappers.evArray
|
||||
|
||||
let fromList = (items: array<Reducer_T.value>): result<
|
||||
Reducer_T.value,
|
||||
errorValue,
|
||||
> =>
|
||||
let fromList = (items: array<Reducer_T.value>): result<Reducer_T.value, errorValue> =>
|
||||
items
|
||||
->E.A2.fmap(item => {
|
||||
switch (item: Reducer_T.value) {
|
||||
|
|
|
@ -74,15 +74,10 @@ module Old = {
|
|||
| _ => Error("Not a number")
|
||||
}
|
||||
|
||||
let parseNumberArray = (ags: array<Reducer_T.value>): Belt.Result.t<
|
||||
array<float>,
|
||||
string,
|
||||
> => E.A.fmap(parseNumber, ags) |> E.A.R.firstErrorOrOpen
|
||||
let parseNumberArray = (ags: array<Reducer_T.value>): Belt.Result.t<array<float>, string> =>
|
||||
E.A.fmap(parseNumber, ags) |> E.A.R.firstErrorOrOpen
|
||||
|
||||
let parseDist = (args: Reducer_T.value): Belt.Result.t<
|
||||
DistributionTypes.genericDist,
|
||||
string,
|
||||
> =>
|
||||
let parseDist = (args: Reducer_T.value): Belt.Result.t<DistributionTypes.genericDist, string> =>
|
||||
switch args {
|
||||
| IEvDistribution(x) => Ok(x)
|
||||
| IEvNumber(x) => Ok(GenericDist.fromFloat(x))
|
||||
|
@ -173,10 +168,9 @@ module Old = {
|
|||
}
|
||||
}
|
||||
|
||||
let dispatchToGenericOutput = (
|
||||
call: Reducer_Value.functionCall,
|
||||
env: GenericDist.env,
|
||||
): option<DistributionOperation.outputType> => {
|
||||
let dispatchToGenericOutput = (call: Reducer_Value.functionCall, env: GenericDist.env): option<
|
||||
DistributionOperation.outputType,
|
||||
> => {
|
||||
let (fnName, args) = call
|
||||
switch (fnName, args) {
|
||||
| ("triangular" as fnName, [IEvNumber(f1), IEvNumber(f2), IEvNumber(f3)]) =>
|
||||
|
|
|
@ -5,10 +5,9 @@ let nameSpace = "List"
|
|||
let requiresNamespace = true
|
||||
|
||||
module Internals = {
|
||||
let makeFromNumber = (
|
||||
n: float,
|
||||
value: Reducer_T.value,
|
||||
): Reducer_T.value => IEvArray(Belt.Array.make(E.Float.toInt(n), value))
|
||||
let makeFromNumber = (n: float, value: Reducer_T.value): Reducer_T.value => IEvArray(
|
||||
Belt.Array.make(E.Float.toInt(n), value),
|
||||
)
|
||||
|
||||
let upTo = (low: float, high: float): Reducer_T.value => IEvArray(
|
||||
E.A.Floats.range(low, high, (high -. low +. 1.0)->E.Float.toInt)->E.A2.fmap(Wrappers.evNumber),
|
||||
|
|
|
@ -9,50 +9,13 @@ let library = [
|
|||
~name="sqrt",
|
||||
~nameSpace="Math",
|
||||
~requiresNamespace=true,
|
||||
~fn=(x) => Js.Math.pow_float(~base=x, ~exp=0.5),
|
||||
(),
|
||||
),
|
||||
|
||||
Make.f2f(
|
||||
~name="sin",
|
||||
~nameSpace="Math",
|
||||
~requiresNamespace=true,
|
||||
~fn=Js.Math.sin,
|
||||
(),
|
||||
),
|
||||
Make.f2f(
|
||||
~name="cos",
|
||||
~nameSpace="Math",
|
||||
~requiresNamespace=true,
|
||||
~fn=Js.Math.cos,
|
||||
(),
|
||||
),
|
||||
Make.f2f(
|
||||
~name="tan",
|
||||
~nameSpace="Math",
|
||||
~requiresNamespace=true,
|
||||
~fn=Js.Math.tan,
|
||||
(),
|
||||
),
|
||||
Make.f2f(
|
||||
~name="asin",
|
||||
~nameSpace="Math",
|
||||
~requiresNamespace=true,
|
||||
~fn=Js.Math.asin,
|
||||
(),
|
||||
),
|
||||
Make.f2f(
|
||||
~name="acos",
|
||||
~nameSpace="Math",
|
||||
~requiresNamespace=true,
|
||||
~fn=Js.Math.acos,
|
||||
(),
|
||||
),
|
||||
Make.f2f(
|
||||
~name="atan",
|
||||
~nameSpace="Math",
|
||||
~requiresNamespace=true,
|
||||
~fn=Js.Math.atan,
|
||||
~fn=x => Js.Math.pow_float(~base=x, ~exp=0.5),
|
||||
(),
|
||||
),
|
||||
Make.f2f(~name="sin", ~nameSpace="Math", ~requiresNamespace=true, ~fn=Js.Math.sin, ()),
|
||||
Make.f2f(~name="cos", ~nameSpace="Math", ~requiresNamespace=true, ~fn=Js.Math.cos, ()),
|
||||
Make.f2f(~name="tan", ~nameSpace="Math", ~requiresNamespace=true, ~fn=Js.Math.tan, ()),
|
||||
Make.f2f(~name="asin", ~nameSpace="Math", ~requiresNamespace=true, ~fn=Js.Math.asin, ()),
|
||||
Make.f2f(~name="acos", ~nameSpace="Math", ~requiresNamespace=true, ~fn=Js.Math.acos, ()),
|
||||
Make.f2f(~name="atan", ~nameSpace="Math", ~requiresNamespace=true, ~fn=Js.Math.atan, ()),
|
||||
]
|
||||
|
|
|
@ -48,9 +48,7 @@ module Internal = {
|
|||
SampleSetDist.map3(~fn, ~t1, ~t2, ~t3)->toType
|
||||
}
|
||||
|
||||
let parseSampleSetArray = (arr: array<Reducer_T.value>): option<
|
||||
array<SampleSetDist.t>,
|
||||
> => {
|
||||
let parseSampleSetArray = (arr: array<Reducer_T.value>): option<array<SampleSetDist.t>> => {
|
||||
let parseSampleSet = (value: Reducer_T.value): option<SampleSetDist.t> =>
|
||||
switch value {
|
||||
| IEvDistribution(SampleSet(dist)) => Some(dist)
|
||||
|
|
|
@ -73,8 +73,7 @@ let getTag = (variant: squiggleValue): squiggleValueTag =>
|
|||
}
|
||||
|
||||
@genType
|
||||
let toString = (variant: squiggleValue) =>
|
||||
Reducer_Value.toString(variant)
|
||||
let toString = (variant: squiggleValue) => Reducer_Value.toString(variant)
|
||||
|
||||
// This is a useful method for unit tests.
|
||||
// Convert the result along with the error message to a string.
|
||||
|
|
|
@ -2,9 +2,7 @@ type squiggleValue = ForTS_SquiggleValue.squiggleValue
|
|||
@genType type squiggleValue_Array = ForTS_SquiggleValue.squiggleValue_Array //re-export recursive type
|
||||
|
||||
@genType
|
||||
let getValues = (v: squiggleValue_Array): array<squiggleValue> =>
|
||||
Reducer_Value.arrayToValueArray(v)
|
||||
let getValues = (v: squiggleValue_Array): array<squiggleValue> => Reducer_Value.arrayToValueArray(v)
|
||||
|
||||
@genType
|
||||
let toString = (v: squiggleValue_Array): string =>
|
||||
Reducer_Value.toStringArray(v)
|
||||
let toString = (v: squiggleValue_Array): string => Reducer_Value.toStringArray(v)
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
@genType type squiggleValue_Declaration = Reducer_T.lambdaDeclaration //re-export
|
||||
|
||||
@genType
|
||||
let toString = (v: squiggleValue_Declaration): string =>
|
||||
Reducer_Value.toStringDeclaration(v)
|
||||
let toString = (v: squiggleValue_Declaration): string => Reducer_Value.toStringDeclaration(v)
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
@genType type squiggleValue_Distribution = ForTS_Distribution.distribution
|
||||
|
||||
@genType
|
||||
let toString = (v: squiggleValue_Distribution): string =>
|
||||
Reducer_Value.toStringDistribution(v)
|
||||
let toString = (v: squiggleValue_Distribution): string => Reducer_Value.toStringDistribution(v)
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
@genType type squiggleValue_Lambda = Reducer_T.lambdaValue //re-export
|
||||
|
||||
@genType
|
||||
let toString = (v: squiggleValue_Lambda): string =>
|
||||
Reducer_Value.toStringFunction(v)
|
||||
let toString = (v: squiggleValue_Lambda): string => Reducer_Value.toStringFunction(v)
|
||||
|
||||
@genType
|
||||
let parameters = (v: squiggleValue_Lambda): array<string> => {
|
||||
|
|
|
@ -6,5 +6,4 @@ let getKeyValuePairs = (value: squiggleValue_Type): array<(string, squiggleValue
|
|||
Reducer_Value.recordToKeyValuePairs(value)
|
||||
|
||||
@genType
|
||||
let toString = (value: squiggleValue_Type): string =>
|
||||
Reducer_Value.toStringType(value)
|
||||
let toString = (value: squiggleValue_Type): string => Reducer_Value.toStringType(value)
|
||||
|
|
|
@ -179,10 +179,9 @@ module FRType = {
|
|||
| FRValueAny(f) => matchReverse(f)
|
||||
}
|
||||
|
||||
let matchWithExpressionValueArray = (
|
||||
inputs: array<t>,
|
||||
args: array<Reducer_T.value>,
|
||||
): option<array<frValue>> => {
|
||||
let matchWithExpressionValueArray = (inputs: array<t>, args: array<Reducer_T.value>): option<
|
||||
array<frValue>,
|
||||
> => {
|
||||
let isSameLength = E.A.length(inputs) == E.A.length(args)
|
||||
if !isSameLength {
|
||||
None
|
||||
|
|
|
@ -278,10 +278,10 @@ module Make = {
|
|||
|
||||
Q: What about polymorphic functions with multiple definitions? Why ~fn is not an array?
|
||||
A: We often define the same function in multiple `FR_*` files, so that doesn't work well anyway. In 90%+ cases there's a single definition. And having to write `name` twice is annoying.
|
||||
*/
|
||||
*/
|
||||
let f2f = (
|
||||
~name: string,
|
||||
~fn: (float) => float,
|
||||
~fn: float => float,
|
||||
~nameSpace="",
|
||||
~requiresNamespace=false,
|
||||
~examples=?,
|
||||
|
@ -290,22 +290,22 @@ module Make = {
|
|||
Function.make(
|
||||
~name,
|
||||
~nameSpace,
|
||||
~requiresNamespace=requiresNamespace,
|
||||
~requiresNamespace,
|
||||
~examples=examples->E.O.default([], _),
|
||||
~output=EvtNumber,
|
||||
~definitions=[
|
||||
FnDefinition.make(
|
||||
~name,
|
||||
~inputs=[FRTypeNumber],
|
||||
~run=((inputs, _, _, _) =>
|
||||
~run=(inputs, _, _, _) =>
|
||||
switch inputs {
|
||||
| [IEvNumber(x)] => fn(x)->IEvNumber->Ok
|
||||
| _ => Error(impossibleError)
|
||||
}),
|
||||
()
|
||||
)
|
||||
},
|
||||
(),
|
||||
),
|
||||
],
|
||||
()
|
||||
(),
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -320,22 +320,22 @@ module Make = {
|
|||
Function.make(
|
||||
~name,
|
||||
~nameSpace,
|
||||
~requiresNamespace=requiresNamespace,
|
||||
~requiresNamespace,
|
||||
~examples=examples->E.O.default([], _),
|
||||
~output=EvtNumber,
|
||||
~definitions=[
|
||||
FnDefinition.make(
|
||||
~name,
|
||||
~inputs=[FRTypeNumber, FRTypeNumber],
|
||||
~run=((inputs, _, _, _) =>
|
||||
~run=(inputs, _, _, _) =>
|
||||
switch inputs {
|
||||
| [IEvNumber(x), IEvNumber(y)] => fn(x, y)->IEvNumber->Ok
|
||||
| _ => Error(impossibleError)
|
||||
}),
|
||||
()
|
||||
)
|
||||
},
|
||||
(),
|
||||
),
|
||||
],
|
||||
()
|
||||
(),
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -350,22 +350,22 @@ module Make = {
|
|||
Function.make(
|
||||
~name,
|
||||
~nameSpace,
|
||||
~requiresNamespace=requiresNamespace,
|
||||
~requiresNamespace,
|
||||
~examples=examples->E.O.default([], _),
|
||||
~output=EvtBool,
|
||||
~definitions=[
|
||||
FnDefinition.make(
|
||||
~name,
|
||||
~inputs=[FRTypeNumber, FRTypeNumber],
|
||||
~run=((inputs, _, _, _) =>
|
||||
~run=(inputs, _, _, _) =>
|
||||
switch inputs {
|
||||
| [IEvNumber(x), IEvNumber(y)] => fn(x, y)->IEvBool->Ok
|
||||
| _ => Error(impossibleError)
|
||||
}),
|
||||
()
|
||||
)
|
||||
},
|
||||
(),
|
||||
),
|
||||
],
|
||||
()
|
||||
(),
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -380,22 +380,22 @@ module Make = {
|
|||
Function.make(
|
||||
~name,
|
||||
~nameSpace,
|
||||
~requiresNamespace=requiresNamespace,
|
||||
~requiresNamespace,
|
||||
~examples=examples->E.O.default([], _),
|
||||
~output=EvtBool,
|
||||
~definitions=[
|
||||
FnDefinition.make(
|
||||
~name,
|
||||
~inputs=[FRTypeBool, FRTypeBool],
|
||||
~run=((inputs, _, _, _) =>
|
||||
~run=(inputs, _, _, _) =>
|
||||
switch inputs {
|
||||
| [IEvBool(x), IEvBool(y)] => fn(x, y)->IEvBool->Ok
|
||||
| _ => Error(impossibleError)
|
||||
}),
|
||||
()
|
||||
)
|
||||
},
|
||||
(),
|
||||
),
|
||||
],
|
||||
()
|
||||
(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,5 +9,4 @@ let createContext = (stdLib: Reducer_Namespace.t, environment: Reducer_T.environ
|
|||
}
|
||||
}
|
||||
|
||||
let createDefaultContext = (): t =>
|
||||
createContext(SquiggleLibrary_StdLib.stdLib, defaultEnvironment)
|
||||
let createDefaultContext = (): t => createContext(SquiggleLibrary_StdLib.stdLib, defaultEnvironment)
|
||||
|
|
|
@ -103,9 +103,7 @@ let rec evaluate: T.reducerFn = (expression, context): (T.value, T.context) => {
|
|||
context,
|
||||
)
|
||||
| _ =>
|
||||
RENotAFunction(lambda->Reducer_Value.toString)
|
||||
->Reducer_ErrorValue.ErrorException
|
||||
->raise
|
||||
RENotAFunction(lambda->Reducer_Value.toString)->Reducer_ErrorValue.ErrorException->raise
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,9 +24,7 @@ let mergeMany = (namespaces: array<t>): t =>
|
|||
let toString = (namespace: t) =>
|
||||
namespace
|
||||
->Belt.Map.String.toArray
|
||||
->Belt.Array.map(((eachKey, eachValue)) =>
|
||||
`${eachKey}: ${eachValue->Reducer_Value.toString}`
|
||||
)
|
||||
->Belt.Array.map(((eachKey, eachValue)) => `${eachKey}: ${eachValue->Reducer_Value.toString}`)
|
||||
->Js.Array2.toString
|
||||
|
||||
let fromArray = (a): t => Belt.Map.String.fromArray(a)
|
||||
|
|
|
@ -16,10 +16,7 @@ let isMax = (modifierArg: Reducer_Value.t, aValue: Reducer_Value.t): bool => {
|
|||
}
|
||||
}
|
||||
|
||||
let isMemberOf = (
|
||||
modifierArg: Reducer_Value.t,
|
||||
aValue: Reducer_Value.t,
|
||||
): bool => {
|
||||
let isMemberOf = (modifierArg: Reducer_Value.t, aValue: Reducer_Value.t): bool => {
|
||||
let pair = (modifierArg, aValue)
|
||||
switch pair {
|
||||
| (ievA, IEvArray(b)) => Js.Array2.includes(b, ievA)
|
||||
|
@ -27,11 +24,7 @@ let isMemberOf = (
|
|||
}
|
||||
}
|
||||
|
||||
let checkModifier = (
|
||||
key: string,
|
||||
modifierArg: Reducer_Value.t,
|
||||
aValue: Reducer_Value.t,
|
||||
): bool =>
|
||||
let checkModifier = (key: string, modifierArg: Reducer_Value.t, aValue: Reducer_Value.t): bool =>
|
||||
switch key {
|
||||
| "min" => isMin(modifierArg, aValue)
|
||||
| "max" => isMax(modifierArg, aValue)
|
||||
|
|
|
@ -13,16 +13,13 @@ let stdLib: Reducer_T.namespace = {
|
|||
Reducer_Expression_Lambda.makeFFILambda((inputs, _, _) => {
|
||||
switch inputs {
|
||||
| [IEvArray(aValueArray), IEvNumber(fIndex)] => {
|
||||
let index = Belt.Int.fromFloat(fIndex) // TODO - fail on non-integer indices?
|
||||
let index = Belt.Int.fromFloat(fIndex) // TODO - fail on non-integer indices?
|
||||
|
||||
switch Belt.Array.get(aValueArray, index) {
|
||||
| Some(value) => value
|
||||
| None =>
|
||||
REArrayIndexNotFound("Array index not found", index)
|
||||
->ErrorException
|
||||
->raise
|
||||
switch Belt.Array.get(aValueArray, index) {
|
||||
| Some(value) => value
|
||||
| None => REArrayIndexNotFound("Array index not found", index)->ErrorException->raise
|
||||
}
|
||||
}
|
||||
}
|
||||
| [IEvRecord(dict), IEvString(sIndex)] =>
|
||||
switch Belt.Map.String.get(dict, sIndex) {
|
||||
| Some(value) => value
|
||||
|
|
Loading…
Reference in New Issue
Block a user