Skip to content

Commit 397d5cf

Browse files
committed
doc: change "fn" syntax
1 parent b832a41 commit 397d5cf

File tree

1 file changed

+27
-15
lines changed

1 file changed

+27
-15
lines changed

_docs/json-dsl.md

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,14 @@ Parameter types are
122122
* expression (only macro can treat this)
123123

124124
But all values must be able to be serialized to JSON. Because AST of whole
125-
process is serialized and saved as a "transaction log file". The process can be
126-
rolled back, when an error occur while the process, or user send SIGINT signal,
127-
or `volt history undo` command is executed. The transaction log file does not
128-
have ID but the saved directory `{id}` does:
125+
process is serialized and saved as a "transaction log file".
126+
127+
NOTE: All macros has `$` prefixed name for readability.
128+
Macros are not saved in transaction log (expanded before saving).
129+
130+
The process can be rolled back, when an error occur while the process, or user
131+
send SIGINT signal, or `volt history undo` command is executed. The transaction
132+
log file does not have ID but the saved directory `{id}` does:
129133

130134
```
131135
$VOLTPATH/trx/{id}/log.json
@@ -367,10 +371,7 @@ As the above signature shows, operators must take care the following points:
367371

368372
TODO: Move to Godoc.
369373

370-
### Basic macros
371-
372-
All macros has `$` prefixed name for readability.
373-
Macros are not saved in transaction log (expanded before saving).
374+
### Basic operators
374375

375376
* `["$array", v1 Value, ...] Array`
376377
* Returns inverse expression of given expression.
@@ -390,20 +391,31 @@ Macros are not saved in transaction log (expanded before saving).
390391
instead of its expression.
391392
* See `repos/git/fetch`, `repos/git/update` for concrete example.
392393

393-
### Basic operators
394+
* `["fn", [args ...[]string], body Expr[R]]R`
395+
* Returns a lambda with `arity` number arguments and `body` expression.
396+
* e.g.
397+
* `["fn", [], ["lockjson/write"]]`
398+
* see below
399+
400+
```json
401+
[["fn", [["path", "string"], ["profiles", ["array", "string"]]],
402+
["lockjson/add", ["repos/get", ["arg", "path"]], ["arg", "profiles"]]],
403+
"github.com/tyru/caw.vim",
404+
["$array", "default"]]
405+
```
394406

395-
* `["$label", linenum: number, tmpl string, expr Expr[* => R]] R`
407+
* `["$label", linenum number, tmpl string, expr Expr[R]] R`
396408
* `["$label", linenum, tmpl, expr]` expands to
397409
`["label", linenum, tmpl, ["fn", [] expr]]`
398410

399-
* `["label", linenum: number, tmpl string, thunk Func[* => R]] R`
411+
* `["label", linenum number, tmpl string, thunk Func[R]] R`
400412
* Render `tmpl` by text/template to `linenum` line (1-origin).
401413
Returns the evaluated value of `thunk`.
402414
* e.g.
403415
* `["$invert", ["label", linenum, "msg", thunk]]` = `["label", ["$invert", linenum], "revert: \"msg\"", ["$invert", thunk]]`
404416
* See `Label examples` section for more details
405417

406-
* `["$do", expr1 Expr[* => R1], ..., expr_last Expr[* => R2]] R2`
418+
* `["$do", expr1 Expr[R1], ..., expr_last Expr[R2]] R2`
407419
* `["$do", expr1, expr2]` expands to
408420
`["do", ["fn", [], expr1], ["fn", [], expr2]]`
409421

@@ -414,11 +426,11 @@ Macros are not saved in transaction log (expanded before saving).
414426
* `["$invert", ["do", thunk1, thunk2]]` = `["do", ["$invert", thunk1], ["$invert", thunk2]]`
415427
* Note that the arguments are reversed.
416428

417-
* `["$parallel", expr1 Expr[* => R1], ..., expr_last Expr[* => R2]] R2`
429+
* `["$parallel", expr1 Expr[R1], ..., expr_last Expr[R2]] R2`
418430
* `["$parallel", expr1, expr2]` expands to
419431
`["parallel", ["fn", [], expr1], ["fn", [], expr2]]`
420432

421-
* `["parallel", thunk1 Func[* => R1], ..., thunk_last Func[* => R2]] R2`
433+
* `["parallel", thunk1 Func[R1], ..., thunk_last Func[R2]] R2`
422434
* Executes multiple lambdas in parallel.
423435
* Returns the evaluated value of the last lambda.
424436
* e.g.
@@ -549,7 +561,7 @@ Macros are not saved in transaction log (expanded before saving).
549561
550562
### Vim directory operators
551563
552-
* `["vimdir/with-install", paths "all" | []ReposPath, expr Expr[* => R]] R`
564+
* `["vimdir/with-install", paths "all" | []ReposPath, expr Expr[R]] R`
553565
* `paths` is the list of repositories to build after `expr` is executed.
554566
* `"all"` means all repositories of current profile.
555567
* e.g.

0 commit comments

Comments
 (0)