September 06, 2019
On Thursday, 5 September 2019 at 20:10:03 UTC, ag0aep6g wrote:
> You're not putting an immutable int into an AA. You're copying the value of an immutable int to a mutable one.
>
>> but I can't do that with a struct, having an immutable member. When I remove that immutable inside of the struct it works. ?!?
>
> `Point` is effectively the same as `immutable long`. A better simile would be this: `immutable(int)[int] a; a[1] = 17;`. And now you get the same error. You can't overwrite the element, because its immutable.

Ah, the point is not, that my object contains an immutable element, but that the base type of the AA is a type with an immutable element! I understand now. Thanks a lot!
September 06, 2019
On Thursday, 5 September 2019 at 21:22:12 UTC, Ali Çehreli wrote:
> If it makes for the type to have immutable (or const) members, then fine; with the understanding that objects of that type cannot be assigned or mutated any other way, we can define them like that. What I meant is, because we want to use such a type in an AA and we don't want the element to change should not dictate the type's members. Using in an AA should be yet another usage of the type.

Got it. ;-)

> > if immutable were that useless, why would it exist
> > at all?
>
> immutable is useful: You can have immutable objects, immutable AAs (different from what we are discussing here), etc.

So, what I'm just trying all the time is not to have a struct with immutable elements but a immutable struct-object with mutable elements. I think, that's what I confused all the time.

> As a general rule, I never make members const or immutable; this is a guideline that I carried over from C++.

I have almost no experience with C++, but I just accept that as a good advise. After all that discussion here, it seems to be sound.

Thank you very much too! I think I made a big jump forward in understanding the concept of immutability in the last 24 hours. :-)
September 06, 2019
On Friday, 6 September 2019 at 08:47:07 UTC, Kagamin wrote:
> Physical objects work like reference types. A place on bookshelf is at one coordinate and a book is at another coordinate, you don't copy the book, you fill a place on bookshelf with a reference to the book.

So it's more like a piece of paper, where there is place for a note. And when assigning, I erase that note (whatever it was) and write the new note at that place. Got it! :-)
1 2 3
Next ›   Last »