feat: +13 tests (184/233, 79%) — case, hex/radix, protocol/record stubs, doseq destructuring
This commit is contained in:
+13
-9
@@ -394,19 +394,23 @@ proc initMacros*() =
|
||||
let name = bindings.items[0]
|
||||
let coll = bindings.items[1]
|
||||
let gs = cljSymbol(gensymName("ds_"))
|
||||
cljList(@[cljSymbol("let"), cljVector(@[gs, coll]),
|
||||
cljList(@[cljSymbol("loop"), cljVector(@[name, cljList(@[cljSymbol("first"), gs]),
|
||||
gs, cljList(@[cljSymbol("rest"), gs])]),
|
||||
cljList(@[cljSymbol("when"), name] & body),
|
||||
cljList(@[cljSymbol("recur"), cljList(@[cljSymbol("first"), gs]),
|
||||
cljList(@[cljSymbol("rest"), gs])])])])
|
||||
if name.kind == ckVector:
|
||||
let destructured = cljList(@[cljSymbol("let"), name, cljList(@[cljSymbol("first"), gs])])
|
||||
let loopBody = cljList(@[cljSymbol("when"), gs] & @[destructured] & body)
|
||||
let recurBody = cljList(@[cljSymbol("recur"), cljList(@[cljSymbol("rest"), gs])])
|
||||
let loopForm = cljList(@[cljSymbol("loop"), cljVector(@[gs, cljList(@[cljSymbol("seq"), gs])]), loopBody, recurBody])
|
||||
result = cljList(@[cljSymbol("let"), cljVector(@[gs, coll]), loopForm])
|
||||
else:
|
||||
let loopBody = cljList(@[cljSymbol("when"), name] & body)
|
||||
let recurBody = cljList(@[cljSymbol("recur"), cljList(@[cljSymbol("first"), gs]), cljList(@[cljSymbol("rest"), gs])])
|
||||
let loopForm = cljList(@[cljSymbol("loop"), cljVector(@[name, cljList(@[cljSymbol("first"), gs]), gs, cljList(@[cljSymbol("rest"), gs])]), loopBody, recurBody])
|
||||
result = cljList(@[cljSymbol("let"), cljVector(@[gs, coll]), loopForm])
|
||||
else:
|
||||
# Nested doseq
|
||||
let name = bindings.items[0]
|
||||
let coll = bindings.items[1]
|
||||
let restBindings = cljVector(bindings.items[2..^1])
|
||||
cljList(@[cljSymbol("doseq"), cljVector(@[name, coll]),
|
||||
cljList(@[cljSymbol("doseq"), restBindings] & body)])
|
||||
let innerDoseq = cljList(@[cljSymbol("doseq"), restBindings] & body)
|
||||
result = cljList(@[cljSymbol("doseq"), cljVector(@[name, coll]), innerDoseq])
|
||||
)
|
||||
|
||||
# dotimes
|
||||
|
||||
Reference in New Issue
Block a user