Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@prism-lang/confidence

HaruHunab132040MIT1.2.3TypeScript support: included

Confidence extraction library for Prism - standardized patterns for extracting confidence values from LLMs and other sources

prism, confidence, uncertainty, llm, ai, extraction, calibration

readme

@prism-lang/confidence

Confidence extraction library for Prism - standardized patterns for extracting confidence values from LLMs and other sources.

📚 Full Documentation | 🔧 API Reference | 💡 Examples

Overview

Since most LLM providers (except OpenAI) don't provide log probabilities, this library focuses on practical confidence extraction methods:

  • Consistency-based extraction - Sample multiple times and measure agreement
  • Response analysis - Detect hedging language and certainty markers
  • Structured parsing - Extract explicit confidence values from responses
  • Domain calibration - Adjust confidence based on domain-specific knowledge
  • Ensemble methods - Combine multiple confidence signals

Installation

npm install @prism-lang/confidence

Quick Start

Level 1: Simple API

import { confidence } from '@prism-lang/confidence';

// Extract confidence from any response
const response = "I'm fairly certain this is a SQL injection vulnerability.";
const result = await confidence.extract(response);
console.log(result.value); // 0.72
console.log(result.explanation); // "Response analysis confidence: 72.0% based on..."

Level 2: Controlled Extraction

import { confidence } from '@prism-lang/confidence';

// Specify extraction method
const result = await confidence.extractWithOptions(response, {
  method: 'response_analysis',
  checkHedging: true,
  checkCertainty: true
});

Level 3: Full Control

import { ConfidenceExtractor, ConfidenceEnsemble, SecurityCalibrator } from '@prism-lang/confidence';

const extractor = new ConfidenceExtractor();
const ensemble = new ConfidenceEnsemble({ 
  weights: { consistency: 0.4, analysis: 0.3, structured: 0.3 } 
});

// Multiple extraction methods
const signals = {
  consistency: await extractor.fromConsistency(async () => llm(prompt), { samples: 5 }),
  analysis: await extractor.fromResponseAnalysis(response),
  structured: await extractor.fromStructuredResponse(response)
};

// Combine signals
const combined = ensemble.combine(signals);

// Apply domain calibration
const calibrator = new SecurityCalibrator();
const final = await calibrator.calibrate(combined.value, { 
  type: 'sql_injection',
  codeFeatures: ['parameterized_queries'] 
});

Core Features

1. Consistency-Based Extraction

const sampler = async () => llm("Is this code secure?");
const result = await extractor.fromConsistency(sampler, {
  samples: 5,
  temperature: [0.1, 0.3, 0.5, 0.7, 0.9]
});

2. Response Analysis

const result = await extractor.fromResponseAnalysis(llmResponse, {
  checkHedging: true,     // "might be", "possibly"
  checkCertainty: true,   // "definitely", "certainly"
  checkSpecificity: true, // Specific details vs vague
  checkCompleteness: true // Response length and structure
});

3. Structured Response Parsing

// Automatically detects patterns like:
// - "confidence: 85%"
// - "certainty: high"
// - "7/10 confident"
const result = await extractor.fromStructuredResponse(response);

4. Domain Calibration

// Pre-built calibrators
import { calibrators } from '@prism-lang/confidence';

const calibrated = await calibrators.security.calibrate(0.8, {
  type: 'sql_injection',
  codeComplexity: 'high'
});

// Custom calibrator
class MyCalibrator extends DomainCalibrator {
  // ... implement domain-specific logic
}

5. Confidence Patterns

Confidence Budgets

const budget = new ConfidenceBudgetManager(2.5); // Require total confidence of 2.5

budget.add(result1, 0.8);
budget.add(result2, 0.9);

if (!budget.met()) {
  const result3 = await getThirdOpinion();
  budget.add(result3, 0.9);
}

Confidence Contracts

const contract = new ConfidenceContractManager({
  security_check: 0.9,
  performance_check: 0.7,
  style_check: 0.5
});

const verification = contract.verify(results);
if (!verification.passed) {
  console.log('Failed checks:', verification.failures);
}

Differential Confidence

const differential = new DifferentialConfidenceManager();
differential.setAspect('disease_identification', 0.9);
differential.setAspect('severity_assessment', 0.6);
differential.setAspect('treatment_selection', 0.4);

const highest = differential.getHighest();
// Use appropriate confidence for each decision

6. Non-LLM Sources

Sensor Confidence

const sensorExtractor = new SensorConfidenceExtractor();
const confidence = sensorExtractor.fromSensor(reading, {
  age: sensor.daysSinceCalibration(),
  environment: { temperature: 25, humidity: 60 },
  history: 0.95 // Historical accuracy
});

API Reliability

const apiExtractor = new APIConfidenceExtractor();
const confidence = apiExtractor.fromAPIReliability({
  provider: 'weather.com',
  historicalAccuracy: 0.85,
  latency: 250,
  lastFailure: new Date('2024-01-01')
});

Using with Prism

import confidence from "@prism-lang/confidence"

// Simple extraction
response = llm("Analyze this code")
conf = confidence.extract(response)
result = response ~> conf

// Consistency-based
samples = confidence.sample(
  prompt => llm(prompt),
  "Is this secure?",
  n=5
)
conf = confidence.from_consistency(samples)
result = samples[0] ~> conf

// With calibration
calibrator = confidence.calibrators.security
raw_conf = confidence.extract(response)
calibrated = calibrator.calibrate(raw_conf, {type: "sql_injection"})
result = response ~> calibrated

// Confidence-aware control flow
uncertain if (result) {
  high { deploy() }
  medium { require_review() }
  low { escalate() }
}

Examples

See the /examples directory for complete examples including:

  • Security vulnerability analysis with confidence
  • Medical diagnosis with differential confidence
  • Sensor fusion with temporal decay
  • API response validation

Contributing

See CONTRIBUTING.md for guidelines.

License

MIT

changelog

Changelog

All notable changes to @prism-lang/core will be documented in this file.

[Unreleased]

Added

  • Module System Runtime Support - Complete runtime implementation for the module system introduced in v1.0.26

    • Import statements: default, named, namespace, and renamed imports
    • Export statements: default, named, re-exports, and direct exports
    • Module loading infrastructure with caching and circular dependency detection
    • Path resolution for relative imports
    • Import hoisting for proper execution order
    • Module isolation with separate environments
    • Full confidence preservation through module boundaries
    • Partial circular dependency support (functions can reference each other)
    • Comprehensive test coverage for all import/export patterns
  • Confident Ternary Operator (~?) - Propagates confidence through conditional expressions

    • Syntax: condition ~? trueBranch : falseBranch
    • Combines confidence from both condition and selected branch
    • Multiplies confidences for full propagation
    • Example: (true ~> 0.8) ~? ("yes" ~> 0.9) : "no" returns "yes" ~> 0.72
    • Differentiates from regular ternary which ignores confidence
  • Confident Assignment Operators - Syntactic sugar for confident arithmetic with assignment

    • ~+= - Confident addition assignment: x ~+= y same as x = x ~+ y
    • ~-= - Confident subtraction assignment: x ~-= y same as x = x ~- y
    • ~*= - Confident multiplication assignment: x ~*= y same as x = x ~* y
    • ~/= - Confident division assignment: x ~/= y same as x = x ~/ y
    • Preserves and combines confidence values during assignment
    • Useful for accumulating values with confidence tracking
  • Multi-Parameter Arrow Functions - Already supported, now with comprehensive tests

    • Support for 0 to N parameters: (a, b, c) => a + b + c
    • Works with array methods: reduce((acc, val) => acc + val, 0)
    • Nested multi-param lambdas: op => (a, b) => op == "+" ? a + b : a * b
    • Full documentation and test coverage

Improved

  • Documentation - Added comprehensive examples for lambda functions and confident operators
  • Test Coverage - Added extensive tests for multi-parameter lambdas, confident ternary, and confident assignment operators
  • Validator Updates - Added support for confident ternary expression in linter

Example

// Module system
import {sum, PI} from "./math.prism"
export result = sum(10, 20) * PI

// Confident ternary operator
message = condition ~? "Welcome!" : "Please verify"

// Confident assignment operators
total ~+= reading  // Accumulate with confidence

// Multi-parameter lambdas
sum = reduce(numbers, (acc, val) => acc + val, 0)

[1.2.1] - 2025-01-07

Added

  • Async/Await Support - Full asynchronous programming capabilities

    • async function declarations: async function fetchData() { ... }
    • await expressions for handling promises: result = await somePromise
    • Promise built-in functions:
      • Promise.resolve(value) - Creates a resolved promise
      • Promise.reject(reason) - Creates a rejected promise
      • Promise.all(promises) - Waits for all promises to resolve
    • delay(ms) and sleep(ms) functions for async delays
    • Confidence propagation through async operations
    • Comprehensive test coverage with 18 async/await tests
  • Strict Equality Operators - JavaScript-style comparison operators

    • === strict equality (no type coercion)
    • !== strict inequality (no type coercion)
    • Enhanced == and != with proper type coercion:
      • null == undefined returns true
      • Number/string/boolean coercion
      • Empty string equals false
    • Note: Arrays and objects compare by value in Prism, not reference
    • Full test suite for equality operators

Improved

  • Validator Enhancements
    • Fixed unknown node type warnings for ExportStatement, ImportStatement, VariableDeclaration
    • Added async/await validation with proper error messages
    • Fixed duplicate FunctionExpression case in validator
    • Improved import/export validation to match AST structure

Example

// Async/await example
async function analyzeData(input) ~> 0.9 {
  // Fetch data asynchronously
  data = await fetchFromAPI(input)

  // Process with LLM
  analysis = await llm("Analyze: " + data)

  // Wait for multiple operations
  results = await Promise.all([
    processA(data),
    processB(data),
    processC(data)
  ])

  return results
}

// Strict equality examples
"5" == 5    // true (type coercion)
"5" === 5   // false (no type coercion)
null == undefined   // true
null === undefined  // false

// Arrays compare by value
[1, 2, 3] === [1, 2, 3]  // true in Prism!

[1.0.26] - 2025-07-22

Added

  • Module import/export system - ES-module style imports and exports for code organization
  • Import statements - Full support for all import patterns
    • Default imports: import defaultName from "module"
    • Named imports: import {name1, name2} from "module"
    • Renamed imports: import {original as renamed} from "module"
    • Namespace imports: import * as name from "module"
    • Mixed imports: import defaultName, {named1, named2} from "module"
    • Empty imports: import {} from "side-effects-only"
  • Export statements - Comprehensive export functionality
    • Default exports: export default expression
    • Named exports: export {name1, name2}
    • Renamed exports: export {local as exported}
    • Re-exports: export {names} from "other-module"
    • Namespace re-exports: export * from "utilities"
    • Direct exports: export result = calculate()
  • New keywords - import, export, from, as for module syntax
  • AST support - New AST node types: ImportStatement, ExportStatement, ImportSpecifier, ExportSpecifier
  • Comprehensive test suite - 31 tests covering all import/export patterns and error cases
  • Trailing comma support - Allows trailing commas in import/export specifier lists
  • Proper error handling - Clear error messages for malformed module syntax

Example

// math.prism - utility module
export sum = (a, b) => a + b
export multiply = (a, b) => a * b
export const PI = 3.14159

// main.prism - application code
import {sum, PI} from "./math.prism"
import * as math from "./math.prism"
import defaultCalculator, {advanced} from "./calculator.prism"

// Use imported functions
result = sum(10, 20) * PI  // 94.2477
product = math.multiply(5, 6)  // 30

// Export processed results
export processedData = data.map(x => sum(x, 1))
export default finalResult = processedData.reduce(sum, 0)

// Re-export utilities
export {helper1, helper2} from "./helpers.prism"
export * from "./shared-utilities.prism"

Breaking Changes

  • None - this is a pure addition to the language

Implementation Notes

  • Module loading and resolution will be implemented in future versions
  • Import/export statements are parsed and represented in the AST
  • Runtime module system will follow ES module semantics
  • Supports relative paths, absolute paths, and package imports

[1.0.20] - 2025-07-08

Added

  • Function argument spread operator - Expand arrays as individual arguments in function calls
    • Use ...array syntax to spread array elements: max(...[1, 2, 3])
    • Combine multiple arrays: concat(...arr1, ...arr2)
    • Mix regular and spread arguments: fn(a, ...rest, b)
  • Rest parameters in function definitions - Collect variable arguments as an array
    • Use ...name in lambda parameters: (...args) => args.length
    • Regular params with rest: (first, ...rest) => first + rest.join(",")
    • Rest parameters preserve confidence values
    • Works seamlessly with array methods
  • Array.join() method - Convert array elements to string
    • Default separator is comma: [1, 2, 3].join() // "1,2,3"
    • Custom separator: ["a", "b", "c"].join(" ") // "a b c"
    • Handles null/undefined as empty strings

Example

// Spread operator in function calls
numbers = [1, 2, 3, 4, 5]
maxValue = max(...numbers)  // 5

// Rest parameters in lambdas
sum = (...nums) => nums.reduce((a, b) => a + b, 0)
total = sum(1, 2, 3, 4, 5)  // 15

// Combining features
greet = (greeting, ...names) => greeting + " " + names.join(" and ")
message = greet("Hello", "Alice", "Bob")  // "Hello Alice and Bob"

[1.0.19] - 2025-07-08

Added

  • JavaScript-style logical operators - The || and && operators now behave like JavaScript
    • || returns the first truthy value or the last value
    • && returns the first falsy value or the last value
    • Enables common patterns like name = userInput || "default"
    • Full short-circuit evaluation for better performance
  • Enhanced error messages - Runtime errors now include location information
    • Shows line and column numbers where errors occur
    • Example: Error at line 5, column 23: Cannot apply - to string and number
    • AST nodes now carry optional location information
    • Improved developer experience for debugging

Changed

  • Logical operators || and && now return actual values instead of booleans
  • Runtime error handling enhanced with location tracking

[1.0.18] - 2025-07-08

Added

  • Uncertainty-aware loops - Revolutionary loop constructs that adapt behavior based on confidence levels
  • Uncertain for loops - Execute different branches based on loop confidence
    • uncertain for i = 0; condition ~> confidence; i++
    • High, medium, and low confidence branches
    • Dynamic confidence evaluation at each iteration
  • Uncertain while loops - Conditional execution with confidence-based branching
    • uncertain while condition ~> confidence
    • Automatic branch selection based on confidence thresholds
    • Perfect for sensor monitoring and AI model inference
  • Confidence thresholds:
    • HIGH: confidence >= 0.7
    • MEDIUM: 0.5 <= confidence < 0.7
    • LOW: confidence < 0.5
  • Full support for break and continue within uncertainty branches
  • Seamless integration with existing confidence system

Example

// Uncertain for loop - adapt to confidence levels
uncertain for i = 0; (i < readings.length) ~> confidence; i++ {
  high {
    // Confidence >= 0.7 - fully automated
    processAutomatically(readings[i])
  }
  medium {
    // 0.5 <= confidence < 0.7 - human review
    flagForReview(readings[i])
  }
  low {
    // Confidence < 0.5 - alert and skip
    sendAlert(readings[i])
    break
  }
}

// Uncertain while - monitor with degradation handling
uncertain while (systemActive() ~> getSystemHealth()) {
  high {
    runNormalOperations()
  }
  medium {
    runDegradedMode()
  }
  low {
    enterSafeMode()
    break
  }
}

// AI inference with confidence-based retries
uncertain for attempt = 0; attempt < 3; attempt++ {
  high {
    return model.predict(input)
  }
  medium {
    // Use ensemble for medium confidence
    return ensemblePredict(input)
  }
  low {
    // Request human labeling
    return requestHumanInput(input)
  }
}

[1.0.17] - 2025-07-08

Added

  • Complete loop support - Standard JavaScript-style loops with Prism's unique features
  • C-style for loops - Traditional loops with init, condition, and update expressions
    • Optional parts: for ; i < 10; i++ or for i = 0; ; i++
    • Variables use outer scope (not block-scoped)
  • For-in loops - Iterate over array elements with optional index
    • for item in array { ... }
    • for item, index in array { ... }
    • Creates new scope for loop variables
  • While loops - Execute while condition is true
  • Do-while loops - Execute at least once, then check condition
  • Break and continue - Control flow within loops
    • Break exits the current loop
    • Continue skips to next iteration
  • Nested loops - Full support for loops within loops
  • Confidence preservation - Loops work seamlessly with confident values
  • Comprehensive test suite with 31 loop tests

Example

// C-style for loop
sum = 0
for i = 0; i < 5; i = i + 1 {
  sum = sum + i
}
// sum = 10 (0 + 1 + 2 + 3 + 4)

// For-in loop with array
arr = ["a", "b", "c"]
result = ""
for item, idx in arr {
  result = result + item + idx
}
// result = "a0b1c2"

// While loop
i = 0
while i < 3 {
  i = i + 1
}

// Do-while - executes at least once
count = 0
do {
  count = count + 1
} while false
// count = 1

// Break and continue
for i = 0; i < 10; i = i + 1 {
  if (i == 5) break      // Exit loop at 5
  if (i % 2 == 0) continue  // Skip even numbers
  // Process odd numbers only
}

// Works with confident values
data = [1, 2, 3] ~> 0.8
sum = 0
for item in data {
  sum = sum + item
}
// sum gets confidence from operations

// Nested loops
for i = 0; i < 3; i = i + 1 {
  for j = 0; j < 2; j = j + 1 {
    // Inner loop runs 6 times total
  }
}

[1.0.16] - 2025-07-08

Added

  • Array methods as properties - All array methods now available as properties for better ergonomics
  • array.map(fn) - Transform array elements with a function
  • array.filter(fn) - Filter elements based on a predicate
  • array.reduce(fn, init?) - Reduce array to a single value with optional initial value
  • array.forEach(fn) - Iterate over elements (returns undefined)
  • array.push(...items) - Add elements to array (returns new array, immutable)
  • All methods preserve confidence values when used on confident arrays
  • Methods intelligently handle optional parameters (e.g., index in reduce)
  • Both method syntax (arr.map(fn)) and function syntax (map(arr, fn)) are supported

Fixed

  • Lambda functions now properly track their arity for correct parameter handling
  • Array method callbacks receive the correct number of arguments based on their parameter count

Example

// Array methods as properties
numbers = [1, 2, 3, 4, 5]

// Map - transform elements
doubled = numbers.map(x => x * 2)         // [2, 4, 6, 8, 10]
squares = numbers.map(x => x ** 2)        // [1, 4, 9, 16, 25]

// Filter - select elements
evens = numbers.filter(x => x % 2 == 0)   // [2, 4]
large = numbers.filter(x => x > 3)        // [4, 5]

// Reduce - aggregate values
sum = numbers.reduce((a, b) => a + b)     // 15
product = numbers.reduce((a, b) => a * b, 1) // 120

// With index parameter
indexed = numbers.reduce((acc, val, idx) => acc + val * idx, 0) // 40

// ForEach - side effects (returns undefined)
result = numbers.forEach(x => x * 2)      // undefined

// Push - add elements (immutable)
original = [1, 2, 3]
expanded = original.push(4, 5)            // [1, 2, 3, 4, 5]
// original is still [1, 2, 3]

// Method chaining
result = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
  .filter(x => x % 2 == 0)               // [2, 4, 6, 8, 10]
  .map(x => x ** 2)                       // [4, 16, 36, 64, 100]
  .reduce((a, b) => a + b)                // 220

// Works with confident arrays
confident = [1, 2, 3] ~> 0.8
doubled = confident.map(x => x * 2)       // [2, 4, 6] ~> 0.8

// Both syntaxes work
methodResult = arr.map(x => x * 2)
functionResult = map(arr, x => x * 2)     // Same result

[1.0.15] - 2025-07-08

Added

  • Spread operator (...) - Essential for modern data manipulation
  • Array spreading: [...arr1, ...arr2] combines arrays immutably
  • Object spreading: {...obj1, ...obj2} merges objects with property overriding
  • Works seamlessly with confidence values by unwrapping before spreading
  • Enables clean, functional programming patterns

Example

// Array spreading
arr1 = [1, 2, 3]
arr2 = [4, 5, 6]
combined = [...arr1, ...arr2]  // [1, 2, 3, 4, 5, 6]
newArray = [0, ...arr1, 4]     // [0, 1, 2, 3, 4]

// Object spreading
defaults = {theme: "dark", lang: "en"}
userPrefs = {lang: "es", debug: true}
settings = {...defaults, ...userPrefs}  // {theme: "dark", lang: "es", debug: true}

// Override properties
user = {name: "Alice", age: 30}
updated = {...user, age: 31}  // {name: "Alice", age: 31}

// Multiple spreads
a = [1, 2]
b = [3, 4]
c = [5, 6]
all = [...a, ...b, ...c]  // [1, 2, 3, 4, 5, 6]

// Works with confidence
data = [1, 2, 3] ~> 0.8
extended = [...data, 4, 5]  // Spreads the array values

// Nested structures
config = {
  server: {host: "localhost", port: 3000},
  debug: true
}
production = {...config, debug: false}  // Overrides debug while keeping server

[1.0.14] - 2024-06-27

Added

  • Exponentiation operator (``)** - Mathematical power operations with right associativity
  • Nullish coalescing operator (??) - Returns right operand only for null/undefined values
  • Exponentiation has higher precedence than multiplication/division
  • Nullish coalescing differs from || by preserving falsy values like 0, false, and ""
  • Both operators work seamlessly with confidence values

Example

// Exponentiation - power operations
squared = 3 ** 2              // 9
cubed = 2 ** 3                // 8
rightAssoc = 2 ** 3 ** 2      // 2 ** 9 = 512

// With variables and expressions
base = 4
result = base ** 0.5          // 2 (square root)
complex = (base + 1) ** 2     // 25

// Nullish coalescing - precise null/undefined handling
// Different from || - preserves falsy values
port = process.env.PORT ?? 3000       // Uses 3000 only if PORT is null/undefined
enabled = config.enabled ?? true      // Keeps false if explicitly set
retries = options.retries ?? 0        // Keeps 0 if specified

// Chaining nullish coalescing
value = cache ?? database ?? defaultValue

// With optional chaining
user = { profile: null }
name = user?.profile?.name ?? "Anonymous"

// With confidence values
uncertain = getData() ~> 0.7
result = (uncertain ?? fallback) ** 2

[1.0.13] - 2024-06-27

Added

  • Optional chaining operator (?.) - Safe property access that returns null instead of throwing errors
  • Undefined support - undefined is now a proper value type, distinct from null
  • Undefined works with all operators including optional chaining
  • Both null and undefined are falsy but remain distinct values
  • Optional chaining works with arrays, objects, and nested properties

Example

// Optional chaining - safe navigation
user = { profile: null }
name = user?.profile?.name  // Returns null instead of throwing

// Undefined support
value = undefined
isEmpty = value == null      // false (undefined != null)
isUndefined = value == undefined  // true

// Optional chaining with undefined
data = { info: undefined }
result = data?.info?.details  // Returns null

// Distinction between null and undefined
missing = undefined          // Never assigned
empty = null                // Explicitly empty

// Both are falsy
if (!missing && !empty) {
  // This executes because both are falsy
}

// Safe navigation in complex structures
config = {
  server: {
    host: "localhost",
    port: undefined
  }
}
port = config?.server?.port ?? 3000  // Uses default 3000

[1.0.12] - 2024-06-27

Added

  • Compound assignment operators - +=, -=, *=, /=, %=
  • Compound assignments work with numbers, strings, and confidence values
  • String concatenation with += operator
  • All compound operators properly propagate confidence values

Example

// Numeric operations
score = 100
score += 25   // score = 125
score -= 10   // score = 115
score *= 2    // score = 230
score /= 5    // score = 46
score %= 10   // score = 6

// String concatenation
greeting = "Hello"
greeting += ", "
greeting += "World!"  // "Hello, World!"

// With confidence values
measurement = 50 ~> 0.9
adjustment = 10 ~> 0.7
measurement += adjustment  // 60 with 0.7 confidence (minimum)

[1.0.11] - 2024-06-27

Added

  • Null literal support - null is now a proper value type
  • Null can be used in variables, arrays, objects, and comparisons
  • Null works with all operators including ternary and logical operators
  • Null integrates with confidence system
  • Array methods handle null values properly

Example

// Basic null usage
value = null
isEmpty = value == null  // true

// Null in data structures
user = { name: "Alice", email: null }
data = [1, null, 3, null, 5]

// Null handling with array methods
validData = filter(data, x => x != null)  // [1, 3, 5]
mapped = map(data, x => x != null ? x * 2 : 0)  // [2, 0, 6, 0, 10]

// Null with confidence
uncertain = null ~> 0.5
fallback = uncertain ~?? "default"  // Uses fallback due to low confidence

[1.0.9] - 2024-06-26

Added

  • Lambda expressions with arrow syntax (=>)
  • Support for single parameter without parentheses: x => x * 2
  • Support for multiple parameters: (x, y) => x + y
  • Support for zero parameters: () => 42
  • Closures - lambdas can capture variables from outer scope
  • Modulo operator (%) for remainder operations
  • Integration of lambdas with array methods for functional programming

Example

// Lambda expressions
double = x => x * 2
add = (x, y) => x + y
getRandom = () => 42

// With array methods
numbers = [1, 2, 3, 4, 5]
squared = map(numbers, x => x * x)        // [1, 4, 9, 16, 25]
evens = filter(numbers, x => x % 2 == 0)  // [2, 4]
sum = reduce(numbers, (a, b) => a + b, 0) // 15

// Closures
multiplier = 10
scale = x => x * multiplier
scaled = scale(5)  // 50

// Currying
makeAdder = x => (y => x + y)
add10 = makeAdder(10)
result = add10(32)  // 42

[1.0.8] - 2024-06-25

Added

  • Array methods as built-in global functions
  • map(array, fn) - transform each element
  • filter(array, predicate) - keep elements matching predicate
  • reduce(array, reducer, initialValue?) - combine elements into single value
  • Confidence preservation through array transformations
  • Support for index parameter in reduce function

Example

// Array methods with confidence
data = [10, 20, 30] ~> 0.8
doubled = map(data, x => x * 2)           // [20, 40, 60] ~> 0.8
filtered = filter(data, x => x > 15)      // [20, 30] ~> 0.8
sum = reduce(data, (acc, val) => acc + val, 0)  // 60 ~> 0.8

// With index in reduce
indexed = reduce(data, (acc, val, idx) => acc + (val * idx), 0)

[1.0.7] - 2024-06-22

Added

  • String interpolation with ${} syntax inside strings
  • Support for complex expressions in interpolations
  • Nested interpolations with proper quote handling
  • Interpolation in multiline strings
  • Confidence value formatting in interpolations

Example

// Basic interpolation
name = "Alice"
greeting = "Hello, ${name}!"

// Complex expressions
user = { name: "Bob", age: 30 }
info = "${user.name} is ${user.age} years old"

// With ternary operators
score = 85
grade = "Your grade: ${score >= 90 ? "A" : "B"}"

// Multiline with interpolation
report =

User: ${name} Score: ${score} Grade: ${grade}

[1.0.6] - 2024-06-22

Added

  • Arrays and lists with literal syntax [1, 2, 3]
  • Objects/dictionaries with literal syntax { key: value }
  • Array methods: length property, index access array[0]
  • Object property access with dot notation object.property
  • Built-in array functions: map(), filter(), reduce()
  • Support for nested data structures and confidence propagation

Example

// Arrays and objects
scores = [85 ~> 0.9, 92 ~> 0.8, 78 ~> 0.7]
firstScore = scores[0]       # 85 (~90%)
count = scores.length        # 3

person = {
  name: "Alice",
  scores: scores,
  metadata: { verified: true }
}
name = person.name           # "Alice"
verified = person.metadata.verified  # true

[1.0.5] - 2024-06-22

Added

  • Ternary operator support (condition ? true : false)
  • Support for nested ternary expressions
  • Reduces need for verbose if-else statements

Example

status = age >= 18 ? "adult" : "minor"
grade = score >= 90 ? "A" : (score >= 80 ? "B" : "C")
action = confidence > 0.8 ? "auto-approve" : "manual-review"

[1.0.4] - 2024-06-22

Added

  • Multiline string support with triple backticks (`) - enables passing code snippets to LLMs
  • Standard escape sequences in strings (\n, \t, ", \, etc.)
  • Enhanced error messages showing line content and error position

Fixed

  • String literals now properly handle escape sequences instead of throwing errors
  • Parse errors now show helpful context including the problematic line and column marker

Example

// New multiline strings for code analysis
code =

function getUserData(userId) { const query = "SELECT * FROM users WHERE id = " + userId; return db.execute(query); }

analysis = llm("Find security issues in: " + code)

// Escape sequences now work
query = "SELECT * FROM users WHERE name = \"John\""

[1.0.3] - 2024-06-22

Fixed

  • LLM providers now properly initialize when API keys are provided
  • Fixed "No LLM provider configured" error when using geminiApiKey or anthropicApiKey options
  • Providers are automatically registered and set as default when API keys are available

[1.0.2] - 2024-06-22

Fixed

  • Updated GitHub repository URL in documentation to correct address

[1.0.1] - 2024-06-06

Added

  • Semicolon support for statement separation
  • Better handling of multiple statements per line
  • Backwards compatibility maintained (semicolons are optional)

Fixed

  • Parser now properly consumes semicolons after statements
  • Improved statement boundary detection

Known Issues

  • Multiple assignments on one line (e.g., x = 10; y = 20) still require workaround
  • Recommended: Use one statement per line for best results

[1.0.0] - 2024-06-06

Initial Release

  • 18 confidence-aware operators for uncertainty handling
  • Native LLM integration support
  • Uncertainty-aware control flow (uncertain if statements)
  • Automatic confidence propagation
  • Full TypeScript implementation
  • Interactive REPL
  • CLI tools (prism run, prism eval, prism repl)
  • npm package: @prism-lang/core