These are chat archives for mozart/mozart2

3rd
Oct 2015
Sidhant Bhavnani
@cosmicAsymmetry
Oct 03 2015 09:41 UTC
Can someone help me fix my syntax error>
Sébastien Doeraene
@sjrd
Oct 03 2015 09:42 UTC
What's the error and the code?
Sidhant Bhavnani
@cosmicAsymmetry
Oct 03 2015 09:42 UTC
fun {MainSum N}
local Sum in
fun {Sum N Acc}
if N==0 then Acc
else
Acc = Acc+(N*N)
N = N-1
end
{Sum N 0}
end
end
Sébastien Doeraene
@sjrd
Oct 03 2015 09:43 UTC
Sidhant Bhavnani
@cosmicAsymmetry
Oct 03 2015 09:43 UTC
fun {MainSum N}
local Sum in
fun {Sum N Acc}
if N==0 then Acc
else
Acc = Acc+(N*N)
N = N-1
end
{Sum N 0}
end
end
'''
fun {MainSum N}
local Sum in
fun {Sum N Acc}
if N==0 then Acc
else
Acc = Acc+(N*N)
N = N-1
end
{Sum N 0}
end
end
'''
Sébastien Doeraene
@sjrd
Oct 03 2015 09:44 UTC
backquotes, like 
You don't have a syntax error. You are trying to reassign immutable variables. Acc = Acc+(N*N) doesn't mean anything. No more than saying "let x = x + n²" in mathematics. You just can't change the value of variables.
Sidhant Bhavnani
@cosmicAsymmetry
Oct 03 2015 09:46 UTC
fun {MainSum N}
local Sum in
fun {Sum N Acc}
if N==0 then Acc
else
Acc = Acc+(N*N)
N = N-1
end
{Sum N 0}
end
end
Sébastien Doeraene
@sjrd
Oct 03 2015 09:47 UTC
You need to call Sum recursively with different values for the parameters N and Acc instead.
Sidhant Bhavnani
@cosmicAsymmetry
Oct 03 2015 09:47 UTC
Aah I see.
Thank you.
Acc = Acc+(N*N)
{Sum Acc N*N}`