squiggle/packages/website/docs/Features/Language.mdx

52 lines
1.5 KiB
Plaintext
Raw Normal View History

2022-03-25 02:08:46 +00:00
---
sidebar_position: 2
2022-04-27 20:28:10 +00:00
title: Language Basics
2022-03-25 02:08:46 +00:00
---
2022-04-11 00:13:11 +00:00
import { SquiggleEditor } from "../../src/components/SquiggleEditor";
2022-03-25 02:08:46 +00:00
The squiggle language has a very simple syntax. The best way to get to understand
2022-03-25 02:08:46 +00:00
it is by simply looking at examples.
## Expressions and statements
A squiggle **expression** is a value like a float or a distribution or a data structure like an array or a record.
<SquiggleEditor initialSquiggleString={`mixture(1 to 2, 3, [0.3, 0.7])`} />
2022-03-25 02:08:46 +00:00
The bottom line of your squiggle buffer should be an expression, which we evaluate (i.e., render). Sometimes we call the last expression of a squiggle file an _export_.
A squiggle **assignment** is a statement, when you want to bind an expression to a name.
2022-03-25 02:08:46 +00:00
2022-04-10 23:15:46 +00:00
<SquiggleEditor
initialSquiggleString={`value_of_work = 10 to 70
value_of_work`}
/>
2022-03-25 02:08:46 +00:00
### Functions
2022-03-25 02:08:46 +00:00
Some assignments are functions
2022-03-25 02:08:46 +00:00
<SquiggleEditor
initialSquiggleString={`ozzie_estimate(t) = lognormal(1, t ^ 1.01)
2022-04-27 20:28:10 +00:00
nuño_estimate(t) = mixture(0.5 to 2, normal(1, t ^ 1.25))
ozzie_estimate(5) * nuño_estimate(5.5)
`}
/>
2022-03-25 02:08:46 +00:00
## Data structures
2022-03-25 02:08:46 +00:00
A squiggle **array** is a list of expressions, which is interpretable as an export.
2022-03-25 02:08:46 +00:00
<SquiggleEditor
initialSquiggleString={`[cauchy(1,1), 4, isNormalized(toPointSet(1 to 2))]`}
/>
A squiggle **record** is a key-value store with dot accessors.
2022-03-25 02:08:46 +00:00
2022-04-10 23:15:46 +00:00
<SquiggleEditor
initialSquiggleString={`d1 = {dist: normal(0, 1), weight: 0.25}
2022-04-27 20:28:10 +00:00
d2 = {dist: 5 to 6, weight: 0.75}
mx(d1.dist, d2.dist, [d1.weight, d2.weight])`}
2022-04-10 23:15:46 +00:00
/>