The point of const, scope, and other attributes
jmh530
john.michael.hall at gmail.com
Wed May 11 16:45:22 UTC 2022
On Wednesday, 11 May 2022 at 13:56:32 UTC, Dennis wrote:
> On Wednesday, 11 May 2022 at 12:54:31 UTC, jmh530 wrote:
>> By contrast, Rust lifetimes are implemented in a more complex
>> way, but also operating at a higher level of abstraction. The
>> higher level of abstraction might also result in a lower
>> mental burden.
>
> I don't know what you mean with 'higher level of abstraction'
> here, can you give an example?
I don't know if I'm using it in the computer science way...
I mean it like how if you look at the rules of arithmetic
(distributive, associative, etc.) these apply to what we normally
think of as numbers (integers, reals, etc.) but then they apply
different to other things (like matrices). You can abstract from
these ideas to group theory and rings and make statements about
all algebras with particular rules.
So with respect to lifetimes, in D we can apply the return
attribute to a function parameter. From Rust's perspective, this
is equivalent to an explicit lifetime for a function parameter
that lasts as long as the return. I was phrasing it as the Rust
approach is a higher level of of abstraction, but you could also
think of it as the D approach is a subset of the Rust approach. I
think this was done on purpose, acknowledging that the return
annotation is the most often way Rust lifetimes are used. My
response would be that is all well and fine, but I still find
this confusing:
https://dlang.org/spec/function.html#ref-return-scope-parameters
More information about the Digitalmars-d
mailing list