-
Notifications
You must be signed in to change notification settings - Fork 94
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feature: add constant declarations #423
Conversation
this is implemented as `is_const` field in `VariableDecl`, so constants are technically variables that cannot be reassigned.
When we start to support |
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 order to resolve this discussion I've created the following poll: #493 |
@Ph0enixKM im confused, though. afaik we don't support |
I think that we eventually will support |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks pretty good @b1ek. It would be nice to improve that error message. I'll create issues to add constants to our editor plugins
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approved subject to suggestions from both myself and @Ph0enixKM.
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? |
|
||
main { | ||
const x = 42 | ||
unsafe $ x=123 $ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
x
is a variable in the amber side, but $ x $
is a variable in the bash. Should this be $ {nameof x}=123 $
to some forward compatibility?
i've added support for the
const X = Y
expression itself. it will resolve todeclare -r X=Y
, for both local and global variables, sincedeclare -r
is the same for locals as welli also set
args
inmain(args)
to be constant. function parameters are never constant.i don't know which is the minimal bash version for
declare -r