yarn format

This commit is contained in:
Vyacheslav Matyukhin 2022-09-20 02:19:55 +04:00
parent 2392002172
commit 92483e66e0
No known key found for this signature in database
GPG Key ID: 3D2A774C5489F96C
26 changed files with 104 additions and 263 deletions

View File

@ -10,12 +10,7 @@ describe("Peggy void", () => {
// ~v="@{fn: lambda(_=>internal code)}", // ~v="@{fn: lambda(_=>internal code)}",
(), (),
) )
testToExpression( testToExpression("fn()=1; fn()", "fn = {|_| {1}}; (fn)(())", ~v="1", ())
"fn()=1; fn()",
"fn = {|_| {1}}; (fn)(())",
~v="1",
(),
)
testToExpression( testToExpression(
"fn(a)=(); call fn(1)", "fn(a)=(); call fn(1)",
"fn = {|a| {()}}; _ = {(fn)(1)}", "fn = {|a| {()}}; _ = {(fn)(1)}",

View File

@ -17,10 +17,7 @@ let expectParseToBe = (code: string, answer: string) =>
Expression.BackCompatible.parse(code)->ExpressionT.toStringResult->expect->toBe(answer) Expression.BackCompatible.parse(code)->ExpressionT.toStringResult->expect->toBe(answer)
let expectEvalToBe = (code: string, answer: string) => let expectEvalToBe = (code: string, answer: string) =>
Expression.BackCompatible.evaluateString(code) Expression.BackCompatible.evaluateString(code)->Reducer_Value.toStringResult->expect->toBe(answer)
->Reducer_Value.toStringResult
->expect
->toBe(answer)
let expectEvalError = (code: string) => let expectEvalError = (code: string) =>
Expression.BackCompatible.evaluateString(code) Expression.BackCompatible.evaluateString(code)

View File

@ -2,13 +2,13 @@ open Jest
open Expect open Expect
describe("ExpressionValue", () => { describe("ExpressionValue", () => {
test("argsToString", () => expect( test("argsToString", () =>
[IEvNumber(1.), IEvString("a")]->Reducer_Value.argsToString)->toBe("1,'a'") expect([IEvNumber(1.), IEvString("a")]->Reducer_Value.argsToString)->toBe("1,'a'")
) )
test("toStringFunctionCall", () => test("toStringFunctionCall", () =>
expect( expect(("fn", [IEvNumber(1.), IEvString("a")])->Reducer_Value.toStringFunctionCall)->toBe(
("fn", [IEvNumber(1.), IEvString("a")])->Reducer_Value.toStringFunctionCall)->toBe("fn(1,'a')" "fn(1,'a')",
) )
) )
}) })

View File

@ -48,10 +48,8 @@ Case "Running a single source".
let bindings = project->Project.getBindings("main") let bindings = project->Project.getBindings("main")
/* Let's display the result and bindings */ /* Let's display the result and bindings */
( (result->Reducer_Value.toStringResult, bindings->Reducer_Value.toStringRecord)->expect ==
result->Reducer_Value.toStringResult, ("Ok(3)", "{}")
bindings->Reducer_Value.toStringRecord,
)->expect == ("Ok(3)", "{}")
/* You've got 3 with empty bindings. */ /* 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. */ /* 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. */ /* Examples above was to prepare you for the multi source tutorial. */
let (result, bindings) = Project.evaluate("1+2") let (result, bindings) = Project.evaluate("1+2")
( (result->Reducer_Value.toStringResult, bindings->Reducer_Value.toStringRecord)->expect ==
result->Reducer_Value.toStringResult, ("Ok(3)", "{}")
bindings->Reducer_Value.toStringRecord,
)->expect == ("Ok(3)", "{}")
}) })
}) })
}) })

View File

@ -30,10 +30,8 @@ describe("ReducerProject Tutorial", () => {
let result3 = project->Project.getResult("source3") let result3 = project->Project.getResult("source3")
let bindings3 = project->Project.getBindings("source3") let bindings3 = project->Project.getBindings("source3")
( (result3->Reducer_Value.toStringResult, bindings3->Reducer_Value.toStringRecord)->expect ==
result3->Reducer_Value.toStringResult, ("Ok(())", "{z: 3}")
bindings3->Reducer_Value.toStringRecord,
)->expect == ("Ok(())", "{z: 3}")
}) })
test("Depending", () => { test("Depending", () => {
@ -56,10 +54,8 @@ describe("ReducerProject Tutorial", () => {
let result3 = project->Project.getResult("source3") let result3 = project->Project.getResult("source3")
let bindings3 = project->Project.getBindings("source3") let bindings3 = project->Project.getBindings("source3")
( (result3->Reducer_Value.toStringResult, bindings3->Reducer_Value.toStringRecord)->expect ==
result3->Reducer_Value.toStringResult, ("Ok(())", "{z: 3}")
bindings3->Reducer_Value.toStringRecord,
)->expect == ("Ok(())", "{z: 3}")
}) })
test("Intro to including", () => { test("Intro to including", () => {
@ -91,10 +87,8 @@ describe("ReducerProject Tutorial", () => {
let result3 = project->Project.getResult("source3") let result3 = project->Project.getResult("source3")
let bindings3 = project->Project.getBindings("source3") let bindings3 = project->Project.getBindings("source3")
( (result3->Reducer_Value.toStringResult, bindings3->Reducer_Value.toStringRecord)->expect ==
result3->Reducer_Value.toStringResult, ("Ok(())", "{z: 3}")
bindings3->Reducer_Value.toStringRecord,
)->expect == ("Ok(())", "{z: 3}")
/* /*
Doing it like this is too verbose for a storybook Doing it like this is too verbose for a storybook
But I hope you have seen the relation of setContinues and parseIncludes */ But I hope you have seen the relation of setContinues and parseIncludes */

View File

@ -144,10 +144,8 @@ Here we will finally proceed to a real life scenario. */
let bindings = project->Project.getBindings("main") let bindings = project->Project.getBindings("main")
/* And see the result and bindings.. */ /* And see the result and bindings.. */
test("recursive includes", () => { test("recursive includes", () => {
( (result->Reducer_Value.toStringResult, bindings->Reducer_Value.toStringRecord)->expect ==
result->Reducer_Value.toStringResult, ("Ok(6)", "{a: 6,b: 2}")
bindings->Reducer_Value.toStringRecord,
)->expect == ("Ok(6)", "{a: 6,b: 2}")
/* Everything as expected */ /* Everything as expected */
}) })
}) })

View File

@ -3,10 +3,7 @@ open Expect
open Reducer_TestHelpers open Reducer_TestHelpers
let expectEvalToBeOk = (code: string) => let expectEvalToBeOk = (code: string) =>
Reducer_Expression.BackCompatible.evaluateString(code) Reducer_Expression.BackCompatible.evaluateString(code)->E.R.isOk->expect->toBe(true)
->E.R.isOk
->expect
->toBe(true)
let registry = FunctionRegistry_Library.registry let registry = FunctionRegistry_Library.registry
let examples = E.A.to_list(FunctionRegistry_Core.Registry.allExamples(registry)) let examples = E.A.to_list(FunctionRegistry_Core.Registry.allExamples(registry))

View File

@ -26,93 +26,31 @@ let makeFn = (
) => makeFnMany(name, [{inputs: inputs, fn: fn}]) ) => makeFnMany(name, [{inputs: inputs, fn: fn}])
let library = [ let library = [
Make.ff2f( Make.ff2f(~name="add", ~fn=(x, y) => x +. y, ()), // infix + (see Reducer/Reducer_Peggy/helpers.ts)
~name="add", // infix + (see Reducer/Reducer_Peggy/helpers.ts) Make.ff2f(~name="subtract", ~fn=(x, y) => x -. y, ()), // infix -
~fn=(x, y) => x +. y, 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.ff2f( Make.ff2b(~name="equal", ~fn=(x, y) => x == y, ()), // infix == on numbers
~name="subtract", // infix - Make.bb2b(~name="equal", ~fn=(x, y) => x == y, ()), // infix == on booleans
~fn=(x, y) => x -. y, 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.ff2f( Make.ff2b(~name="smallerEq", ~fn=(x, y) => x <= y, ()), // infix <=
~name="multiply", // infix * Make.ff2b(~name="larger", ~fn=(x, y) => x > y, ()), // infix >
~fn=(x, y) => x *. y, 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.ff2f( Make.f2f(~name="unaryMinus", ~fn=x => -.x, ()), // unary prefix -
~name="divide", // infix / makeFn("not", [FRTypeNumber], inputs => {
~fn=(x, y) => x /. y, // unary prefix !
()
),
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 !
switch inputs { switch inputs {
| [IEvNumber(x)] => IEvBool(x != 0.)->Ok | [IEvNumber(x)] => IEvBool(x != 0.)->Ok
| _ => Error(impossibleError) | _ => Error(impossibleError)
} }
}), }),
makeFn("not", [FRTypeBool], inputs => { // unary prefix ! makeFn("not", [FRTypeBool], inputs => {
// unary prefix !
switch inputs { switch inputs {
| [IEvBool(x)] => IEvBool(!x)->Ok | [IEvBool(x)] => IEvBool(!x)->Ok
| _ => Error(impossibleError) | _ => Error(impossibleError)
@ -157,9 +95,7 @@ let library = [
}), }),
makeFn("javascriptraise", [FRTypeAny], inputs => { makeFn("javascriptraise", [FRTypeAny], inputs => {
switch inputs { switch inputs {
| [msg] => { | [msg] => Js.Exn.raiseError(msg->Reducer_Value.toString)
Js.Exn.raiseError(msg->Reducer_Value.toString)
}
| _ => Error(impossibleError) | _ => Error(impossibleError)
} }
}), }),

View File

@ -17,10 +17,7 @@ module Internals = {
->E.A2.fmap(((key, value)) => Wrappers.evArray([IEvString(key), value])) ->E.A2.fmap(((key, value)) => Wrappers.evArray([IEvString(key), value]))
->Wrappers.evArray ->Wrappers.evArray
let fromList = (items: array<Reducer_T.value>): result< let fromList = (items: array<Reducer_T.value>): result<Reducer_T.value, errorValue> =>
Reducer_T.value,
errorValue,
> =>
items items
->E.A2.fmap(item => { ->E.A2.fmap(item => {
switch (item: Reducer_T.value) { switch (item: Reducer_T.value) {

View File

@ -74,15 +74,10 @@ module Old = {
| _ => Error("Not a number") | _ => Error("Not a number")
} }
let parseNumberArray = (ags: array<Reducer_T.value>): Belt.Result.t< let parseNumberArray = (ags: array<Reducer_T.value>): Belt.Result.t<array<float>, string> =>
array<float>, E.A.fmap(parseNumber, ags) |> E.A.R.firstErrorOrOpen
string,
> => E.A.fmap(parseNumber, ags) |> E.A.R.firstErrorOrOpen
let parseDist = (args: Reducer_T.value): Belt.Result.t< let parseDist = (args: Reducer_T.value): Belt.Result.t<DistributionTypes.genericDist, string> =>
DistributionTypes.genericDist,
string,
> =>
switch args { switch args {
| IEvDistribution(x) => Ok(x) | IEvDistribution(x) => Ok(x)
| IEvNumber(x) => Ok(GenericDist.fromFloat(x)) | IEvNumber(x) => Ok(GenericDist.fromFloat(x))
@ -173,10 +168,9 @@ module Old = {
} }
} }
let dispatchToGenericOutput = ( let dispatchToGenericOutput = (call: Reducer_Value.functionCall, env: GenericDist.env): option<
call: Reducer_Value.functionCall, DistributionOperation.outputType,
env: GenericDist.env, > => {
): option<DistributionOperation.outputType> => {
let (fnName, args) = call let (fnName, args) = call
switch (fnName, args) { switch (fnName, args) {
| ("triangular" as fnName, [IEvNumber(f1), IEvNumber(f2), IEvNumber(f3)]) => | ("triangular" as fnName, [IEvNumber(f1), IEvNumber(f2), IEvNumber(f3)]) =>

View File

@ -5,10 +5,9 @@ let nameSpace = "List"
let requiresNamespace = true let requiresNamespace = true
module Internals = { module Internals = {
let makeFromNumber = ( let makeFromNumber = (n: float, value: Reducer_T.value): Reducer_T.value => IEvArray(
n: float, Belt.Array.make(E.Float.toInt(n), value),
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( 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), E.A.Floats.range(low, high, (high -. low +. 1.0)->E.Float.toInt)->E.A2.fmap(Wrappers.evNumber),

View File

@ -9,50 +9,13 @@ let library = [
~name="sqrt", ~name="sqrt",
~nameSpace="Math", ~nameSpace="Math",
~requiresNamespace=true, ~requiresNamespace=true,
~fn=(x) => Js.Math.pow_float(~base=x, ~exp=0.5), ~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,
(), (),
), ),
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, ()),
] ]

View File

@ -48,9 +48,7 @@ module Internal = {
SampleSetDist.map3(~fn, ~t1, ~t2, ~t3)->toType SampleSetDist.map3(~fn, ~t1, ~t2, ~t3)->toType
} }
let parseSampleSetArray = (arr: array<Reducer_T.value>): option< let parseSampleSetArray = (arr: array<Reducer_T.value>): option<array<SampleSetDist.t>> => {
array<SampleSetDist.t>,
> => {
let parseSampleSet = (value: Reducer_T.value): option<SampleSetDist.t> => let parseSampleSet = (value: Reducer_T.value): option<SampleSetDist.t> =>
switch value { switch value {
| IEvDistribution(SampleSet(dist)) => Some(dist) | IEvDistribution(SampleSet(dist)) => Some(dist)

View File

@ -73,8 +73,7 @@ let getTag = (variant: squiggleValue): squiggleValueTag =>
} }
@genType @genType
let toString = (variant: squiggleValue) => let toString = (variant: squiggleValue) => Reducer_Value.toString(variant)
Reducer_Value.toString(variant)
// This is a useful method for unit tests. // This is a useful method for unit tests.
// Convert the result along with the error message to a string. // Convert the result along with the error message to a string.

View File

@ -2,9 +2,7 @@ type squiggleValue = ForTS_SquiggleValue.squiggleValue
@genType type squiggleValue_Array = ForTS_SquiggleValue.squiggleValue_Array //re-export recursive type @genType type squiggleValue_Array = ForTS_SquiggleValue.squiggleValue_Array //re-export recursive type
@genType @genType
let getValues = (v: squiggleValue_Array): array<squiggleValue> => let getValues = (v: squiggleValue_Array): array<squiggleValue> => Reducer_Value.arrayToValueArray(v)
Reducer_Value.arrayToValueArray(v)
@genType @genType
let toString = (v: squiggleValue_Array): string => let toString = (v: squiggleValue_Array): string => Reducer_Value.toStringArray(v)
Reducer_Value.toStringArray(v)

View File

@ -1,5 +1,4 @@
@genType type squiggleValue_Declaration = Reducer_T.lambdaDeclaration //re-export @genType type squiggleValue_Declaration = Reducer_T.lambdaDeclaration //re-export
@genType @genType
let toString = (v: squiggleValue_Declaration): string => let toString = (v: squiggleValue_Declaration): string => Reducer_Value.toStringDeclaration(v)
Reducer_Value.toStringDeclaration(v)

View File

@ -1,5 +1,4 @@
@genType type squiggleValue_Distribution = ForTS_Distribution.distribution @genType type squiggleValue_Distribution = ForTS_Distribution.distribution
@genType @genType
let toString = (v: squiggleValue_Distribution): string => let toString = (v: squiggleValue_Distribution): string => Reducer_Value.toStringDistribution(v)
Reducer_Value.toStringDistribution(v)

View File

@ -1,8 +1,7 @@
@genType type squiggleValue_Lambda = Reducer_T.lambdaValue //re-export @genType type squiggleValue_Lambda = Reducer_T.lambdaValue //re-export
@genType @genType
let toString = (v: squiggleValue_Lambda): string => let toString = (v: squiggleValue_Lambda): string => Reducer_Value.toStringFunction(v)
Reducer_Value.toStringFunction(v)
@genType @genType
let parameters = (v: squiggleValue_Lambda): array<string> => { let parameters = (v: squiggleValue_Lambda): array<string> => {

View File

@ -6,5 +6,4 @@ let getKeyValuePairs = (value: squiggleValue_Type): array<(string, squiggleValue
Reducer_Value.recordToKeyValuePairs(value) Reducer_Value.recordToKeyValuePairs(value)
@genType @genType
let toString = (value: squiggleValue_Type): string => let toString = (value: squiggleValue_Type): string => Reducer_Value.toStringType(value)
Reducer_Value.toStringType(value)

View File

@ -179,10 +179,9 @@ module FRType = {
| FRValueAny(f) => matchReverse(f) | FRValueAny(f) => matchReverse(f)
} }
let matchWithExpressionValueArray = ( let matchWithExpressionValueArray = (inputs: array<t>, args: array<Reducer_T.value>): option<
inputs: array<t>, array<frValue>,
args: array<Reducer_T.value>, > => {
): option<array<frValue>> => {
let isSameLength = E.A.length(inputs) == E.A.length(args) let isSameLength = E.A.length(inputs) == E.A.length(args)
if !isSameLength { if !isSameLength {
None None

View File

@ -278,10 +278,10 @@ module Make = {
Q: What about polymorphic functions with multiple definitions? Why ~fn is not an array? 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. 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 = ( let f2f = (
~name: string, ~name: string,
~fn: (float) => float, ~fn: float => float,
~nameSpace="", ~nameSpace="",
~requiresNamespace=false, ~requiresNamespace=false,
~examples=?, ~examples=?,
@ -290,22 +290,22 @@ module Make = {
Function.make( Function.make(
~name, ~name,
~nameSpace, ~nameSpace,
~requiresNamespace=requiresNamespace, ~requiresNamespace,
~examples=examples->E.O.default([], _), ~examples=examples->E.O.default([], _),
~output=EvtNumber, ~output=EvtNumber,
~definitions=[ ~definitions=[
FnDefinition.make( FnDefinition.make(
~name, ~name,
~inputs=[FRTypeNumber], ~inputs=[FRTypeNumber],
~run=((inputs, _, _, _) => ~run=(inputs, _, _, _) =>
switch inputs { switch inputs {
| [IEvNumber(x)] => fn(x)->IEvNumber->Ok | [IEvNumber(x)] => fn(x)->IEvNumber->Ok
| _ => Error(impossibleError) | _ => Error(impossibleError)
}), },
() (),
) ),
], ],
() (),
) )
} }
@ -320,22 +320,22 @@ module Make = {
Function.make( Function.make(
~name, ~name,
~nameSpace, ~nameSpace,
~requiresNamespace=requiresNamespace, ~requiresNamespace,
~examples=examples->E.O.default([], _), ~examples=examples->E.O.default([], _),
~output=EvtNumber, ~output=EvtNumber,
~definitions=[ ~definitions=[
FnDefinition.make( FnDefinition.make(
~name, ~name,
~inputs=[FRTypeNumber, FRTypeNumber], ~inputs=[FRTypeNumber, FRTypeNumber],
~run=((inputs, _, _, _) => ~run=(inputs, _, _, _) =>
switch inputs { switch inputs {
| [IEvNumber(x), IEvNumber(y)] => fn(x, y)->IEvNumber->Ok | [IEvNumber(x), IEvNumber(y)] => fn(x, y)->IEvNumber->Ok
| _ => Error(impossibleError) | _ => Error(impossibleError)
}), },
() (),
) ),
], ],
() (),
) )
} }
@ -350,22 +350,22 @@ module Make = {
Function.make( Function.make(
~name, ~name,
~nameSpace, ~nameSpace,
~requiresNamespace=requiresNamespace, ~requiresNamespace,
~examples=examples->E.O.default([], _), ~examples=examples->E.O.default([], _),
~output=EvtBool, ~output=EvtBool,
~definitions=[ ~definitions=[
FnDefinition.make( FnDefinition.make(
~name, ~name,
~inputs=[FRTypeNumber, FRTypeNumber], ~inputs=[FRTypeNumber, FRTypeNumber],
~run=((inputs, _, _, _) => ~run=(inputs, _, _, _) =>
switch inputs { switch inputs {
| [IEvNumber(x), IEvNumber(y)] => fn(x, y)->IEvBool->Ok | [IEvNumber(x), IEvNumber(y)] => fn(x, y)->IEvBool->Ok
| _ => Error(impossibleError) | _ => Error(impossibleError)
}), },
() (),
) ),
], ],
() (),
) )
} }
@ -380,22 +380,22 @@ module Make = {
Function.make( Function.make(
~name, ~name,
~nameSpace, ~nameSpace,
~requiresNamespace=requiresNamespace, ~requiresNamespace,
~examples=examples->E.O.default([], _), ~examples=examples->E.O.default([], _),
~output=EvtBool, ~output=EvtBool,
~definitions=[ ~definitions=[
FnDefinition.make( FnDefinition.make(
~name, ~name,
~inputs=[FRTypeBool, FRTypeBool], ~inputs=[FRTypeBool, FRTypeBool],
~run=((inputs, _, _, _) => ~run=(inputs, _, _, _) =>
switch inputs { switch inputs {
| [IEvBool(x), IEvBool(y)] => fn(x, y)->IEvBool->Ok | [IEvBool(x), IEvBool(y)] => fn(x, y)->IEvBool->Ok
| _ => Error(impossibleError) | _ => Error(impossibleError)
}), },
() (),
) ),
], ],
() (),
) )
} }
} }

View File

@ -9,5 +9,4 @@ let createContext = (stdLib: Reducer_Namespace.t, environment: Reducer_T.environ
} }
} }
let createDefaultContext = (): t => let createDefaultContext = (): t => createContext(SquiggleLibrary_StdLib.stdLib, defaultEnvironment)
createContext(SquiggleLibrary_StdLib.stdLib, defaultEnvironment)

View File

@ -103,9 +103,7 @@ let rec evaluate: T.reducerFn = (expression, context): (T.value, T.context) => {
context, context,
) )
| _ => | _ =>
RENotAFunction(lambda->Reducer_Value.toString) RENotAFunction(lambda->Reducer_Value.toString)->Reducer_ErrorValue.ErrorException->raise
->Reducer_ErrorValue.ErrorException
->raise
} }
} }
} }

View File

@ -24,9 +24,7 @@ let mergeMany = (namespaces: array<t>): t =>
let toString = (namespace: t) => let toString = (namespace: t) =>
namespace namespace
->Belt.Map.String.toArray ->Belt.Map.String.toArray
->Belt.Array.map(((eachKey, eachValue)) => ->Belt.Array.map(((eachKey, eachValue)) => `${eachKey}: ${eachValue->Reducer_Value.toString}`)
`${eachKey}: ${eachValue->Reducer_Value.toString}`
)
->Js.Array2.toString ->Js.Array2.toString
let fromArray = (a): t => Belt.Map.String.fromArray(a) let fromArray = (a): t => Belt.Map.String.fromArray(a)

View File

@ -16,10 +16,7 @@ let isMax = (modifierArg: Reducer_Value.t, aValue: Reducer_Value.t): bool => {
} }
} }
let isMemberOf = ( let isMemberOf = (modifierArg: Reducer_Value.t, aValue: Reducer_Value.t): bool => {
modifierArg: Reducer_Value.t,
aValue: Reducer_Value.t,
): bool => {
let pair = (modifierArg, aValue) let pair = (modifierArg, aValue)
switch pair { switch pair {
| (ievA, IEvArray(b)) => Js.Array2.includes(b, ievA) | (ievA, IEvArray(b)) => Js.Array2.includes(b, ievA)
@ -27,11 +24,7 @@ let isMemberOf = (
} }
} }
let checkModifier = ( let checkModifier = (key: string, modifierArg: Reducer_Value.t, aValue: Reducer_Value.t): bool =>
key: string,
modifierArg: Reducer_Value.t,
aValue: Reducer_Value.t,
): bool =>
switch key { switch key {
| "min" => isMin(modifierArg, aValue) | "min" => isMin(modifierArg, aValue)
| "max" => isMax(modifierArg, aValue) | "max" => isMax(modifierArg, aValue)

View File

@ -13,16 +13,13 @@ let stdLib: Reducer_T.namespace = {
Reducer_Expression_Lambda.makeFFILambda((inputs, _, _) => { Reducer_Expression_Lambda.makeFFILambda((inputs, _, _) => {
switch inputs { switch inputs {
| [IEvArray(aValueArray), IEvNumber(fIndex)] => { | [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) { switch Belt.Array.get(aValueArray, index) {
| Some(value) => value | Some(value) => value
| None => | None => REArrayIndexNotFound("Array index not found", index)->ErrorException->raise
REArrayIndexNotFound("Array index not found", index) }
->ErrorException
->raise
} }
}
| [IEvRecord(dict), IEvString(sIndex)] => | [IEvRecord(dict), IEvString(sIndex)] =>
switch Belt.Map.String.get(dict, sIndex) { switch Belt.Map.String.get(dict, sIndex) {
| Some(value) => value | Some(value) => value