DIP25/DIP1000: My thoughts round 2

Nick Treleaven nick at geany.org
Tue Sep 4 16:36:20 UTC 2018


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).

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.

> int*'a frank(scope int*'a p) { return p; } // basically id()

I'd keep `return scope` for p.

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.



More information about the Digitalmars-d mailing list