Thesis on metaprogramming in D

Bruno Medeiros brunodomedeiros+spam at com.gmail
Thu Nov 30 14:07:42 PST 2006


Daniel Keep wrote:
> Bruno Medeiros wrote:
>> Daniel Keep wrote:
>>
>>>  > def sr = System.IO.StreamReader ("SomeFile.txt");
>>>
>>> Immutable run-time variables.  You can assign anything to them, and 
>>> then it can't change.  AFAIK, D's const doesn't let you do that.
>>>
>>
>> What's the difference from C# and Java's 'final'? Is the variable 
>> transitively unchangeable, or just the immediate value?
>>
> 
> I'm not really sure what 'transitively unchangeable' means... >_<
> 
'transitively unchangeable' or transitively const, means that in the 
case of references or pointers you can't change what is being referenced 
(and recursively so on). It's a transitive (recursive) read-only.

> Firstly, isn't 'final' just used for class members?  This is used for 
> local variables (or members, if I remember correctly).  As for the 
> second sentence, it's immutable storage.  So you can't change what's 
> stored in the variable, but if you've stored a reference, then you can 
> mutate what's being referenced.
> 
>     -- Daniel

Then that is just like 'final'. But I've realize now that this 'final' 
construct is only called 'final' in Java. The C# equivalent is actually 
called 'readonly' 
(http://msdn2.microsoft.com/en-us/library/acdd6hb7.aspx), whereas I 
thought it was 'final' too. Also, indeed the C# 'readonly' can only be 
used on fields, but the Java 'final' can be used on any variable, such 
as locals. And like Don said D has that feature too, but hideously 
hidden behind 'const'. -_-'

-- 
Bruno Medeiros - MSc in CS/E student
http://www.prowiki.org/wiki4d/wiki.cgi?BrunoMedeiros#D



More information about the Digitalmars-d mailing list