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
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 wan
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 work
On Thursday, 5 September 2019 at 12:46:06 UTC, berni wrote:
OK. This are two solutions and although I'll probably not going
to use any of those (due to other reasons), I still don't
understand, why the original approach does not work. If I've
got a book an put it in a box and later I'll get it
On 09/05/2019 12:51 PM, berni wrote:
>> int[int] a;
>>
>> immutable int b = 17;
>> a[1] = b; // <-- expecting error here
As explained elsewhere, a[1] is a mutable int. That assignment is
copying b on top of the element.
>> const oldPointer = (1 in a);
On 05.09.19 21:51, berni wrote:
void main()
{
int[int] a;
immutable int b = 17;
a[1] = b; // <-- expecting error here
const oldPointer = (1 in a);
immutable int c = 10;
a[1] = c;
assert(oldPointer is (1 in a));
Point[int] d;
immutabl
On Thursday, 5 September 2019 at 15:48:40 UTC, Ali Çehreli wrote:
That's the misunderstanding: The existing object is assigned
over. The address is the same:
void main() {
int[int] aa;
aa[1] = 1;
const oldPointer = (1 in aa);
aa[1] = 11;
assert(oldPointer is (1 in aa)); // Passes
}
On 09/05/2019 07:31 AM, berni wrote:
> On Thursday, 5 September 2019 at 13:27:55 UTC, drug wrote:
>> [...]when you put it into an AA you modify old value
>
> Why?!? :-o When putting it into an AA it will be copied to a different
> place in memory,
That's the misunderstanding: The existing object
05.09.2019 17:31, berni пишет:
On Thursday, 5 September 2019 at 13:27:55 UTC, drug wrote:
[...]when you put it into an AA you modify old value
Why?!? :-o When putting it into an AA it will be copied to a different
place in memory, but the value is still the same, it's not modified.
Sorry, bu
On Thursday, 5 September 2019 at 13:27:55 UTC, drug wrote:
[...]when you put it into an AA you modify old value
Why?!? :-o When putting it into an AA it will be copied to a
different place in memory, but the value is still the same, it's
not modified. Sorry, but I still think, there is someth
05.09.2019 15:46, berni пишет:
On Thursday, 5 September 2019 at 12:15:51 UTC, drug wrote:
One solution could be using either pointer to `const(Point)` or class
here (to avoid pointer using) https://run.dlang.io/is/rfKKAJ
OK. This are two solutions and although I'll probably not going to use
a
On Thursday, 5 September 2019 at 12:15:51 UTC, drug wrote:
One solution could be using either pointer to `const(Point)` or
class here (to avoid pointer using)
https://run.dlang.io/is/rfKKAJ
OK. This are two solutions and although I'll probably not going
to use any of those (due to other reaso
05.09.2019 14:28, berni пишет:
On Thursday, 5 September 2019 at 11:22:15 UTC, drug wrote:
05.09.2019 14:17, berni пишет:
Point[long] q;
q[1] = Point(3);
Leads to:
test.d(7): Error: cannot modify struct q[1L] Point with immutable
members
But why do you try to modify immutable data? What
On Thursday, 5 September 2019 at 11:22:15 UTC, drug wrote:
05.09.2019 14:17, berni пишет:
Point[long] q;
q[1] = Point(3);
Leads to:
test.d(7): Error: cannot modify struct q[1L] Point with
immutable members
But why do you try to modify immutable data? What is your
point? Could you descri
05.09.2019 14:17, berni пишет:
Point[long] q;
q[1] = Point(3);
Leads to:
test.d(7): Error: cannot modify struct q[1L] Point with immutable members
But why do you try to modify immutable data? What is your point? Could
you describe you use case?
On Thursday, 5 September 2019 at 10:47:56 UTC, Simen Kjærås wrote:
https://dlang.org/library/std/range/retro.html
Yeah, that worked. Thanks. :-)
Don't worry about asking questions
OK. Then here's the next one:
Point[long] q;
q[1] = Point(3);
Leads to:
test.d(7): Error: cannot modify s
On Thursday, 5 September 2019 at 09:07:30 UTC, berni wrote:
import std.algorithm: reverse;
writeln(q.reverse);
How to get this working? (I hope I don't annoy you by asking
that much questions, but I've got the feeling, that I've got
only two choices: To shy away from using immutable (like I d
On Thursday, 5 September 2019 at 08:56:42 UTC, berni wrote:
[..]
And one more question:
import std.algorithm: reverse;
writeln(q.reverse);
Here the compiler complains with:
test.d(8): Error: template std.algorithm.mutation.reverse
cannot deduce function from argument types !()(Point[]),
On Thursday, 5 September 2019 at 08:44:35 UTC, berni wrote:
This doesn't compile:
[...]
Any idea, how to get around this?
Found the answer myself: q.map!(a=>a.x).minElement; :-)
On Thursday, 5 September 2019 at 08:16:08 UTC, Daniel Kozak wrote:
in this case you can just use:
auto q = cast()p.x;
Ahh, great! :-)
But that directly gets me to the next question:
import std.stdio;
void main()
{
Point[] q = [Point(1),Point(3),Point(2)];
import std.algorithm.sear
On Thursday, 5 September 2019 at 08:16:08 UTC, Daniel Kozak wrote:
On Thu, Sep 5, 2019 at 9:55 AM berni via Digitalmars-d-learn
wrote:
I still struggle with the concept of immutable and const:
> import std.stdio;
>
> void main()
> {
> auto p = Point(3);
> auto q = p.x;
> writeln(t
On Thu, Sep 5, 2019 at 9:55 AM berni via Digitalmars-d-learn
wrote:
>
> I still struggle with the concept of immutable and const:
>
> > import std.stdio;
> >
> > void main()
> > {
> > auto p = Point(3);
> > auto q = p.x;
> > writeln(typeof(q).stringof);
> > }
> >
> > struct Point
> > {
I still struggle with the concept of immutable and const:
import std.stdio;
void main()
{
auto p = Point(3);
auto q = p.x;
writeln(typeof(q).stringof);
}
struct Point
{
@property immutable long x;
}
The type of q is immutable(long). But I need a mutable q. I found
two ways:
23 matches
Mail list logo