Re: Programming in D, page 155. shared static this() fails

2025-07-30 Thread monkyyy via Digitalmars-d-learn
On Wednesday, 30 July 2025 at 18:00:39 UTC, H. S. Teoh wrote: On Wed, Jul 30, 2025 at 10:54:15AM -0600, Jonathan M Davis via Digitalmars-d-learn wrote: [...] immutable int[] i; shared static this() { immutable(int)[] temp; temp ~= foo(); temp ~= bar(); i = temp; } But even the

Re: Programming in D, page 155. shared static this() fails

2025-07-30 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Jul 30, 2025 at 10:54:15AM -0600, Jonathan M Davis via Digitalmars-d-learn wrote: [...] > immutable int[] i; > > shared static this() > { > immutable(int)[] temp; > temp ~= foo(); > temp ~= bar(); > i = temp; > } > > But even the shared static constructor isn't allowed to

Re: Programming in D, page 155. shared static this() fails

2025-07-30 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, July 29, 2025 5:18:18 PM Mountain Daylight Time Brother Bill via Digitalmars-d-learn wrote: > Your changes do work, but at the cost of making i NOT deeply > immutable: no assignment, no changing any elements, no appending, > no setting length. This syntax permits appending and setting

Re: Programming in D, page 155. shared static this() fails

2025-07-29 Thread monkyyy via Digitalmars-d-learn
On Tuesday, 29 July 2025 at 23:48:58 UTC, H. S. Teoh wrote: `i` is immutable, so it's illegal to use mutating operations like ~= on it. @luna The question should be if programming in d (page 177 https://ddili.org/ders/d.en/Programming_in_D.pdf) should be authoritive here It is possible t

Re: Programming in D, page 155. shared static this() fails

2025-07-29 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Jul 29, 2025 at 10:57:50PM +, Brother Bill via Digitalmars-d-learn wrote: > ``` > import std.stdio; > > immutable int[] i; > > shared static this() { > writeln("In shared static this()"); > i ~= 43; > } `i` is immutable, so it's illegal to use mutating operations like ~=

Re: Programming in D, page 155. shared static this() fails

2025-07-29 Thread Luna via Digitalmars-d-learn
On Tuesday, 29 July 2025 at 22:57:50 UTC, Brother Bill wrote: ``` import std.stdio; immutable int[] i; shared static this() { writeln("In shared static this()"); i ~= 43; } void main() { writeln("In main()"); writeln("i: ", i); } ``` Error messages: C:\D\dmd2\w

Re: Programming in D, page 155. shared static this() fails

2025-07-29 Thread monkyyy via Digitalmars-d-learn
On Tuesday, 29 July 2025 at 23:18:18 UTC, Brother Bill wrote: Your changes do work, but at the cost of making i NOT deeply immutable: no assignment, no changing any elements, no appending, no setting length. if you insit on the type id suggest this code then ```d import std.stdio; immutabl

Re: Programming in D, page 155. shared static this() fails

2025-07-29 Thread Brother Bill via Digitalmars-d-learn
On Tuesday, 29 July 2025 at 23:03:41 UTC, monkyyy wrote: On Tuesday, 29 July 2025 at 22:57:50 UTC, Brother Bill wrote: ``` import std.stdio; immutable int[] i; shared static this() { writeln("In shared static this()"); i ~= 43; } void main() { writeln("In main()");

Re: Programming in D, page 155. shared static this() fails

2025-07-29 Thread monkyyy via Digitalmars-d-learn
On Tuesday, 29 July 2025 at 22:57:50 UTC, Brother Bill wrote: ``` import std.stdio; immutable int[] i; shared static this() { writeln("In shared static this()"); i ~= 43; } void main() { writeln("In main()"); writeln("i: ", i); } ``` Error messages: C:\D\dmd2\w

Programming in D, page 155. shared static this() fails

2025-07-29 Thread Brother Bill via Digitalmars-d-learn
``` import std.stdio; immutable int[] i; shared static this() { writeln("In shared static this()"); i ~= 43; } void main() { writeln("In main()"); writeln("i: ", i); } ``` Error messages: C:\D\dmd2\windows\bin64\..\..\src\druntime\import\core\internal\array\appe