You know how Nim forces you to choose between its Python-style indentation andβ¦ that's it, that's the only option? Yeah, I got a bit restless π
So I may have done something slightly unhinged and taught Nim to accept both Python-style indentation and C-style curly braces. At the same time. In the same codebase. Because I missed my curlies and I'm not sorry π
nimproc add(a, b: int): int {
return a + b
}
# also still works:
proc add(a, b: int): int =
return a + b
Is it official? No.
Is it upstream? Absolutely not.
Is it for everyone? Please no π
Is it cursed? Possibly.
Does it work for me? Beautifully.
This is a personal hack for personal sanity, layered on community-owned Nim code. The Nim community is wonderful and I have nothing but respect for the language β I just have a complicated relationship with significant whitespace that goes back further than I'd like to admit π΄
Don't use this. Don't ask about this. Pretend you didn't read this.
...but if you're also a curly brace person living reluctantly in an indentation world, you know where to find me π€
How you will work with template/macroses then? For example, its boring to open/close/parse config files to me and i wrote something like this:
template withFile(fname: string, body: untyped): untyped =
block:
var lines {.inject.}: seq[string]
if fileExists(fname):
lines = readFile(fname).strip.splitLines
var origLinesCount = lines.len
if origLinesCount == 1 and lines[0].len == 0:
lines.setLen(0)
origLinesCount = 0
body
if lines.len != origLinesCount:
lines.add("")
writeFile(fname, lines.join("\n")) And use it then:
withFile ".gitignore":
lines.addUnique("build/")
lines.addUnique("tmp/")
lines.addUnique("data/*.bundle")
lines.addUnique("/config.nims")
lines.addUnique("/nimble.paths")
lines.addUnique("znak_platforms/")
lines.addUnique("/znak")
lines.addUnique("/znak.exe")
How you will be able to create similar thing with curly braces?