How do we have for i in loop inside quote do macro due to this keep on error:
macro foo(c :char; s :string) =
result = quote do:
var
i :char
echo `s`
for `i` in `s`:
if `i`==`c` : echo `c`
foo('l', "hello")
Error: undeclared identifier: 'i'
Guide to a correct way
You mixed up the variable i in the quote section. You only want to interpolate (`i`) for variables created outside the quote section:
macro foo(c: char, s: string) =
result = quote do:
echo `s`
for i in `s`:
if i == `c`: echo `c`
Though it'd be easier to use a template for this example:
template foo(c: char, s: string) =
echo `s`
for i in `s`:
if i == `c`: echo `c`