I often find myself building small components while designing a larger system. The issue is sometimes it can be hard to keep track of what still needs work, even with todo comments and would rather have compiler warnings.
I would actually like it if there was a pragma that behaved similar to {.deprecated.} but that implies that this feature has been superseded by a new feature and you should use that instead. While I want to imply that this feature is not yet fully ready, but will be in the future, so keep using it, but expect bugs.
that would have been my answer too :), and this would be an example usage:
unfinished.nim:
proc question(answer: int): string =
{.warning: "work in progress".}
result = "What do you get if you multiply six by nine?"
echo question(42)
nim c -r unfinished :
unfinished.nim(2, 12) Warning: work in progress [User]
What do you get if you multiply six by nine?
because @pietroppeter and i seem to have found ourselves in a friendly question-answering rivalry: i see your excellent answer and raise you a user-defined {.wip.} pragma:
import macros
macro wip(p: untyped): untyped =
expectkind(p, nnkProcDef)
let name = p[0].strVal
expectkind(p[6], nnkStmtList)
let warn = nnkPragma.newTree(newColonExpr(ident("warning"), newStrLitNode(
name&" is a work in progress")))
var body = p[6][0 .. ^1]
body.insert(warn)
p[6] = newStmtList(body)
p
proc question(answer: int): string{.wip.} =
result = "what do you get if you multiply six by nine?"
proc last_message(): string{.wip.} = "We apologize for the inconvenience."
echo question(42)
echo last_message()
nim c -r --hints:off unfinished:
unfinished.nim(13,32) template/generic expansion of `wip` from here
unfinished.nim(14,3) Warning: question is a work in progress [User]
unfinished.nim(15,38) Warning: last_message is a work in progress [User]
what do you get if you multiply six by nine?
We apologize for the inconvenience.
I am loving it (both the friendly rivalry and the answer)!
You definitely win this round (I fold! I was bluffing!). don't tell anyone, but I am not really good at macros... 😝
Previously, on StackOverflow...