RFC: scope and borrowing
via Digitalmars-d
digitalmars-d at puremagic.com
Sat Oct 4 12:22:44 PDT 2014
On Saturday, 4 October 2014 at 18:13:03 UTC, Ivan Timokhin wrote:
> On the second thought, doesn't syntax look a bit awkward now? I
> mean, `scope!a(T)` certainly looks like `scope!a` as a whole is
> a type modifier. Since this syntax is pretty much limited to
> function return types with this proposal, maybe a better
> solution would be to have an owner as a separate annotation on
> a function?
I agree, but it should still stay closely associated to the
return type.
>
> Also, would it really make much sense to track the owner
> further than the assignment of a function's return value? That
> seems to complicate things a lot by adding a hidden attribute
> to a variable that is not only invisible at the declaration
> (even though the full type is spelled out), but, in fact,
> cannot be specified explicitly (because there's no syntax for
> that, now that scope with owners is limited to function
> signatures).
>
> How about this:
> ---
> scope(string) haystack, needle;
> // next assignment is okay, because `s` is guaranteed not
> to outlive
> // `haystack`.
> scope(string) s = findSubstring(haystack, needle);
> // type of `s` is now scope(string), no additional
> information
> // attached
>
> // so the next assignment is disallowed:
> //needle = s; // error!
> ---
>
> This could be unnecessarily limiting, but would it really cause
> much trouble?
I think you're right, I thought about this after I replied to
you. It would be the logical next step. On the other hand, I
wouldn't want to lose const borrowing, because it turned out to
be a requirement for safe moving. But I think it can still be
tracked internally (owner tracking is necessary for
implementation anyway).
More information about the Digitalmars-d
mailing list