Skip to main content

Prism Quick Reference

A comprehensive cheat sheet for the Prism programming language.

Keywords

Declarations

KeywordDescriptionExample
letMutable variablelet count = 0
constImmutable bindingconst PI = 3.14
functionFunction declarationfunction add(a, b) { return a + b }
asyncAsync functionasync function fetch() { ... }
importImport moduleimport {sum} from "./math.prism"
exportExport valueexport const VERSION = "1.0"
fromImport sourceimport {x} from "./module.prism"
asImport aliasimport {x as y} from "./m.prism"

Control Flow

KeywordDescriptionExample
if / elseConditionalif x > 0 { ... } else { ... }
matchPattern matchingmatch value { 0 => "zero", _ => "other" }
forFor loopfor let i = 0; i < 10; i++ { ... }
for...inIterate arrayfor item in array { ... }
whileWhile loopwhile condition { ... }
do...whileDo-while loopdo { ... } while condition
breakExit loopbreak
continueNext iterationcontinue
returnReturn valuereturn result
tryTry blocktry { ... } catch (e) { ... }
catchCatch errorscatch (error) { ... }
finallyAlways executefinally { cleanup() }
awaitAwait promiseresult = await fetchData()

Uncertainty

KeywordDescriptionExample
uncertainConfidence-based controluncertain if (value) { ... }
highConfidence ≥ 0.7high { handleConfident() }
medium0.5 ≤ confidence < 0.7medium { needsReview() }
lowConfidence < 0.5low { reject() }
defaultFallback branchdefault { handleUnknown() }
contextContext blockcontext analysis { ... }
agentsAgent declarationsagents { assistant: { confidence: 0.9 } }

Literals

KeywordDescriptionExample
trueBoolean truelet isValid = true
falseBoolean falselet isValid = false
nullNull valuelet data = null
undefinedAlias of nulllet value = undefined

Type Checking

KeywordDescriptionExample
typeofGet type stringtypeof x == "number"
instanceofCheck instancex instanceof Array

Operators

Arithmetic

OperatorDescriptionExample
+Additiona + b
-Subtractiona - b
*Multiplicationa * b
/Divisiona / b
%Moduloa % b
**Exponentiationa ** 2
-xNegation-value
+xUnary plus+string
++Incrementi++ or ++i
--Decrementi-- or --i

Comparison

OperatorDescriptionExample
==Loose equalitya == b
!=Loose inequalitya != b
===Strict equalitya === b
!==Strict inequalitya !== b
<Less thana < b
>Greater thana > b
<=Less than or equala <= b
>=Greater than or equala >= b

Logical

OperatorDescriptionExample
&&Logical ANDa && b
||Logical ORa || b
!Logical NOT!value
??Nullish coalescinga ?? default

Assignment

OperatorDescriptionExample
=Assignmentlet x = 10
+=Add-assignx += 5
-=Subtract-assignx -= 5
*=Multiply-assignx *= 2
/=Divide-assignx /= 2
%=Modulo-assignx %= 3

Confidence Operators

Core Confidence

OperatorDescriptionExample
~>Attach confidencevalue ~> 0.85
~Extract confidence~value (returns 0.85)
<~Extract raw value<~value (returns value)

Confident Arithmetic

OperatorDescriptionExample
~+Confident adda ~+ b
~-Confident subtracta ~- b
~*Confident multiplya ~* b
~/Confident dividea ~/ b
~+=Confident add-assignx ~+= y
~-=Confident subtract-assignx ~-= y
~*=Confident multiply-assignx ~*= y
~/=Confident divide-assignx ~/= y

Confident Comparison

OperatorDescriptionExample
~==Confident equalitya ~== b
~!=Confident inequalitya ~!= b
~<Confident less thana ~< b
~>Confident greater thana ~> b
~<=Confident less/equala ~<= b
~>=Confident greater/equala ~>= b

Confident Logical

OperatorDescriptionExample
~&&Confident AND (min conf)a ~&& b
~||Confident OR (max conf)a ~|| b
~||>Parallel (highest conf wins)a ~||> b

Confident Special

OperatorDescriptionExample
~.Confident property accessobj~.prop
~?Confident ternarycond ~? a : b
~??Confidence coalescea ~?? b
~@>Threshold gatevalue ~@> 0.8
~|>Confidence pipelinedata ~|> process
~~Confidence chaininga ~~ b

Other Operators

OperatorDescriptionExample
|>Pipelinex |> fn1 |> fn2
?.Optional chainingobj?.prop?.nested
...Spread/rest[...arr] or ...params
? :Ternarycond ? a : b
->Context shiftcontext a -> b { }

Built-in Functions

Output

FunctionDescriptionExample
print(...)Print to consoleprint("Hello", value)
console.log(...)Log messageconsole.log("Info:", x)
console.warn(...)Warningconsole.warn("Caution")
console.error(...)Errorconsole.error("Failed")
console.debug(...)Debug infoconsole.debug("State:", s)

Array Operations

FunctionDescriptionExample
map(arr, fn)Transform elementsmap(nums, x => x * 2)
filter(arr, fn)Filter elementsfilter(nums, x => x > 0)
reduce(arr, fn, init)Reduce to valuereduce(nums, (a,b) => a+b, 0)

Math

FunctionDescriptionExample
max(...vals)Maximum valuemax(1, 5, 3)5
min(...vals)Minimum valuemin(1, 5, 3)1

Async

FunctionDescriptionExample
delay(ms)Wait millisecondsawait delay(1000)
sleep(ms)Alias for delayawait sleep(500)
debounce(ms)Create debouncerdebounce(300)
Promise.resolve(v)Resolved promisePromise.resolve(42)
Promise.reject(e)Rejected promisePromise.reject("err")
Promise.all(arr)Wait for allawait Promise.all([p1, p2])

Collections

FunctionDescriptionExample
sortBy(key, dir?)Create sortersortBy("name", "desc")
groupBy(key)Create groupergroupBy("category")

Confidence

FunctionDescriptionExample
confidence(val)Wrap with confidenceconfidence(0.9)(fn)
threshold(min)Filter by confidencethreshold(0.8)(data)

LLM

FunctionDescriptionExample
llm(prompt, opts?)Query LLMllm("Summarize this")
stream_llm(prompt, opts?)Stream LLMstream_llm("Draft...")

Common Patterns

Confident Value Creation

// Attach confidence to any value
let temperature = 23.5 ~> 0.92
let prediction = "sunny" ~> 0.75
let data = {score: 85} ~> 0.88

Uncertain Control Flow

uncertain if (prediction) {
high { executeWithConfidence() }
medium { requestReview() }
low { reject() }
default { handleUnknown() }
}

Async with Error Handling

async function safeFetch(url) {
try {
let response = await fetch(url)
return response ~> 0.95
} catch (error) {
console.error("Fetch failed:", error)
return null ~> 0.0
}
}

Pipeline Processing

let result = data
|> filter(x => x > 0)
|> map(x => x * 2)
|> sortBy("value", "desc")(_)
|> threshold(0.8)(_)

LLM with Confidence

let analysis = llm("Analyze: " + text)

uncertain if (analysis) {
high {
// High confidence response
applyAnalysis(analysis)
}
medium {
// Needs human review
flagForReview(analysis)
}
low {
// Unreliable, get more info
analysis = llm("Clarify: " + text, {temperature: 0.2})
}
}

Module Structure

// utils.prism
export const VERSION = "1.0.0"
export function validate(input) {
return input.length > 0
}

// main.prism
import {VERSION, validate} from "./utils.prism"
console.log("Version:", VERSION)

Destructuring

// Arrays
let [first, second, ...rest] = [1, 2, 3, 4, 5]

// Objects
let {name, age, city = "Unknown"} = user

// In function parameters
let processPoint = ({x, y}) => Math.sqrt(x*x + y*y)

Operator Precedence (High to Low)

  1. () - Grouping
  2. . ?. ~. [] - Property access
  3. ++ -- - Increment/decrement
  4. ! - + ~ <~ - Unary
  5. ** - Exponentiation
  6. * / % ~* ~/ - Multiplicative
  7. + - ~+ ~- - Additive
  8. < > <= >= ~< ~> ~<= ~>= - Relational
  9. == != === !== ~== ~!= - Equality
  10. && ~&& - Logical AND
  11. || ~|| ~||> - Logical OR
  12. ?? ~?? - Nullish/Confidence coalescing
  13. ~> - Confidence annotation
  14. ? : ~? - Ternary
  15. |> ~|> - Pipeline
  16. = += -= etc. - Assignment

Quick Tips

  • Confidence is optional: Regular values have implicit confidence of 1.0
  • Confidence propagates: Operations on confident values produce confident results
  • Use ~> for annotation: value ~> 0.85 creates a confident value
  • Use ~ for extraction: ~value gets the confidence level
  • Pipeline for clarity: x |> fn1 |> fn2 is clearer than fn2(fn1(x))
  • Async is everywhere: Most operations support async/await
  • Modules for organization: Use import/export for larger projects