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

[Proposal] const keyword in function arguments #605

Closed
Protryon opened this issue Feb 3, 2021 · 4 comments
Closed

[Proposal] const keyword in function arguments #605

Protryon opened this issue Feb 3, 2021 · 4 comments
Assignees
Labels
documentation Improvements or additions to documentation feature A new feature.

Comments

@Protryon
Copy link
Contributor

Protryon commented Feb 3, 2021

💥 Proposal

We want to add a const keyword prefixed to function declaration arguments. This would enable function calls to trivially do const checking in a user-friendly way, and opens the path to generics.

Syntax

function_definition_head := "function" ident "(" (argument ",")* argument? ")"
argument := "const"? ident ":" type_ref

Semantics

Functions would treat the specific argument as a const value, and function call expressions would enforce constness of the argument.

@collinc97
Copy link
Collaborator

This looks great @Protryon!

To confirm the visualization, an example of the new Leo syntax would be:

function foo(const x: u32) {
    ...
}

@collinc97 collinc97 added ast documentation Improvements or additions to documentation feature A new feature. labels Feb 3, 2021
@collinc97
Copy link
Collaborator

This feature will also encompass the features of generics.

It will close #479

@acoglio
Copy link
Collaborator

acoglio commented Feb 4, 2021

This looks good to me.

@collinc97
Copy link
Collaborator

Implemented by #617

@collinc97 collinc97 added this to the Leo Developer Preview II milestone Feb 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation feature A new feature.
Projects
None yet
Development

No branches or pull requests

3 participants