proc parseStringSeq*(text: string, charset: CHARSET): CHARSEQ =
var osq: CHARSEQ = @[]
for i in countup(0, text.len - 1):
if text[i].isAlphaAscii():
osq.add(charset[int(text[i]) - 63]) #alphabets(capital)
elif text[i].isDigit():
osq.add(charset[int(text[i]) - 2]) #digits
else:
discard
return osq
This is a shoddy proc for taking a string and converting into other type char by char. And when I try to run it it says cannot evaluate at compile time: text. If i replace string with static[string], it says cannot evaluate at compile time: i.
I have a hard time understanding why this error happens.
Here's what I think you are trying to do. Notice I replaced osq with the implicit variable result.
When you evaluate an expression at the compile-time, all the operands have to be compile-time expressions (mostly literals, constants and expressions consisted of them) in that context.
When you write
"123"
Then "123" can be used as a compile-time expression.
When you write
const text = "123"
Then text can be used as a compile-time expression.
However, when you write
var text = "123"
text cannot be used as a compile-time expression, because it is considered a runtime variable (var). The same applies to let-variables.
When you write
static:
var text = "123" & "4"
text
This whole static-expression is a compile-time expression once resolved. But within the context of this inner block, text is still not considered static.
Complex. I know. Just think of it as stack-like.
Also it seems that the lengths of arrays are always considered static, while that of string/seq are not (and thus as static as the associated variable).