Cor does not has a keyword to declare variables, instead, Cor declares it for you the first time it is used. If a variable with equal name is declared in outer scope the compiler will assume you are using the declared outside. Unless you write the variable as a simple statement. This technique is called variable announcing.
Sadly, it's the same mistake that CoffeeScript made: you cannot just introduce a variable, to be completely sure you didn't break anything, you'll have to search for all uses of it in outer scope above and inner scopes below.
I understand that you can announce variable, but to be save, you'll have to announce it in every scope you want to declare it, so why not just use "var" or ":=" to declare and assign?
Looking for simplicity. One of the goals of Cor is to have few keywords, to make it easy to learn, to get involved, and to work with. I had three possible solutions to solve the variable scoping problem.
1- `var` keyword. Like javascript. It assumes all variables are global if not declared with `var`.
2- `global` keyword. Like PHP. It assumes all variables are local unlike that is annotated with `global`.
3- Ruby-like, Coffeescript-like.
A mixing of options number 1 and 3 was chosen.
I will open an issue regarding this subject, considering your proposal for future versions.
Thank you. Actually, what I think the best way is to make it an error to use undeclared variable, unlike in JavaScript. If it's a global, is should be declared in global scope. I really like this way of declaring variables, so please consider it:
This is the first transcompiled JS language I've seen that I have wanted to use. It's as strait forward as JS, but adds a lot of features I wished the language had.
Not sure I really see the point of this. The syntax seems to offer little beyond what's possible already in ES6, and is missing several features, such as generators, destructuring, rest and spread operators and template strings that are very useful in modern JS development.
Most of the design of ES6 is like this due to backward compatibility. I'm very sure if the comunity behind ES6 specs designs a language for the web regardless backward compatibility, ES would be very different to what it actually is. These features you are mentioning are awesome, for sure. But ES6 is bloated for sake of having features plus backward compatibility. Cor is different, it is simple but modern, it is going in the opposite direction.
9 comments
[ 3.5 ms ] story [ 37.6 ms ] threadSadly, it's the same mistake that CoffeeScript made: you cannot just introduce a variable, to be completely sure you didn't break anything, you'll have to search for all uses of it in outer scope above and inner scopes below.
https://donatstudios.com/CoffeeScript-Madness
http://yosbelms.github.io/cor/docs/playground/index.html#lin...
1- `var` keyword. Like javascript. It assumes all variables are global if not declared with `var`. 2- `global` keyword. Like PHP. It assumes all variables are local unlike that is annotated with `global`. 3- Ruby-like, Coffeescript-like.
A mixing of options number 1 and 3 was chosen.
I will open an issue regarding this subject, considering your proposal for future versions.