feat(builtin): len, #441
Fix https://github.com/amber-lang/amber/issues/441
I am not sure why it is reporting "Variable 'len' does not exist", someone can help me?
Now says "Identifier 'len' is a reserved keyword".
len [1, 2, 3, 4]
echo len [1, 2, 3, 4]
The first line of code works but the second one no, so @Ph0enixKM maybe there is something to improve in the compiler on parsing a builtin that include another one?
This happens because you have added it to statements modules which means that it works only as a statement like function declaration or loops. What you probably wanted is to add it to an expression modules. Expressions are syntax elements that represent certain value and type. For instance loop is not an expression because it does not represent any type or value. On the other hand a len is an expression because it's a value of length of the value that we put in and it's of type Num. Each expression must implement Typed trait. You can see it being used in modules under modules/expression
So we discussed and seems that the issue is the fact that Amber load anyway the stdlib so a len already exists also if it is not loaded in the Amber script.
To fix the issue we should remove it from the stdlib and alert in the next release about the breaking change.
@Ph0enixKM says that needs some rewrite Amber in the expression part instead.
Also this is the first builtin that return a value compared to the others we already have.
To fix the issue we should remove it from the stdlib and alert in the next release about the breaking change.
so push a commit
@Ph0enixKM says that needs some rewrite Amber in the expression part instead.
he should say that himself, or even better push a commit resolving the issue
he should say that himself, or even better push a commit resolving the issue
Yeah, I am waiting him to know what to do
Sorry for long overdue. I'll add this issue to my priority to-do list
Closed for https://github.com/amber-lang/amber/pull/545/