Empty records
This commit is contained in:
parent
1784024952
commit
63c124307b
|
@ -3,7 +3,7 @@ title: "P-expressions"
|
|||
---
|
||||
|
||||
Tony Garnock-Jones <tonyg@leastfixedpoint.com>
|
||||
October 2023. Version 0.1.1.
|
||||
October 2023. Version 0.1.2.
|
||||
|
||||
This document defines a grammar called *Preserves Expressions*
|
||||
(*P-expressions*, *pexprs*) that includes [ordinary Preserves text
|
||||
|
@ -53,6 +53,10 @@ with `Block` everywhere it is mentioned.
|
|||
|
||||
Block = "{" *Value ws "}"
|
||||
|
||||
Syntax for `Record` is loosened to allow empty angle brackets.
|
||||
|
||||
Record = "<" *Value ws ">"
|
||||
|
||||
New syntax for explicit uninterpreted grouping of sequences of values is
|
||||
introduced, and added to class `Value`.
|
||||
|
||||
|
@ -86,7 +90,7 @@ While the ordinary text syntax forbids comments in these positions,
|
|||
P-expressions allow them:
|
||||
|
||||
Document =/ *Value Trailer ws
|
||||
Record =/ "<" Value *Value Trailer ws ">"
|
||||
Record =/ "<" *Value Trailer ws ">"
|
||||
Sequence =/ "[" *Value Trailer ws "]"
|
||||
Set =/ "#{" *Value Trailer ws "}"
|
||||
Block =/ "{" *Value Trailer ws "}"
|
||||
|
@ -101,8 +105,8 @@ We write ⌜*p*⌝ for the encoding into Preserves of P-expression *p*.
|
|||
| ⌜·⌝ : **P-expression** | ⟶ | **Preserves** |
|
||||
|
||||
Aside from the special classes `Group`, `Block`, `Comma`, `Semicolon`,
|
||||
`Colons`, or `Trailer`, P-expressions are encoded directly as Preserves
|
||||
data.
|
||||
`Colons`, `Trailer`, or empty `Record`, P-expressions are encoded
|
||||
directly as Preserves data.
|
||||
|
||||
{:.pseudocode.equations}
|
||||
| ⌜`[`*p* ...`]`⌝ | = | `[`⌜*p*⌝ ...`]` |
|
||||
|
@ -112,7 +116,7 @@ data.
|
|||
| ⌜`@`*p* *q*⌝ | = | `@`⌜*p*⌝ ⌜*q*⌝ |
|
||||
| ⌜*p*⌝ | = | *p* when *p* ∈ **Atom** |
|
||||
|
||||
All members of the special classes are encoded as Preserves
|
||||
Everything else is encoded as Preserves
|
||||
dictionaries[^encoding-rationale].
|
||||
|
||||
[^encoding-rationale]: In principle, it would be nice to use *records*
|
||||
|
@ -120,6 +124,7 @@ dictionaries[^encoding-rationale].
|
|||
usages of records!
|
||||
|
||||
{:.pseudocode.equations}
|
||||
| ⌜`<>`⌝ | = | `{r:[]}` |
|
||||
| ⌜`(`*p* ...`)`⌝ | = | `{g:[`⌜*p*⌝ ...`]}` |
|
||||
| ⌜`{`*p* ...`}`⌝ | = | `{b:[`⌜*p*⌝ ...`]}` |
|
||||
| ⌜`,`⌝ | = | `{s:|,|}` |
|
||||
|
@ -153,8 +158,9 @@ classes mentioned above.
|
|||
1. Every `Group` or `Semicolon` that appears is an error.
|
||||
2. Every `Colons` with two or more colons in it is an error.
|
||||
3. Every `Comma` that appears is discarded.
|
||||
3. Every `Trailer` that appears is an error.[^discard-trailers-instead-of-error]
|
||||
4. Every `Block` must contain triplets of `Value`, `Colons` (with a
|
||||
4. Every `Trailer` that appears is an error.[^discard-trailers-instead-of-error]
|
||||
5. Every `Record` with no values in it is an error.
|
||||
6. Every `Block` must contain triplets of `Value`, `Colons` (with a
|
||||
single colon), `Value`. Any `Block` not following this pattern is an
|
||||
error. Each `Block` following the pattern is translated to a
|
||||
`Dictionary` containing a key/value pair for each triplet.
|
||||
|
@ -176,6 +182,11 @@ text-syntax encodings.
|
|||
= <date 1821 {g:[lookup-month "February"]} 3>
|
||||
```
|
||||
|
||||
```preserves
|
||||
⌜<>⌝
|
||||
= {r:[]}
|
||||
```
|
||||
|
||||
```preserves
|
||||
⌜(begin (println! (+ 1 2)) (+ 3 4))⌝
|
||||
= {g:[begin {g:[println! {g:[+ 1 2]}]} {g:[+ 3 4]}]}
|
||||
|
|
Loading…
Reference in New Issue