|
| 1 | +# Syntax |
| 2 | + |
| 3 | +The following listing shows the syntax of Plutus. |
| 4 | +The corresponding Haskell definition can be found in [UntypedPlutusCore.Core.Type](https://plutus.cardano.intersectmbo.org/haddock/latest/plutus-core/UntypedPlutusCore-Core-Type.html#t:Term). |
| 5 | + |
| 6 | +```text |
| 7 | +𝐿, 𝑀, 𝑁 ∈ Term ::= 𝑥 variable |
| 8 | + | (con T 𝑐) constant 𝑐 with type T |
| 9 | + | (builtin 𝑏) builtin |
| 10 | + | (lam 𝑥 𝑀) lambda abstraction |
| 11 | + | [𝑀 𝑁] application |
| 12 | + | (delay 𝑀) delayed execution of a term |
| 13 | + | (force 𝑀) force execution of a term |
| 14 | + | (constr 𝑘 𝑀₀ … 𝑀ₘ₋₁) constructor with tag 𝑘 and 𝑚 arguments |
| 15 | + | (case 𝑀 𝑁₀ … 𝑁ₘ₋₁) case analysis with 𝑚 alternatives |
| 16 | + | (error) error |
| 17 | +
|
| 18 | +𝑃 ∈ Program ::= (program 𝑣 𝑀) versioned program |
| 19 | +``` |
| 20 | + |
| 21 | +Plutus (Untyped Plutus Core) is untyped in the sense that variables don't have type tags, and the same variable can have different types during evaluation. |
| 22 | +Constants, however, do carry type tags. |
| 23 | +A constant must be of a builtin type. |
| 24 | +Builtin types and functions are listed in [Builtin Types and Functions](./builtin.md). |
| 25 | + |
| 26 | +## Version Numbers |
| 27 | + |
| 28 | +The 𝑣 in a program is the _Plutus Core language version_. |
| 29 | +This is distinct from the Plutus ledger language version. |
| 30 | +For a detailed explanation, see [Different Notions of Version](https://plutus.cardano.intersectmbo.org/docs/essential-concepts/versions). |
| 31 | + |
| 32 | +## Iterated Applications |
| 33 | + |
| 34 | +An application of a term 𝑀 to a term 𝑁 is represented by `[𝑀 𝑁]`. |
| 35 | +We may occasionally write `[𝑀 𝑁₁ … 𝑁ₖ]` or `[𝑀 𝑁]` as an abbreviation for an iterated application `[ … [[𝑀 𝑁₁] 𝑁₂] … 𝑁ₖ]`. |
| 36 | + |
| 37 | +## Constructor Tags |
| 38 | + |
| 39 | +Constructor tags can in principle be any natural number. |
| 40 | +In practice, since they cannot be dynamically constructed, we can limit them to a fixed size without having to worry about overflow. |
| 41 | +So we limit them to 64 bits, although this is currently only enforced in the binary format. |
| 42 | +The Haskell definition uses `Word64` for the tag. |
| 43 | + |
| 44 | +## de Bruijn Indices |
| 45 | + |
| 46 | +Variable `𝑥` in the above listing can be either textual strings or de Bruijn indices. |
| 47 | +de Bruijn indices are used in serialized scripts. |
| 48 | +It therefore makes the most sense for a CEK machine implementation to use de Bruijn indices. |
| 49 | + |
| 50 | +## The `data` Type |
| 51 | + |
| 52 | +We provide a built-in type, `data`, which permits the encoding of simple data structures |
| 53 | +for use as arguments to Plutus Core scripts. |
| 54 | +The Haskell definition of `data` can be found in [PlutusCore.Data](https://plutus.cardano.intersectmbo.org/haddock/latest/plutus-core/PlutusCore-Data.html#t:Data). |
0 commit comments