Amber icon indicating copy to clipboard operation
Amber copied to clipboard

feat(builtin): len, #441

Open Mte90 opened this issue 1 year ago • 2 comments

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?

Mte90 avatar Oct 02 '24 10:10 Mte90

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?

Mte90 avatar Oct 02 '24 13:10 Mte90

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

Ph0enixKM avatar Oct 03 '24 10:10 Ph0enixKM

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.

Mte90 avatar Oct 16 '24 10:10 Mte90

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

b1ek avatar Oct 21 '24 06:10 b1ek

he should say that himself, or even better push a commit resolving the issue

Yeah, I am waiting him to know what to do

Mte90 avatar Oct 21 '24 08:10 Mte90

Sorry for long overdue. I'll add this issue to my priority to-do list

Ph0enixKM avatar Oct 21 '24 18:10 Ph0enixKM

Closed for https://github.com/amber-lang/amber/pull/545/

Mte90 avatar Oct 28 '24 11:10 Mte90