Re: Why do immutable variables need reference counting?

2022-04-10 Thread norm via Digitalmars-d-learn
On Sunday, 10 April 2022 at 23:19:47 UTC, rikki cattermole wrote: immutable isn't tied to lifetime semantics. It only says that this memory will never be modified by anyone during its lifetime. This is clearly where I am misunderstanding. In my mind immutable data means the data will not ch

Why do immutable variables need reference counting?

2022-04-10 Thread norm via Digitalmars-d-learn
Hi All, I am clearly misunderstanding something fundamental, and probably obvious :D Reading some of the discussions on __metadata I was wondering if someone could explain why a immutable reference counting type is needed. By definition a reference counter cannot be immutable, so what would

Re: best/proper way to declare constants ?

2021-08-05 Thread norm via Digitalmars-d-learn
On Thursday, 5 August 2021 at 01:14:26 UTC, H. S. Teoh wrote: On Thu, Aug 05, 2021 at 12:47:06AM +, someone via Digitalmars-d-learn wrote: [...] 1) If the constant is a POD (int, float, etc.), use: enum myValue = ...; 2) If the constant is a string or some other array: s

Re: Compiler version "dirty"

2021-05-22 Thread Norm via Digitalmars-d-learn
On Monday, 8 March 2021 at 22:29:58 UTC, Q. Schroll wrote: When I enter `dmd --version`, it says: DMD64 D Compiler v2.095.1-dirty What should the "dirty" mean? To me, it seems looks something went wrong somewhere. This comes from `git describe --dirty` and indicates there were uncommitted c

Re: why is "hello".writeln considered bad?

2020-11-20 Thread norm via Digitalmars-d-learn
On Friday, 20 November 2020 at 18:46:40 UTC, Martin wrote: On Friday, 20 November 2020 at 10:03:18 UTC, Daniel Kozak wrote: I remember days when I liked UFCS too . Unfortunately it is not so awesome when you use it with IDE. And I would like to add: if you use in a bigger team. It's annoying

why is "hello".writeln considered bad?

2020-11-19 Thread norm via Digitalmars-d-learn
I was reading some posts and this was presented as a snippet of code and was immediately flagged as bad practice. I get some people don't like it but occasionally I prefer this syntax. It feels more declarative and fluent in style. Is there a good technical reason why it is bad practice, e.g.

Re: sort a string

2020-05-01 Thread norm via Digitalmars-d-learn
On Friday, 1 May 2020 at 07:38:53 UTC, Chris Katko wrote: I'm making anagrams. According to the nextPermutation() docs, I need to 'sort by less' to get all permutations. ... Except the doc page doesn't mention how to do that, nor does std.algorithm.sort show how to sort a string. ... and the g

Re: How to call a extern C++ class constructor ?

2020-02-01 Thread norm via Digitalmars-d-learn
On Saturday, 1 February 2020 at 08:38:22 UTC, Luhrel wrote: On Saturday, 1 February 2020 at 08:32:51 UTC, Ferhat Kurtulmuş wrote: On Saturday, 1 February 2020 at 08:27:07 UTC, Luhrel wrote: On Saturday, 1 February 2020 at 08:21:29 UTC, Ferhat Kurtulmuş wrote: You cannot. https://dlang.org/sp

Re: Indexed graphics for retro engine?

2019-09-19 Thread norm via Digitalmars-d-learn
On Thursday, 19 September 2019 at 20:47:45 UTC, Shadowblitz16 wrote: On Thursday, 19 September 2019 at 19:16:03 UTC, Mike Parker wrote: On Thursday, 19 September 2019 at 18:25:05 UTC, Shadowblitz16 wrote: I wanted to do 4bpp 16 color graphics. and I didn't want to load anything unnecessary in

Re: static if (is (T==Complex))

2019-09-18 Thread Norm via Digitalmars-d-learn
On Wednesday, 18 September 2019 at 11:10:11 UTC, berni wrote: Is it possible to simplfy this? static if (is (T==Complex!double) || is (T==Complex!float) || is (T==Complex!real)) I usually do something like the following: --- import std.traits; template isComplexReal(T) { enum isComplexRe

Re: Make executable archive just like Java's .jar archive?

2019-09-12 Thread norm via Digitalmars-d-learn
On Thursday, 12 September 2019 at 12:52:48 UTC, BoQsc wrote: Is there a way to archive multiple .d source code files and make that archive executable, or something similar? You can achieve something similar with rdmd and shell; $ tar -zcvf source_files.tar.gz source1.d source2.d ... sourceN.d

Re: Range violation error when reading from a file

2019-06-16 Thread Norm via Digitalmars-d-learn
On Monday, 17 June 2019 at 00:22:23 UTC, Samir wrote: On Sunday, 16 June 2019 at 23:55:41 UTC, lithium iodate wrote: There is *very* likely to be a terminating new-line at the end of the file (many editors add one without asking!). If that the case, the last line seen by the loop will be empty

Re: variant .init value

2019-02-07 Thread Norm via Digitalmars-d-learn
On Thursday, 7 February 2019 at 07:44:17 UTC, Alex wrote: On Thursday, 7 February 2019 at 07:33:50 UTC, Norm wrote: [...] Hmm... found something similar from 2014... https://issues.dlang.org/show_bug.cgi?id=11864 Thanks, I've added a comment to that bug report. Cheers, Norm

variant .init value

2019-02-06 Thread Norm via Digitalmars-d-learn
Hi, I'm trying to use Variant in a struct and want a default init value like so: --- struct S { Variant v = Variant(10); } void main() {auto s = S();} but when I try to build this I get the following error: dmd2/linux/bin64/../../src/phobos/std/variant.d(661): Error: memcpy cannot be inte

Re: Singleton in Action?

2019-02-02 Thread Norm via Digitalmars-d-learn
On Saturday, 2 February 2019 at 16:56:45 UTC, Ron Tarrant wrote: Hi guys, I ran into another snag this morning while trying to implement a singleton. I found all kinds of examples of singleton definitions, but nothing about how to put them into practice. Can someone show me a code example fo

Re: Singleton in Action?

2019-02-02 Thread Norm via Digitalmars-d-learn
On Saturday, 2 February 2019 at 16:56:45 UTC, Ron Tarrant wrote: Hi guys, I ran into another snag this morning while trying to implement a singleton. I found all kinds of examples of singleton definitions, but nothing about how to put them into practice. [...] If you haven't already been t

Re: Fields with the same name not causing a warning?

2018-11-16 Thread Norm via Digitalmars-d-learn
On Friday, 16 November 2018 at 15:59:14 UTC, Vinay Sajip wrote: This code should IMO give at least a warning, but it doesn't: abstract class A { int kind; } [...] This is not unique to D you can do the same in Java or C++. bye, Norm

Re: remove file access denied

2018-09-13 Thread Norm via Digitalmars-d-learn
On Thursday, 13 September 2018 at 23:25:24 UTC, Josphe Brigmo wrote: I am trying to remove a file remove(filename); and I get an access denied! I can remove it from explorer just fine. I am able to remove other files but there should be no reason why the file can't be removed in this case.

Re: Optional parameters?

2018-04-01 Thread Norm via Digitalmars-d-learn
On Sunday, 1 April 2018 at 15:54:16 UTC, Steven Schveighoffer wrote: I currently have a situation where I want to have a function that accepts a parameter optionally. I thought maybe Nullable!int might work: void foo(Nullable!int) {} void main() { foo(1); // error int x; foo(x); // e

Re: D RAII with postblit disabled

2018-03-28 Thread Norm via Digitalmars-d-learn
On Thursday, 29 March 2018 at 04:16:55 UTC, Adam D. Ruppe wrote: On Thursday, 29 March 2018 at 04:12:38 UTC, Norm wrote: Is there a way to do this in D, or does it require special "create" functions for every struct that has a RAII-like struct as a member? You'll have to do it all the way up

Re: D RAII with postblit disabled

2018-03-28 Thread Norm via Digitalmars-d-learn
On Tuesday, 27 March 2018 at 02:43:15 UTC, Adam D. Ruppe wrote: On Tuesday, 27 March 2018 at 02:35:23 UTC, Norm wrote: What's the best way to do this in D? I'd also add `@disable this();` and then a `static O make() { return O(theAllocator.make!int(99)); }` than you construct it with that s

Re: D RAII with postblit disabled

2018-03-26 Thread Norm via Digitalmars-d-learn
On Tuesday, 27 March 2018 at 02:43:15 UTC, Adam D. Ruppe wrote: On Tuesday, 27 March 2018 at 02:35:23 UTC, Norm wrote: What's the best way to do this in D? I'd also add `@disable this();` and then a `static O make() { return O(theAllocator.make!int(99)); }` than you construct it with that s

D RAII with postblit disabled

2018-03-26 Thread Norm via Digitalmars-d-learn
Hi All, What's the best way to do this in D? E.g. --- struct O { int* value; @disable this(this); /+ this() { this.value = theAllocator.make!int(99); } +/ ~this() { theAllocator.dispose(this.value); } } O obj = O(); // Ideally this would be allocated but it simply run

Re: Game and GC

2018-02-22 Thread Norm via Digitalmars-d-learn
On Friday, 23 February 2018 at 01:54:07 UTC, Leonardo wrote: Hi, I'm new to language and games. Many people say that GC is bad and can slow down your project in some moments. What can happen if I create a game using D without worrying with memory management? (using full GC) Have a look at ht

inout question

2018-02-11 Thread Norm via Digitalmars-d-learn
Hi, I'm new to D so can someone explain to me what is happening here? void func(const char* s, char** e) { import core.stdc.stdlib; auto result = strtod(s, e); } Error: function core.stdc.stdlib.strtod (scope inout(char)* nptr, scope inout(char)** endptr) is not callable using argumen

deprecation warning after upgrade

2018-02-07 Thread Norm via Digitalmars-d-learn
Hi All, In my generic code I now get this error, which requires manually finding all -a[] array ops, but that is another matter. $/src/druntime/import/core/internal/arrayop.d-mixin-57(57,20): Deprecation: integral promotion not done for -_param_1[pos], use '-transition=intpromote' switch or