So, I had this code:
import std/os
import system/io
echo paramStr(1)
if declared(paramStr(1)) == true:
echo It exists
else:
echo It doesn't exists
And then while I was compiling this error ocurred:
Error: identifier expected, but got: paramStr(1)
I don't know what could be the cause of it, maybe it could be the type of paramStr?
Maybe you meant
if paramCount() >= 1:
I assume you want to output the first command-line argument passed to the binary. Your code has a lot of unnecessary stuff, first of all, you don't need to import system modules explicitly - system is always imported.
Then your usage of declared is wrong - first of all, it's supposed to be used in a compile-time context with when, and then it should only be used to check if a variable with a certain name is _declared. You want to check the amount of passed arguments, so you should use paramCount instead (as @xigoi mentioned).
Also echo is supposed to be used on strings or objects that have a stringification proc, so you should use quotes to output strings.
Here's how the fixed code can look like:
import std/os
if paramCount() >= 1:
echo "First argument - ", paramStr(1)
else:
echo "It doesn't exist"
Ok, I'll have that in mind the next time I have to make a question
Thank you very much to all people who participed in this thread