Hi all, newbie question, but I am struggling to find documentation for the do keyword, although I have seen a few examples of it, e.g this from the nimsvg library readme:
settings.buildAnimation(numFrames) do (i: int) -> Nodes:
let w = 200
let h = 200
buildSvg:
svg(width=w, height=h):
let r = 0.4 * w.float * i.float / numFrames.float + 10
circle(cx=w/2, cy=h/2, r=r, stroke="#445", `stroke-width`=4, fill="#EEF")
It seems to have special syntax in that it introduces something similar to the -> macro from the sugar module, and I have also seen it without the -> and just an expression (or a block expression):
echo do:
"xyzzy"
but how is this different from just:
echo:
"xyzzy"
using dumpTree these statements both seem to parse into the same thing.
I am sure this is all detailed in the friendly manual, but I struggled to find it! Apologies in advance for needing someone to point out the obvious!
Many thanks, -Paul
it is found in the experimental manual albeit it being used often
tldr do w/o parens is just a code block, do with parens is an anon. procedure
let a = do: # or block:
0
let b = do () -> int: # or proc (): int =
0
https://nim-lang.org/docs/manual_experimental.html#do-notation