Something Go and Scala syntax
spir
denis.spir at gmail.com
Thu Dec 30 06:07:52 PST 2010
On Thu, 30 Dec 2010 05:55:13 -0500
bearophile <bearophileHUGS at lycos.com> wrote:
> An alternative is to use Go syntax, and use the Pascal-like ":=" to denote a value assignment (function signature can't use := ).
> Here there is another idea from Go syntax: if the "then" clause of the "if" uses {} then the () around the test can be omitted:
>
> void foo(immutable int y) {
> x := 5;
> if i > x {
> writeln(x);
> }
> if (i > x)
> writeln(x);
> if i > x { // {} become necessary if you remove ()
> writeln(x);
> }
> }
1. I dislike optional () around conditions. I find better either always omitted or compulsary.
2. The alternative ':=' operator reminds me of a related past idea. In mainstream language, there is no difference between creating (definition) a new symbol and changing it (redefinition). I personly prefere ':' and ':=' or ':' and '::' (so that '=' means equality as expected). But '=' and ':=' would do the job.
In a local scope, value symbols could be considered immutable by default, so that using twice '=' on them would be an error. To change a symbol's value, one would have to use ':=' instead. This is a kind of explicite forced redefinition. Anyway, this is only needed for loop accumulators.
(see also http://spir.wikidot.com/create-vs-change -- I would enjoy having Bearophile's critics on this article ;-)
Denis
-- -- -- -- -- -- --
vit esse estrany ☣
spir.wikidot.com
More information about the Digitalmars-d
mailing list