3 ms·
"Variable announcing" solves that issue, please see the example in the following link: http://yosbelms.github.io/cor/docs/playground/index.html#link:---%0Aexam
by yosbelms 11y ago
"Variable announcing" solves that issue, please see the example in the following link:
http://yosbelms.github.io/cor/docs/playground/index.html#link:---%0Aexample%20of%20announcing%20variable%0A---%0A%0AsomeVar%20%3D%200%0A%0A%0A%2F%2F%20see%20how%20to%20use%20outer%0A%0Afunc%20usingOuter()%20%7B%0A%20%20%20%20someVar%20%3D%200%0A%7D%0A%0A%0A%2F%2F%20see%20the%20compiled%20code%20in%20the%20right%2C%0A%2F%2F%20notice%20the%20declaration%20inside%20the%20scope%0A%0Afunc%20avoidingOuter()%20%7B%0A%20%20%20%20someVar%0A%20%20%20%20someVar%20%3D%200%0A%7D http://yosbelms.github.io/cor/docs/playground/index.html#lin...
- dchest 11y agoI 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?
- yosbelms 11y agoLooking 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.
- dchest 11y agoThank 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: someVar := 123 //declared and assigned someVar = 456 // reassigned anotherVar = 777 // error: undeclared variable