On Tuesday, 4 September 2018 at 16:36:20 UTC, Nick Treleaven
wrote:
Rust's lifetime syntax is noisy - the scope name is repeated,
and why require a name if it's usually not given a meaningful
one (`a`)?
Rust is more limited semantically due to unique mutability, so
it may have different requirements for function signatures to
D. (I think they recently tweaked the rules on how lifetimes
can be inferred).
As I was typing this up I was thinking about how Rust's rules
with how an object can be borrowed would affect it, but I can't
think of any examples off the top of my head.
My syntax for parameters that may get aliased to another
parameter is to write the parameter number that may escape it
in its scope attribute:
On Sunday, 2 September 2018 at 05:14:58 UTC, Chris M. wrote:
void betty(ref scope int*'a r, scope int*'a p) // okay it's
not pretty
void betty(ref scope int* r, scope(1) int* p);
p is documented as (possibly) escaped in parameter 1.
void betty(scope int*'a r, ref scope int*'a p)
void betty(scope(2) int* r, ref scope int* p);
I think my syntax is lightweight, clearer than Walter's
`return` for void functions PR, but just as expressive as your
examples.
I wouldn't disagree, it's much cleaner than what I had.
int*'a frank(scope int*'a p) { return p; } // basically id()
I'd keep `return scope` for p.
That's true, it'd also allow your other syntax to be fitted over
retroactively.
There's also:
void swap(ref scope(2) T a, ref scope(1) T b);
swap(r[0], r[1]);
Arguments to a,b must have the same lifetime. Without support
for this, we might need to use e.g. `swapAt(r, 0, 1)` instead
of indexing throughout range algorithms.
That's a good example.