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

Make declarations order-independent in impl blocks #78

Open
liquidev opened this issue Jun 8, 2022 · 0 comments
Open

Make declarations order-independent in impl blocks #78

liquidev opened this issue Jun 8, 2022 · 0 comments
Labels
enhancement New feature or request

Comments

@liquidev
Copy link
Member

liquidev commented Jun 8, 2022

Currently constructors have to be declared first, for instance functions to be able to see fields:

impl struct Vector
  func x() @x end  # error

  func new(x, y) constructor
    @x = x
    @y = y
  end
end

I believe this restriction should be relaxed, such that constructors are processed before anything else, so that all other functions can see fields declared in constructors.


Update 2022-09-10

Additionally, I believe it would make sense to make field declarations part of the struct definition, such as struct Vector { @x, @y }. This would allow us to define mutability of fields in one central state rather than relying on order of constructors. The exact syntax is still to be determined.


Update 2022-01-29

I've determined that it would make the most sense in terms of implementation simplicity if we add field declarations right into impl blocks, using the new let syntax that is to be implemented (#129).

struct Vector impl
    let @x
    let @y

    func new(x, y) constructor = do
        @x = x
        @y = y
    end
end
@liquidev liquidev added the enhancement New feature or request label Jun 8, 2022
@liquidev liquidev moved this to 📦 Backlog in Mica 1.0 Sep 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: 📦 Backlog
Development

No branches or pull requests

1 participant