import fusion/matching
{.experimental: "caseStmtMacros".}
case [(1, 3), (3, 4)]:
of [(1, @a), _]:
echo a
else:
echo "Match failed"
Results in:
benjaminlee@Benjamins-Mac-mini ~ [1]> nim c tmatching.nim
Hint: used config file '/opt/homebrew/Cellar/nim/1.6.0/nim/config/nim.cfg' [Conf]
Hint: used config file '/opt/homebrew/Cellar/nim/1.6.0/nim/config/config.nims' [Conf]
.................................................................................
stack trace: (most recent call last)
/Users/benjaminlee/.nimble/pkgs/fusion-1.0/fusion/matching.nim(2346, 49) case
/Users/benjaminlee/.nimble/pkgs/fusion-1.0/fusion/matching.nim(2307, 12) matchImpl
/Users/benjaminlee/.nimble/pkgs/fusion-1.0/fusion/matching.nim(1189, 44) parseMatchExpr
/Users/benjaminlee/.nimble/pkgs/fusion-1.0/fusion/matching.nim(1006, 31) parseSeqMatch
/Users/benjaminlee/.nimble/pkgs/fusion-1.0/fusion/matching.nim(1360, 12) parseMatchExpr
/Users/benjaminlee/tmatching.nim(4, 1) template/generic instantiation of `case` from here
/Users/benjaminlee/tmatching.nim(5, 7) Error: Malformed DSL - found (1, @a) of kind nnkTupleConstr.
Nim info:
benjaminlee@Benjamins-Mac-mini ~ [1]> nim -V
Nim Compiler Version 1.6.0 [MacOSX: arm64]
Compiled at 2021-10-19
Copyright (c) 2006-2021 by Andreas Rumpf
active boot switches: -d:release -d:nimUseLinenoise
Related https://www.reddit.com/r/nim/comments/qfi1d0 (provides a solution - install using requires "fusion#head") and #86 (provides a fix for the tuple error, but it is not in current latest tagged version).
Results in:
Nim info: