I ask because i find myself (and others) placing comments around blocks.
Can you please clarify? I don't understand what placing comments has to do with blocks (not) allowing strings as arguments.
E.g. I can write a comment currently too:
block outer: # here's a comment
for i in 1 .. 5:
for j in 10 .. 15:
if i > 1:
break outer # this can be commented too
echo i*j
not sure if this is related, but I sometimes use the following template when I need a way to fold regions of code in the IDE (VS code for me) in a long nim file (of course I could split and do imports, but sometimes it is quicker this way):
template region(name, body: untyped) {.dirty.} = body
and I use it like this
region(common):
... # code for common functionalities of the api
region(featureA):
... # code for code related to featureA
... # other regions
^ in the above usecase I don't pass an identifier to the block
an example (modified from your example)
block : # this block iterates over a matrix...
for i in 1 .. 5:
for j in 10 .. 15:
if i > 1:
# no need to break in this example
# just wanted to use indentation to demarcate code
echo i*j
i'm asking if it would be a good idea to support doing
block "this block iterates over a matrix..." :
for i in 1 .. 5:
for j in 10 .. 15:
if i > 1:
# no need to break in this example
# just wanted to use indentation to demarcate code
echo i*j
^ it's kind of similar to the unittest dsl (really love writing tests in nim!)
i fully understand that the usecase is kind of trivial & not necessarily a good idea
^ just wanted to see if anyone else desired the feature
Thanks again
this is actually exactly related!
I think I'll copy your pattern! region is a great name!
{.dirty.}
FWIW, there's no need for that.
Yes, I took the name region from .NET (C#, VB).
Also, thanks for pointing out dirty pragma is not needed.
5 months later, I just realized that stropping allows me to achieve this natively:
block `this loop iterates over a matrix...` :
for i in 1 .. 5:
...