mirror of
https://github.com/CPunch/Cosmo.git
synced 2025-10-20 16:00:23 +00:00
syntax: 'var'->'let' 'function'->'func'
- 'var' has some weird scoping connotations with users of JS. better to change it to 'let', which will decide whether to make the variable a local or a global - 'func' looks visually appealing lol - some minor refactoring done in cparse.c
This commit is contained in:
@@ -1,27 +1,27 @@
|
||||
proto test
|
||||
function __init(self, x)
|
||||
func __init(self, x)
|
||||
self:setArg(x)
|
||||
end
|
||||
|
||||
function __tostring(self)
|
||||
var total = 1
|
||||
func __tostring(self)
|
||||
let total = 1
|
||||
|
||||
for (var i = self.x; i > 0; i = i - 1) do
|
||||
for (let i = self.x; i > 0; i = i - 1) do
|
||||
total = total * i;
|
||||
end
|
||||
|
||||
return "The factorial of " .. self.x .. " is " .. total
|
||||
end
|
||||
|
||||
function setArg(self, x)
|
||||
func setArg(self, x)
|
||||
self.x = x
|
||||
end
|
||||
end
|
||||
|
||||
var t = test(1)
|
||||
let t = test(1)
|
||||
|
||||
for (var x = 1; x < 1000; x = x + 1) do
|
||||
for (var i = 1; i < 100; i = i + 1) do
|
||||
for (let x = 1; x < 1000; x = x + 1) do
|
||||
for (let i = 1; i < 100; i = i + 1) do
|
||||
t:setArg(i)
|
||||
|
||||
print(t)
|
||||
|
Reference in New Issue
Block a user