Expand `x => 'x; `,x => x; `(,@x y) => (append x y)
(x)
| 276 | _append, _cons, _let = map(Sym, "append cons let".split()) |
| 277 | |
| 278 | def expand_quasiquote(x): |
| 279 | """Expand `x => 'x; `,x => x; `(,@x y) => (append x y) """ |
| 280 | if not is_pair(x): |
| 281 | return [_quote, x] |
| 282 | require(x, x[0] is not _unquotesplicing, "can't splice here") |
| 283 | if x[0] is _unquote: |
| 284 | require(x, len(x)==2) |
| 285 | return x[1] |
| 286 | elif is_pair(x[0]) and x[0][0] is _unquotesplicing: |
| 287 | require(x[0], len(x[0])==2) |
| 288 | return [_append, x[0][1], expand_quasiquote(x[1:])] |
| 289 | else: |
| 290 | return [_cons, expand_quasiquote(x[0]), expand_quasiquote(x[1:])] |
| 291 | |
| 292 | def let(*args): |
| 293 | args = list(args) |