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

Mutability design (mut) #112

Closed
bvssvni opened this issue May 5, 2016 · 0 comments
Closed

Mutability design (mut) #112

bvssvni opened this issue May 5, 2016 · 0 comments

Comments

@bvssvni
Copy link
Member

bvssvni commented May 5, 2016

Dyon uses mut to declare mutability. This appears in front of a function argument declaration or when calling a function that mutates the argument.

  • foo(mut a) mutates the argument a
  • foo(mut a) has function name foo(mut)
  • foo(mut a, b) has function name foo(mut,_)
  • foo(a, b) has function name foo

Local variables are mutable.

Mutability is not part of a type, but added to the function name inside parentheses, e.g.(mut,_). When adding an external function, the mutability information must be added as part of the function name.

Mutability propagates for arguments:

fn foo(mut a) { ... }

// `bar` requires `mut a` because it calls `foo(mut a)`.
fn bar(mut a) { foo(mut a) }

Multiple functions can use the same name if they have different mutability information. This reduces the need for "get", "set" and "mut" in function name:

fn title(window: 'return) -> { ... }

fn title(mut window, val) { ... }

t := title(window)
title(mut window, "hello world!")

This is designed for:

  • Explicitly declare when a function mutates a variable
  • Improve readability and maintenance
  • Allow a function name to be reused for different mutability patterns
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant