const fac4 = (var x = 1; for i in 1..4: x *= i; x)
It works fine. I re-wrote it as (no change in logic or identifiers):
const fac4 = (
var x = 1;
for i in 1..4: x *= i;
x)
It also worked fine. However when I indented the for loop as in following code, it throws compile error for last line x) Error: ')' expected
const fac4 = (
var x = 1;
for i in 1..4:
x *= i;
x)
What is the reason for error?
Thanks Araq, can't it be extended to expression as shown in the last piece of code or will it be supported in future?
Following line definitely provides a clean interface in terms of writing logic that need to be assigned to a variable without worrying about two different syntax to remember :
var x = ( ....
.....
)
Am I thinking something wrong?
Sure it can be extended in the future, but you're the first one who complains about it. ;-) Here's one reason why most people are already happy: There is nothing clean about
var x = (echo "foo"; 13)
when there is already
echo "foo"
var x = 13
Note that both yield a void type, so it's not like composition works any better with var x = (;;).
Hi Araq, frankly as you said, there will not be a need to do such assignments as there are better ways to do it.
Thanks for clarification.