Skip to content

Commit 8317300

Browse files
authored
Merge pull request #37 from cardano-scaling/zliu41/syntax
Plutus Syntax
2 parents 0b0dcd2 + b69f5b2 commit 8317300

File tree

3 files changed

+61
-0
lines changed

3 files changed

+61
-0
lines changed

src/SUMMARY.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
- [Transaction fee](ledger/transaction-fee.md)
2323
- [Block Validation](ledger/block-validation.md)
2424
- [Plutus](plutus/README.md)
25+
- [Syntax](plutus/syntax.md)
26+
- [Builtin Types and Functions](plutus/builtin.md)
2527
- [The CEK Machine](plutus/cek.md)
2628
- [API reference]()
2729
- [Node-To-Client (NTC)](api/node-to-client.md)

src/plutus/builtin.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Built-in Types and Functions

src/plutus/syntax.md

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# Syntax
2+
3+
The following listing shows the concrete 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 𝑏) built-in
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 (𝑚 ≥ 0).
15+
Available since 1.1.0
16+
| (case 𝑀 𝑁₁ … 𝑁ₘ) case analysis with 𝑚 alternatives (𝑚 ≥ 0).
17+
Available since 1.1.0
18+
| (error) error
19+
20+
𝑃 ∈ Program ::= (program 𝑣 𝑀) versioned program
21+
```
22+
23+
Plutus (Untyped Plutus Core) is untyped in the sense that variables don't have type tags.
24+
Constants, however, do carry type tags.
25+
A constant must be of a built-in type.
26+
Built-in types and functions are listed in [Built-in Types and Functions](./builtin.md).
27+
28+
## Version Numbers
29+
30+
The 𝑣 in a program is the _Plutus Core language version_, in the form of `x.y.z`.
31+
This is distinct from the Plutus ledger language version.
32+
For a detailed explanation, see [Different Notions of Version](https://plutus.cardano.intersectmbo.org/docs/essential-concepts/versions).
33+
34+
## Iterated Applications
35+
36+
An application of a term 𝑀 to a term 𝑁 is represented by `[𝑀 𝑁]`.
37+
We may occasionally write `[𝑀 𝑁₁ … 𝑁ₖ]` or `[𝑀 𝑁]` as an abbreviation for an iterated application `[ … [[𝑀 𝑁₁] 𝑁₂] … 𝑁ₖ]`.
38+
39+
## Constructor Tags
40+
41+
Constructor tags can in principle be any natural number.
42+
In practice, since they cannot be dynamically constructed, we can limit them to a fixed size without having to worry about overflow.
43+
So we limit them to 64 bits, although this is currently only enforced in the binary format.
44+
The Haskell definition uses `Word64` for the tag.
45+
46+
## de Bruijn Indices
47+
48+
Variable `𝑥` in the above listing can be either textual strings or de Bruijn indices.
49+
De Bruijn indices are used in serialized scripts.
50+
It therefore makes the most sense for a CEK machine implementation to use de Bruijn indices.
51+
52+
When using de Bruijn indices, the binder `𝑥` in `(lam 𝑥 𝑀)` is irrelevant, and any number can be used.
53+
54+
## The `data` Type
55+
56+
We provide a built-in type, `data`, which permits the encoding of simple data structures
57+
for use as arguments to Plutus Core scripts.
58+
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

Comments
 (0)