Something Go and Scala syntax

sybrandy sybrandy at gmail.com
Thu Dec 30 04:59:24 PST 2010


Sigils may be another solution.  I've been a fan of them in Perl/PHP for 
various reasons and I think that they should be considered here, though 
maybe not in the same way.  Here are a couple possible examples using 
bearophile's first example:

void foo(int $y) {
     $x = 5;
     if (i > $x) {
         writeln($x);
     }
     if (i > $x)
         writeln($x);
}

In this example, the sigil is on the variable to mark that it is 
immutable.  This has the advantage of making it clear that the variable 
is immutable, however it also means that we have to apply the sigil 
everywhere the variable is used.  Also, if for some reason the variable 
should not be immutable anymore, then we have to change every instance.

void foo($int y) {
     $int x = 5;
     if (i > x) {
         writeln(x);
     }
     if (i > x)
         writeln(x);
}

Here the sigil is on the type and indicates that x and y are of the type 
"immutable int".  It's short and it's clear that the type is different 
here, however it isn't as self explanatory as using "immutable int". 
However, it is the shortest possible solution I can think of.

Casey


More information about the Digitalmars-d mailing list