cashscript icon indicating copy to clipboard operation
cashscript copied to clipboard

Add support for "constant" keyword in tuples

Open cgcardona opened this issue 6 years ago • 7 comments

Currently defining a variable is

<Typ> name = expression;

This can be non-obvious to developers who are used to keywords before declaring variables. Also in CashScript variables can be reassigned.

For that reason this ticket is to add support for let and const. Their functionality would be inline with other mainstream languages.

let would be for variables which can be reassigned.

const would be for variables which have a constant value.

Both would be block scoped.

cgcardona avatar Aug 23 '19 18:08 cgcardona

Right now I don't really want to add type inference to the language, as I think the time could be better spent on other things. So I don't want to add a let keyword, but I'm open to reconsidering that in the future. I think adding a keyword for constant values could be useful though.

rkalis avatar Sep 20 '19 08:09 rkalis

Solidity uses the constant keyword in Solidity to indicate that a variable can't be changed (Source). This can be added to CashScript as well. Shouldn't change anything about the compiler output, but instead it should throw an error in semantic analysis when a constant variable is reassigned.

rkalis avatar Dec 13 '19 16:12 rkalis

I just realised that we probably should add this modifier for tuple assignment as well. What do you think @nathanielCherian?

rkalis avatar Jun 13 '22 10:06 rkalis

For sure. I think we should wait until the modifier refactoring in #125 is merged, but it shouldn't be a tricky fix.

nathanielCherian avatar Jun 14 '22 06:06 nathanielCherian