preparing for const, final, and invariant

gareis dhasenan at gmail.com
Thu May 24 05:22:41 PDT 2007


== Quote from Regan Heath (regan at netmail.co.nz)'s article
> Regan Heath Wrote:
> > It seems to me you want both of these ('scope' because the reference will
persist outside the function and 'final' because the very point of 'ref' is to be
able to modify the reference) except in cases where you pass it by 'ref', in which
case you want neither.
> Re-reading this it appears I have made a mistake and worded it terribly to boot.
 To clarify...
> What I was trying to say is twofold:
> 1. Because we have 'ref' as an option then in the cases where we do not use
'ref' we do not need to modify the reference and therefore it should be 'final'.
> 2. Because the reference is not passed by 'ref' it is a copy and will not
persist outside the function and therefore is 'scope'
> In short, unless you use 'ref' you want 'scope final' applied to these references.
> Fingers crossed I haven't made any more mistakes there.
> Regan Heath

So wait...if I have a ref parameter, can I change the value of the reference
locally without global changes?

I like passing mutable copies of references. It's simple and expected behavior
that I can count on.

So will there be syntax that, for example, would give me the following?
---
void func(char[] a) {
   a = a[1..$]; // good
   a[1] = 'f';  // error
}
---

For that, I'd just use final, correct?



More information about the Digitalmars-d-announce mailing list