StardustPL / Stardust

"A programming language that doesn't make me angry to use it."
https://StardustPL.GitHub.IO/
The Unlicense
4 stars 0 forks source link

Planning: Variable Declaration #15

Open LB-- opened 9 years ago

LB-- commented 9 years ago

I'm not sure how I want variables to be declared. I could use var to hint to initiate a variable declaration as with some languages, thus avoiding the most-vexing-parse issue in C++, but this seems like an awkward solution. If I did it like in C++ or Go, there would need to be a way to distinguish between a new identifier shadowing an existing one vs an identifier being a variable that holds the type of the new variable (maybe).

Here are some examples that I am thinking through:

type identifier //1: C++/Java style
identifier type //2: Go style
var identifier type //3: JavaScript-esque, kind of unusual in Stardust
`identifier` type //4
type `identifier` //5
`identifier`(type) //6: functional syntax (kind of does the impossible for functions though)
type(`identifier`) //7: functional syntax (again, kind of does the impossible)
//others?

There is also the question about initialization - all of the above would use default initialization. For value initialization, I am considering declaration := value, but it's different when passing multiple parameters.

type identifier (params, ...) //1A: C++ style
type identifier : (params, ...) //1B
identifier type(params, ...) //2A: might be ambiguous if a type doubles as a function (e.g. chain types)
identifier type:(params, ...) //2B
//1/2 are pretty similar to 4/5
//Not sure about the rest
LB-- commented 8 years ago

If I decide to go with #9 we will need to use a syntax which is not ambiguous with unary operator usage.

LB-- commented 8 years ago

Declared variables should be implicitly immutable and require an explicit keyword to be made mutable.