ark-lang / ark

A compiled systems programming language written in Go using the LLVM framework
https://ark-lang.github.io/
MIT License
677 stars 47 forks source link

Attribute Block changes #451

Open felixangell opened 9 years ago

felixangell commented 9 years ago

We think that the current idea for attribute blocks:

[attrib] {
   ...
}

Is not a great solution for attribute blocks, because they should not introduce a scope, yet we feel by adding this rule to the compiler it's somewhat misleading and inconsistent with the syntax of the language.

Because of this, we think it's best to re-think attribute blocks. And instead of having literal attribute blocks, you have "attribute groups". In other words, you have a couple of functions where you're always using the attributes, a, b, c. So you group this under a general attribute, for instance x. Then instead of writing [a, b, c] func..., you can simplify it down to [x] func.... Since it's in essence an alias or a variable, it's also easy to add more attributes under the general attribute x, and also easy to remove them too.

The syntax for this feature is still in the works, but we have a few ideas. Before I go on to those, we wanted to add a way of differentiating various attributes that are defined by the developer; compiler; and are a group of attributes. So we've come up with the following syntax:

Now to define a group of attributes, we aren't too sure, but we have a few ideas:

alias [a, b, c] = [x]
@[x] = [a, b, c]
@[x] group [a, b, c]

And that's it! Feedback, suggestions, etc... are greatly appreciated.

@ark-lang/owners

SamTebbs33 commented 9 years ago

As long as the first syntax option (the one using the alias keyword) doesn't introduce some syntax ambiguity for the parser (as the keyword may also be used for type aliases), then I would say it is the better option.

Also, would it not fit with the language a little more if you were to put the alias name before the assignment operator? This would fit with the syntax used for variable assignments, rather than reversing it.

So for example: alias [x] = [a, b, c]

rather than: alias [a, b, c] = [x]

MovingtoMars commented 9 years ago

I think it should be like this: attr @[x] [a, b, c]

felixangell commented 9 years ago

@SamTebbs33 Yeah that looks like it makes sense. @MovingtoMars As for attr, I understand it's to avoid ambiguity, but it seems kind of random.

felixangell commented 9 years ago

@ark-lang/owners Conclusion to be drawn here!!! Or ideas if you disagree with all of the stuff above ^^^

kiljacken commented 9 years ago

:-1: On attributes groups. Realistically, I don't think most attributes would be used to the point where that would help.

:+1: for the revival attribute blocks, although i agree that the previous syntax should be changed..

felixangell commented 9 years ago

@kiljacken Do you mean attribute blocks? Or do you mean grouping attributes under a single attribute. What do you mean by the revival of attribute blocks?

kiljacken commented 9 years ago

@felixangell I was thinking of the scenario of writing bindings to a c library. It would be nice to do something like:

[c] {
    func some_library_function()
    func some_other_library_function()
    func some_third_library_function()
}

It's not a big deal tho

felixangell commented 8 years ago

@kiljacken I'm down with attribute blocks, that's primarily the reason I wanted them :+1: