Skip to content
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

Idea: #define usage for functions #209

Open
Jofairden opened this issue Jan 11, 2023 · 2 comments
Open

Idea: #define usage for functions #209

Jofairden opened this issue Jan 11, 2023 · 2 comments

Comments

@Jofairden
Copy link

Currently #define annotations are quite limited, being only applicable at the contract level.
It would be nice to be able to use a #define, rather than supplying a function, simply replacing the code inside other annotations.

Example:

        #define voterId uint256 = voterList[_wallet]; // _wallet is a function parameter
        #define voter Voter = listOfVoters[voterId];

        #if_succeeds "registered the update"
            voter.isActive == _isActive;

Would be translated into

        #if_succeeds "registered the update"
            listOfVoters[voterList[_wallet]].isActive == _isActive;

This would give #define a second purpose for functions and help clean up annotations.

@cd1m0
Copy link
Collaborator

cd1m0 commented Feb 9, 2023

Thank you for the suggestion. This is a neat idea. We currently have a #let var := some expression; annotation that can be used inside of a function like a normal local variable. Would you be ok if instead of the #define keyword, we re-used the #let keyword at the function level as well? Honestly I am not sure which is the better option. Just wondering.

@Jofairden
Copy link
Author

@cd1m0 I am not up to speed on the interface design of this library, but my thought is that a 'definition' (define) is more clear because it indicates that the user would define X to be Y. In the case of let, it might initially appear to be or behave as a variable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants