-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
104 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,6 +29,24 @@ This is, essentially, the identity function. | |
It produces a stream from any number of arguments, concatenating the streams produced by the nested expressions. | ||
Used to aggregate multiple values or sub-streams to pass to a single argument, or to produce multiple results. | ||
|
||
#### `default` | ||
|
||
```ion | ||
(macro default (expr* default_expr*) | ||
// If `expr` is empty... | ||
(.if_none (%expr) | ||
// then expand `default_expr` instead. | ||
(%default_expr) | ||
// If it wasn't empty, then expand `expr`. | ||
(%expr) | ||
) | ||
) | ||
``` | ||
|
||
`default` tests `expr` to determine whether it expands to the empty stream. | ||
If it does not, `default` will produce the expansion of `expr`. | ||
If it does, `default` will produce the expansion of `default_expr` instead. | ||
|
||
#### `flatten` | ||
|
||
```ion | ||
|
@@ -297,19 +315,22 @@ Examples: | |
(:sum (:)) => 0 | ||
``` | ||
|
||
#### `comment` | ||
#### `meta` | ||
|
||
```ion | ||
(macro comment (anything*) (.none)) | ||
(macro meta (anything*) (.none)) | ||
``` | ||
|
||
The `comment` macro accepts any values and emits nothing. | ||
It can be used for comments that must be syntactically valid Ion. | ||
The `meta` macro accepts any values and emits nothing. | ||
It allows writers to encode data that will be not be surfaced to most readers. | ||
Readers can be configured to intercept calls to `meta`, allowing them to read the otherwise invisible data. | ||
|
||
When transcribing from one format to another, writers should preserve invocations of `meta` when possible. | ||
|
||
Example: | ||
```ion | ||
(:values | ||
(:comment equivalent to {foo:1,foo:2}) | ||
(:meta {author: "Mike Smith", email: "[email protected]"}) | ||
{foo:2,foo:1} | ||
) | ||
=> | ||
|
@@ -408,7 +429,7 @@ Appends the content of the given module to the encoding context. | |
```ion | ||
(macro use (catalog_key version?) | ||
$ion_encoding::( | ||
(import the_module catalog_key (.if_none (%version) 1 (%version))) | ||
(import the_module catalog_key (.default (%version) 1)) | ||
(symbol_table $ion_encoding the_module) | ||
(macro_table $ion_encoding the_module) | ||
)) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters