diff --git a/packages/squiggle-lang/src/js/index.ts b/packages/squiggle-lang/src/js/index.ts index 34318424..98a79b84 100644 --- a/packages/squiggle-lang/src/js/index.ts +++ b/packages/squiggle-lang/src/js/index.ts @@ -2,9 +2,11 @@ import * as _ from "lodash"; import { genericDist, samplingParams, + environment, evaluatePartialUsingExternalBindings, externalBindings, expressionValue, + recordEV, errorValue, distributionError, toPointSet, @@ -15,6 +17,8 @@ import { mixedShape, sampleSetDist, symbolicDist, + defaultEnvironment, + defaultSamplingEnv, } from "../rescript/TypescriptInterface.gen"; export { makeSampleSetDist, @@ -50,10 +54,7 @@ import { } from "../rescript/Distributions/DistributionOperation/DistributionOperation.gen"; export type { samplingParams, errorValue, externalBindings as bindings }; -export let defaultSamplingInputs: samplingParams = { - sampleCount: 10000, - xyPointLength: 10000, -}; +export let defaultSamplingInputs: samplingParams = defaultSamplingEnv; export type result = | { @@ -90,8 +91,9 @@ export type squiggleExpression = | tagged<"symbol", string> | tagged<"string", string> | tagged<"call", string> - | tagged<"lambda", [string[], internalCode]> + | tagged<"lambda", [string[], recordEV, internalCode]> | tagged<"array", squiggleExpression[]> + | tagged<"arrayString", string[]> | tagged<"boolean", boolean> | tagged<"distribution", Distribution> | tagged<"number", number> @@ -100,16 +102,16 @@ export type squiggleExpression = export function run( squiggleString: string, bindings?: externalBindings, - samplingInputs?: samplingParams + samplingInputs?: samplingParams, + environ?: environment ): result { let b = bindings ? bindings : {}; let si: samplingParams = samplingInputs ? samplingInputs : defaultSamplingInputs; - - let result: result = - evaluateUsingExternalBindings(squiggleString, b); - return resultMap(result, (x) => createTsExport(x, si)); + let e = environ ? environ : defaultEnvironment; + let res: result = eval(squiggleString); // , b, e); + return resultMap(res, (x) => createTsExport(x, si)); } // Run Partial. A partial is a block of code that doesn't return a value @@ -118,7 +120,11 @@ export function runPartial( bindings: externalBindings, _samplingInputs?: samplingParams ): result { - return evaluatePartialUsingExternalBindings(squiggleString, bindings); + return evaluatePartialUsingExternalBindings( + squiggleString, + bindings, + defaultEnvironment + ); } function createTsExport( @@ -158,6 +164,8 @@ function createTsExport( } }) ); + case "EvArrayString": + return tag("arrayString", x.value); case "EvBool": return tag("boolean", x.value); case "EvCall": diff --git a/packages/squiggle-lang/src/rescript/ReducerInterface/ReducerInterface_GenericDistribution.res b/packages/squiggle-lang/src/rescript/ReducerInterface/ReducerInterface_GenericDistribution.res index a5c5b22e..ceac0800 100644 --- a/packages/squiggle-lang/src/rescript/ReducerInterface/ReducerInterface_GenericDistribution.res +++ b/packages/squiggle-lang/src/rescript/ReducerInterface/ReducerInterface_GenericDistribution.res @@ -1,11 +1,13 @@ module ExpressionValue = ReducerInterface_ExpressionValue type expressionValue = ReducerInterface_ExpressionValue.expressionValue -let runGenericOperation = DistributionOperation.run( - ~env={ +let defaultEnv: DistributionOperation.env = { sampleCount: MagicNumbers.Environment.defaultSampleCount, xyPointLength: MagicNumbers.Environment.defaultXYPointLength, - }, + } + +let runGenericOperation = DistributionOperation.run( + ~env=defaultEnv, ) module Helpers = { diff --git a/packages/squiggle-lang/src/rescript/ReducerInterface/ReducerInterface_GenericDistribution.resi b/packages/squiggle-lang/src/rescript/ReducerInterface/ReducerInterface_GenericDistribution.resi index 7f26a610..038f4479 100644 --- a/packages/squiggle-lang/src/rescript/ReducerInterface/ReducerInterface_GenericDistribution.resi +++ b/packages/squiggle-lang/src/rescript/ReducerInterface/ReducerInterface_GenericDistribution.resi @@ -1,3 +1,4 @@ +let defaultEnv: DistributionOperation.env let dispatch: ( ReducerInterface_ExpressionValue.functionCall, ReducerInterface_ExpressionValue.environment, diff --git a/packages/squiggle-lang/src/rescript/TypescriptInterface.res b/packages/squiggle-lang/src/rescript/TypescriptInterface.res index 70f3a3d1..114dc4e6 100644 --- a/packages/squiggle-lang/src/rescript/TypescriptInterface.res +++ b/packages/squiggle-lang/src/rescript/TypescriptInterface.res @@ -49,6 +49,9 @@ type externalBindings = Reducer.externalBindings @genType type expressionValue = ReducerInterface_ExpressionValue.expressionValue +@genType +type recordEV = ReducerInterface_ExpressionValue.record + @genType type errorValue = Reducer_ErrorValue.errorValue @@ -72,3 +75,12 @@ let distributionErrorToString = DistributionTypes.Error.toString @genType type internalCode = ReducerInterface_ExpressionValue.internalCode + +@genType +let defaultSamplingEnv = ReducerInterface_GenericDistribution.defaultEnv + +@genType +type environment = ReducerInterface_ExpressionValue.environment + +@genType +let defaultEnvironment = ReducerInterface_ExpressionValue.defaultEnvironment