Skip to content

Commit 10fd52e

Browse files
document template command
i apparently, unknowingly, implemented Scheme quasiquoting
1 parent b28b2f1 commit 10fd52e

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

README.md

+16-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,22 @@ Conceptually, there are 4 major things in JSON: strings, numbers, objects (Pytho
116116
: Creates anonymous and named functions. The list of varnames is the parameters, and additionally the entire arguments list is available as `$args`. The named form is equivalent to setting the value returned by the lambda form (`$result`) to the named variable. The functions are closures, with Python-style local->global->builtin scoping rules.
117117

118118
`{"template": ...}`
119-
: TODO: document this one
119+
: This one was designed to act a lot like Scheme quasiquotes. In fact, they are basically identical:
120+
121+
```python
122+
>>> json_runner.Engine().eval([
123+
... "set bar 33",
124+
... {"template": {"numbers": [1, 2, 1, {"template": [{"insert": "foo"}, {"insert": {"insert": "set bar"}}]}]}}
125+
... ])
126+
{'numbers': [1, 2, 1, {'template': [{'insert': 'foo'}, {'insert': 33}]}]}
127+
```
128+
```scheme
129+
(define bar 33)
130+
(display `(numbers 1 2 1 `(,foo ,,bar)))
131+
;; prints: (numbers 1 2 1 (quasiquote ((unquote foo) (unquote 33))))
132+
```
133+
134+
The objects with the sole "template" key act as `quasiquote`, and ones with the sole key of "insert" function as `unquote`.
120135

121136
### Operators
122137

0 commit comments

Comments
 (0)