From 935535a76ebcd594f2c16518b25cd27bc2a6d97b Mon Sep 17 00:00:00 2001 From: Mark Spanbroek Date: Mon, 13 Feb 2023 12:05:57 +0100 Subject: [PATCH] Rearrange tuple binding code Introduce separate proc for creation of unpacking statement. Use `quote do` to make code as similar as possible to the `bindLet` and `bindVar` templates. --- questionable/binding.nim | 45 +++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 24 deletions(-) diff --git a/questionable/binding.nim b/questionable/binding.nim index e556207..bdd0ee1 100644 --- a/questionable/binding.nim +++ b/questionable/binding.nim @@ -30,38 +30,35 @@ template bindVar(name, expression): bool = placeholder(T) option.isSome -macro bindTuple(name, expression): bool = - let stmtList = newStmtList() - let opt = genSym(nskLet, "option") - let T = genSym(nskType, "T") +proc newUnpackTupleNode(names: NimNode, value: NimNode): NimNode = + # builds tuple unpacking statement, eg: let (a, b) = value + let vartuple = nnkVarTuple.newTree() + for i in 0..