feature: add constant declarations
i've added support for the const X = Y expression itself. it will resolve to declare -r X=Y, for both local and global variables, since declare -r is the same for locals as well
i also set args in main(args) to be constant. function parameters are never constant.
i don't know which is the minimal bash version for declare -r
i just checked, declare -r works for bash 4.0:
The reason why I never introduces const is because sh does not support it. So for instance on ash it fails:
When we start to support sh - we should compile it to the regular variable instead (but still never let reassign the variable in the script)
When we start to support
sh- we should compile it to the regular variable instead (but still never let reassign the variable in the script)
i'd rather have it defined as a function that always returns the same literal
The idea of a function that returns always the same value I think that is the best and assure that can't change.
I'd say go with the @Ph0enixKM idea, since functions have an additional performance penalty. It doesn't matter that a constant is technically a regular variable, so long as it is translated from an Amber constant, thus is proven to be impossible to modify.
I think that we can move on with a function that return always the same value so we can assure the best compatibility. In the future we can think for something more sophisticated.
In order to resolve this discussion I've created the following poll: https://github.com/amber-lang/amber/discussions/493
@Ph0enixKM im confused, though. afaik we don't support sh right now. why is it an issue?
I think that we eventually will support sh. I just wanted to settle down how are we going to solve this problem holistically (including sh even if we do not implement it's support just yet)
I think that we'll have to write a guideline on writing error messages. But that's not a hurry. Let's merge the feature
@b1ek can you fix the conflicts so we can merge it?