Re: LDC 1.38.0

2024-05-15 Thread H. S. Teoh via Digitalmars-d-announce
On Sat, May 11, 2024 at 01:22:58AM +, kinke via Digitalmars-d-announce wrote: > Glad to announce LDC 1.38.0. Major changes: > > - Based on D 2.108.1. > - Support for LLVM 18; the prebuilt packages use v18.1.5. > - Android: Switch to native ELF TLS, supported since API level 29 (Android >

Re: Range handling difficulties

2024-04-24 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Apr 24, 2024 at 08:08:06AM +, Menjanahary R. R. via Digitalmars-d-learn wrote: > I tried to solve Project Euler [problem > #2](https://projecteuler.net/problem=2) using > [Recurrence/recurrence](https://dlang.org/library/std/range/recurrence.html). > > Assuming `genEvenFibonacci` is

Re: Unittests pass, and then an invalid memory operation happens after?

2024-04-06 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Apr 03, 2024 at 09:57:00PM +, Liam McGillivray via Digitalmars-d-learn wrote: > On Friday, 29 March 2024 at 01:18:22 UTC, H. S. Teoh wrote: > > Take a look at the docs for core.memory.GC. There *is* a method > > GC.free that you can use to manually deallocate GC-allocated memory > >

Re: Inconsistent chain (implicitly converts to int)

2024-04-05 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Apr 05, 2024 at 03:18:09PM +, Salih Dincer via Digitalmars-d-learn wrote: > Hi everyone, > > Technically r1 and r2 are different types of range. Isn't it > inconsistent to chain both? If not, why is the char type converted to > int? [...] It's not inconsistent if there exists a

Re: Unittests pass, and then an invalid memory operation happens after?

2024-03-28 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Mar 28, 2024 at 11:49:19PM +, Liam McGillivray via Digitalmars-d-learn wrote: > On Thursday, 28 March 2024 at 04:46:27 UTC, H. S. Teoh wrote: > > The whole point of a GC is that you leave everything up to it to > > clean up. If you want to manage your own memory, don't use the GC. >

Re: Difference between chunks(stdin, 1) and stdin.rawRead?

2024-03-28 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Mar 28, 2024 at 10:10:43PM +, jms via Digitalmars-d-learn wrote: > On Thursday, 28 March 2024 at 02:30:11 UTC, jms wrote: [...] > I think I figured it out and the difference is probably in the mode. > This documentation >

Re: Opinions on iterating a struct to absorb the decoding of a CSV?

2024-03-28 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Mar 28, 2024 at 05:23:39PM +, Andy Valencia via Digitalmars-d-learn wrote: [...] > auto t = T(); > foreach (i, ref val; t.tupleof) { > static if (is(typeof(val) == int)) { > val = this.get_int(); > } else { > val = this.get_str(); >

Re: Unittests pass, and then an invalid memory operation happens after?

2024-03-27 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Mar 28, 2024 at 03:56:10AM +, Liam McGillivray via Digitalmars-d-learn wrote: [...] > I may be now starting to see why the use of a garbage collector is > such a point of contention for D. Not being able to predict how the > garbage collection process will happen seems like a major

Re: Unittests pass, and then an invalid memory operation happens after?

2024-03-27 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Mar 27, 2024 at 09:43:48PM +, Liam McGillivray via Digitalmars-d-learn wrote: [...] > ``` > ~this() { > this.alive = false; > if (this.map !is null) this.map.removeUnit(this); > if (this.faction !is null) this.faction.removeUnit(this); > if

Re: Challenge: Make a data type for holding one of 8 directions allowing increment and overflow

2024-03-16 Thread H. S. Teoh via Digitalmars-d-learn
On Sat, Mar 16, 2024 at 09:16:51PM +, Liam McGillivray via Digitalmars-d-learn wrote: > On Friday, 15 March 2024 at 00:21:42 UTC, H. S. Teoh wrote: [...] > > When dealing with units of data smaller than a byte, you generally > > need to do it manually, because memory is not addressable by > >

Re: Challenge: Make a data type for holding one of 8 directions allowing increment and overflow

2024-03-14 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Mar 14, 2024 at 11:39:33PM +, Liam McGillivray via Digitalmars-d-learn wrote: [...] > I tried to rework the functions to use bitwise operations, but it was > difficult to figure out the correct logic. I decided that it's not > worth the hassle, so I just changed the value storage from

Re: varargs when they're not all the same type?

2024-03-14 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Mar 14, 2024 at 08:58:21PM +, Andy Valencia via Digitalmars-d-learn wrote: > On Thursday, 14 March 2024 at 18:05:59 UTC, H. S. Teoh wrote: > > ... > > The best way to do multi-type varags in D is to use templates: > > > > import std; > > void myFunc(Args...)(Args args) { > >

Re: varargs when they're not all the same type?

2024-03-14 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Mar 14, 2024 at 05:57:21PM +, Andy Valencia via Digitalmars-d-learn wrote: > Can somebody give me a starting point for understanding varadic > functions? I know that we can declare them > > int[] args... > > and pick through whatever the caller provided. But if the caller >

Re: Is D programming friendly for beginners?

2024-03-12 Thread H. S. Teoh via Digitalmars-d-announce
On Tue, Mar 12, 2024 at 08:40:49PM +, Meta via Digitalmars-d-announce wrote: [...] > I think it really depends on the person. My first language was C++, which > was absolute hell to learn as a complete beginner to programming, but I > really wanted to learn a language with low-level

Re: Is D programming friendly for beginners?

2024-03-12 Thread H. S. Teoh via Digitalmars-d-announce
On Tue, Mar 12, 2024 at 06:03:43PM +, Lance Bachmeier via Digitalmars-d-announce wrote: > On Tuesday, 12 March 2024 at 17:03:42 UTC, Mike Shah wrote: > > > As a note, the 'which language is best for CS 1' debate has long > > been debated -- but at least in a school setting, I've found the >

Re: Hidden members of Class objects

2024-03-06 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Mar 06, 2024 at 11:39:13PM +, Carl Sturtivant via Digitalmars-d-learn wrote: > I notice that a class with no data members has a size of two words (at > 64 bits). Presumably there's a pointer to a table of virtual > functions, and one more. Is the Vtable first? [...] > What is actually

Re: LDC 1.37.0

2024-03-05 Thread H. S. Teoh via Digitalmars-d-announce
On Sun, Mar 03, 2024 at 02:46:34PM +, kinke via Digitalmars-d-announce wrote: > Glad to announce LDC 1.37.0. Major changes: > > * Based on D 2.107.1. > * Important fix wrt. if-statement elision on constant condition. > > Full release log and downloads: >

Re: Array types and index types

2024-02-27 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Feb 28, 2024 at 03:00:55AM +, Liam McGillivray via Digitalmars-d-learn wrote: > In D, it appears that dynamic arrays (at least by default) use a ulong > as their key type. They are declared like this: > ``` > string[] dynamicArray; > ``` > > I imagine that using a 64-bit value as the

Re: what was the problem with the old post blit operator already ?

2024-02-14 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Feb 15, 2024 at 02:17:15AM +, Basile B. via Digitalmars-d-learn wrote: > From what I remember, it was that there was no reference to the > source. Things got blitted and you had to fix the copy, already > blitted. Was that the only issue ? I don't quite remember all of the reasons

Re: length's type.

2024-02-13 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Feb 13, 2024 at 06:36:22PM +, Nick Treleaven via Digitalmars-d-learn wrote: > On Monday, 12 February 2024 at 18:22:46 UTC, H. S. Teoh wrote: [...] > > Honestly, I think this issue is blown completely out of proportion. > > The length of stuff in any language needs to be some type. D

Re: length's type.

2024-02-12 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Feb 12, 2024 at 07:34:36PM +, bachmeier via Digitalmars-d-learn wrote: > On Monday, 12 February 2024 at 18:22:46 UTC, H. S. Teoh wrote: > > > Honestly, I think this issue is blown completely out of proportion. > > Only for people that don't have to deal with the problems it causes.

Re: length's type.

2024-02-12 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Feb 12, 2024 at 05:26:25PM +, Nick Treleaven via Digitalmars-d-learn wrote: > On Friday, 9 February 2024 at 15:19:32 UTC, bachmeier wrote: > > It's been discussed many, many times. The behavior is not going to > > change - there won't even be a compiler warning. (You'll have to > >

Re: The difference between the dates in years

2024-02-10 Thread H. S. Teoh via Digitalmars-d-learn
On Sat, Feb 10, 2024 at 03:53:09PM +, Alexander Zhirov via Digitalmars-d-learn wrote: > Is it possible to calculate the difference between dates in years > using regular means? Something like that > > > ``` > writeln(Date(1999, 3, 1).diffMonths(Date(1999, 1, 1))); > ``` > > At the same

Re: std.uni CodepointSet toString

2024-02-08 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Feb 08, 2024 at 06:22:29PM +, Carl Sturtivant via Digitalmars-d-learn wrote: > On Wednesday, 7 February 2024 at 17:11:30 UTC, H. S. Teoh wrote: > > Do we know why the compiler isn't getting it right? Shouldn't we be > > fixing it instead of just turning off elision completely? > >

Re: std.uni CodepointSet toString

2024-02-07 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Feb 08, 2024 at 05:44:59AM +1300, Richard (Rikki) Andrew Cattermole via Digitalmars-d-learn wrote: > On 08/02/2024 5:36 AM, Carl Sturtivant wrote: [...] > > ``` > > $ dmd --help | grep allinst > >   -allinst  generate code for all template instantiations > > ``` > > Unclear

Re: trouble with associative Arrays

2024-01-20 Thread H. S. Teoh via Digitalmars-d-learn
On Sat, Jan 20, 2024 at 02:33:24PM +, atzensepp via Digitalmars-d-learn wrote: > Hello, > > I am new with D and want to convert a c program for a csv file manipulation > with exhaustive dynamic memory mechanics to D . > > When reading a CSV-file line by line I would like to create an

Re: Help optimize D solution to phone encoding problem: extremely slow performace.

2024-01-19 Thread H. S. Teoh via Digitalmars-d-learn
On Sat, Jan 20, 2024 at 01:35:44AM +0100, Daniel Kozak via Digitalmars-d-learn wrote: [...] >> Try addressing the points I wrote above and see if it makes a >> difference. > >I have tried it (all of it) even before you wrote it here, because >I have completely the same ideas, but

Re: Help optimize D solution to phone encoding problem: extremely slow performace.

2024-01-19 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Jan 19, 2024 at 01:40:39PM +, Renato via Digitalmars-d-learn wrote: > On Friday, 19 January 2024 at 10:15:57 UTC, evilrat wrote: [...] > > Additionally if you comparing D by measuring DMD performance - > > don't. It is valuable in developing for fast iterations, but it > > lacks many

Re: Help optimize D solution to phone encoding problem: extremely slow performace.

2024-01-18 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Jan 18, 2024 at 04:23:16PM +, Renato via Digitalmars-d-learn wrote: [...] > Ok, last time I'm running this for someone else :D > > ``` > Proc,Run,Memory(bytes),Time(ms) > ===> ./rust > ./rust,23920640,30 > ./rust,24018944,147 > ./rust,24068096,592 > ./rust,24150016,1187 >

Re: Datetime format?

2024-01-18 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Jan 18, 2024 at 11:58:32PM +, zoujiaqing via Digitalmars-d-learn wrote: > On Thursday, 18 January 2024 at 23:43:13 UTC, Jonathan M Davis wrote: > > On Thursday, January 18, 2024 4:26:42 PM MST zoujiaqing via > > Digitalmars-d- learn wrote: > > > ```D > > > import std.datetime : Clock,

Re: Help optimize D solution to phone encoding problem: extremely slow performace.

2024-01-17 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Jan 17, 2024 at 07:57:02AM -0800, H. S. Teoh via Digitalmars-d-learn wrote: [...] > I'll push the code to github. [...] Here: https://github.com/quickfur/prechelt/blob/master/encode_phone.d T -- Why do conspiracy theories always come from the same people??

Re: Help optimize D solution to phone encoding problem: extremely slow performace.

2024-01-17 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Jan 17, 2024 at 07:19:39AM +, Renato via Digitalmars-d-learn wrote: [...] > But pls run the benchmarks yourself as I am not going to keep running > it for you, and would be nice if you posted your solution on a Gist > for example, pasting lots of code in the forum makes it difficult to

Re: Help optimize D solution to phone encoding problem: extremely slow performace.

2024-01-17 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Jan 17, 2024 at 07:19:39AM +, Renato via Digitalmars-d-learn wrote: > On Tuesday, 16 January 2024 at 22:13:55 UTC, H. S. Teoh wrote: > > used for the recursive calls. Getting rid of the .format ought to > > speed it up a bit. Will try that now... > > > > That will make no difference

Re: Help optimize D solution to phone encoding problem: extremely slow performace.

2024-01-16 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Jan 16, 2024 at 10:15:04PM +, Siarhei Siamashka via Digitalmars-d-learn wrote: > On Tuesday, 16 January 2024 at 21:15:19 UTC, Renato wrote: [...] > > ... what I am really curious about is what the code I wrote is doing > > wrong that causes it to run 4x slower than Rust despite doing

Re: Help optimize D solution to phone encoding problem: extremely slow performace.

2024-01-16 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Jan 16, 2024 at 09:15:19PM +, Renato via Digitalmars-d-learn wrote: > On Tuesday, 16 January 2024 at 20:34:48 UTC, H. S. Teoh wrote: > > On Tue, Jan 16, 2024 at 12:28:49PM -0800, H. S. Teoh via > > Digitalmars-d-learn wrote: [...] > > > Anyway, I've fixed the

Re: Help optimize D solution to phone encoding problem: extremely slow performace.

2024-01-16 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Jan 16, 2024 at 12:28:49PM -0800, H. S. Teoh via Digitalmars-d-learn wrote: [...] > Anyway, I've fixed the problem, now my program produces the exact same > output as Renato's repo. Code is posted below. [...] Oops, forgot to actually paste the code

Re: Help optimize D solution to phone encoding problem: extremely slow performace.

2024-01-16 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Jan 16, 2024 at 06:54:56PM +, Renato via Digitalmars-d-learn wrote: > On Tuesday, 16 January 2024 at 16:56:04 UTC, Siarhei Siamashka wrote: [...] > > You are not allowed to emit "1" as the first token in the output as > > long as there are any dictionary word matches at that position.

Re: Help optimize D solution to phone encoding problem: extremely slow performace.

2024-01-16 Thread H. S. Teoh via Digitalmars-d-learn
P.S. Compiling my program with `ldc -O2`, it runs so fast that I couldn't measure any meaningful running time that's greater than startup overhead. So I wrote a helper program to generate random phone numbers up to 50 characters long, and found that it could encode 1 million phone numbers in 2.2

Re: Help optimize D solution to phone encoding problem: extremely slow performace.

2024-01-16 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Jan 16, 2024 at 07:50:35AM -0800, H. S. Teoh via Digitalmars-d-learn wrote: [...] > Unfortunately there seems to be some discrepancy between the output I > got and the prescribed output in your repository. For example, in your > output the number 1556/0 does not have an

Re: Help optimize D solution to phone encoding problem: extremely slow performace.

2024-01-16 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Jan 15, 2024 at 08:10:55PM +, Renato via Digitalmars-d-learn wrote: > On Monday, 15 January 2024 at 01:10:14 UTC, Sergey wrote: > > On Sunday, 14 January 2024 at 17:11:27 UTC, Renato wrote: > > > If anyone can find any flaw in my methodology or optmise my code so > > > that it can

Re: `static` function ... cannot access variable in frame of ...

2024-01-15 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Jan 15, 2024 at 06:16:44PM +, Bastiaan Veelo via Digitalmars-d-learn wrote: > Hey people, I can use some help understanding why the last line > produces a compile error. > > ```d > import std.stdio; > > struct S > { > static void foo(alias len)() [...] The trouble is with the

Re: Doubt about Struct and members

2024-01-08 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Jan 08, 2024 at 05:28:50PM +, matheus via Digitalmars-d-learn wrote: > Hi, > > I was doing some tests and this code: > > import std; > > struct S{ > string[] s = ["ABC"]; > int i = 123; > } [...] It's not recommended to use initializers to initialize mutable array-valued

Re: LDC 1.36.0

2024-01-06 Thread H. S. Teoh via Digitalmars-d-announce
On Sat, Jan 06, 2024 at 06:03:54PM +, kinke via Digitalmars-d-announce wrote: > Glad to announce LDC 1.36.0. Major changes: > > * Based on D 2.106.1. > * Support for LLVM 17; the prebuilt packages use v17.0.6. > * New GDC-compatible CLI options `-fno-{exceptions,moduleinfo,rtti}` to >

Re: Trying to understand map being a template

2024-01-05 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Jan 05, 2024 at 08:41:53PM +, Noé Falzon via Digitalmars-d-learn wrote: > On the subject of `map` taking the function as template parameter, I > was surprised to see it could still be used with functions determined > at runtime, even closures, etc. I am trying to understand the >

Re: Pick a class at random

2024-01-03 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Jan 03, 2024 at 04:50:57PM +, axricard via Digitalmars-d-learn wrote: > I have an interface that is implemented by many classes, and I want to > pick one of these implementations at random. There are two more > constraints : first the distribution is not uniform, all classes can >

Re: D is nice whats really wrong with gc??

2023-12-22 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Dec 22, 2023 at 09:40:03PM +, bomat via Digitalmars-d-learn wrote: > On Friday, 22 December 2023 at 16:51:11 UTC, bachmeier wrote: > > Given how fast computers are today, the folks that focus on memory > > and optimizing for performance might want to apply for jobs as > > flooring

Re: D is nice whats really wrong with gc??

2023-12-22 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Dec 22, 2023 at 07:22:15PM +, Dmitry Ponyatov via Digitalmars-d-learn wrote: > > It's called GC phobia, a knee-jerk reaction malady common among > > C/C++ programmers > > I'd like to use D in hard realtime apps (gaming can be thought as one > of them, but I mostly mean realtime

Re: D is nice whats really wrong with gc??

2023-12-18 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Dec 18, 2023 at 04:44:11PM +, Bkoie via Digitalmars-d-learn wrote: [...] > but what is with these ppl and the gc? [...] It's called GC phobia, a knee-jerk reaction malady common among C/C++ programmers (I'm one of them, though I got cured of GC phobia thanks to D :-P). 95% of the

Re: Is it possible to set/override the name of the source file when piping it into DMD via stdin?

2023-12-13 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Dec 13, 2023 at 11:58:42AM -0800, H. S. Teoh via Digitalmars-d-learn wrote: [...] > Add a module declaration to your source file. For example: > > echo 'module abc; import std; void main(){writefln(__MODULE__);}' | dmd > -run - > > Output: > abc &

Re: Is it possible to set/override the name of the source file when piping it into DMD via stdin?

2023-12-13 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Dec 13, 2023 at 07:37:09PM +, Siarhei Siamashka via Digitalmars-d-learn wrote: > Example: > > ```D > import std; > void main() { > deliberate syntax error here > } > ``` > > ```bash > $ cat example.d | dmd -run - > __stdin.d(3): Error: found `error` when expecting `;` or `=`, did

Re: union default initialization values

2023-12-05 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Dec 06, 2023 at 04:24:51AM +0900, confuzzled via Digitalmars-d-learn wrote: [...] > import std.stdio; > void main() > { > F fp; > fp.lo.writeln; // Why is this not zero? How is this value derived? > fp.hi.writeln; // expected > fp.x.writeln; // expected > > fp.x = >

Re: anonymous structs within structs

2023-12-04 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Dec 04, 2023 at 11:46:45PM +, DLearner via Digitalmars-d-learn wrote: [...] > Basically, B corresponds to the whole record (and only a whole record > can be read). > But the task only requires Var1 and Var2, the last two fields on the record. > By putting all the irrelevant fields

Re: Release D 2.106.0

2023-12-04 Thread H. S. Teoh via Digitalmars-d-announce
On Sat, Dec 02, 2023 at 06:09:11PM +, Iain Buclaw via Digitalmars-d-announce wrote: > Glad to announce D 2.106.0, ♥ to the 33 contributors. > > This release comes with... > > - In the D language, it is now possible to statically initialize AAs. [...] Finally! Hooray! T -- That's not a

Re: D: Declaring empty pointer variables that return address inside function calls?

2023-11-23 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Nov 23, 2023 at 07:22:22PM +, BoQsc via Digitalmars-d-learn wrote: > Is it possible to declare empty pointer variable inside function calls > and pass its address to the function? > > These are sometimes required while using Win32 - Windows Operating > System API. > > * Empty pointer

Re: New DUB documentation

2023-11-22 Thread H. S. Teoh via Digitalmars-d-announce
On Wed, Nov 22, 2023 at 09:58:51PM +, Vladimir Marchevsky via Digitalmars-d-announce wrote: > On Wednesday, 22 November 2023 at 21:52:12 UTC, claptrap wrote: > > A single table of contents type menu would be better IMO, a left > > sidebar that gives links to all the pages. > > Wouldn't it be

Re: Keyword "package" prevents from importing a package module "package.d"

2023-11-02 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Nov 03, 2023 at 12:19:48AM +, Andrey Zherikov via Digitalmars-d-learn wrote: > On Thursday, 2 November 2023 at 19:43:01 UTC, Adam D Ruppe wrote: > > On Thursday, 2 November 2023 at 19:30:58 UTC, Jonathan M Davis wrote: > > > The entire reason that it was added to the language was to

Re: LDC 1.35.0

2023-10-16 Thread H. S. Teoh via Digitalmars-d-announce
On Sun, Oct 15, 2023 at 01:37:30PM +, kinke via Digitalmars-d-announce wrote: > Glad to announce LDC 1.35.0. Major changes: > > * Based on D 2.105.2+. > * A few important ImportC fixes. > * Fix GC2Stack optimization regression introduced in v1.24. > > Full release log and downloads: >

Re: is the array literal in a loop stack or heap allocated?

2023-10-10 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Oct 11, 2023 at 02:54:53AM +, mw via Digitalmars-d-learn wrote: > Hi, > > I want to confirm: in the following loop, is the array literal `a` vs. > `b` stack or heap allocated? and how many times? > > void main() { > > int[2] a; This is stack-allocated. Once per call to the

Re: array setting : Whats going in here?

2023-10-06 Thread H. S. Teoh via Digitalmars-d-learn
On Sat, Oct 07, 2023 at 12:00:48AM +, claptrap via Digitalmars-d-learn wrote: > > char[] foo; > foo.length = 4; > foo[] = 'a'; // ok sets all elements > foo[] = "a"; // range error at runtime? > foo[] = "ab"; // range error at runtime? > > So I meant to init with a char literal but

Re: Setting struct as default parameter of a function using struct literal?

2023-09-11 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Sep 11, 2023 at 10:39:00PM +, Salih Dincer via Digitalmars-d-learn wrote: > On Monday, 11 September 2023 at 22:13:25 UTC, H. S. Teoh wrote: > > > > Because sometimes I want a specific type. > > > > it's possible... > > ```d > alias ST = Options; > void specificType(ST option =

Re: Setting struct as default parameter of a function using struct literal?

2023-09-11 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Sep 11, 2023 at 10:05:11PM +, Salih Dincer via Digitalmars-d-learn wrote: > On Monday, 11 September 2023 at 20:17:09 UTC, H. S. Teoh wrote: > > > > Someone should seriously come up with a way of eliminating the > > repeated type name in default parameters. > > Why not allow it to be

Re: Setting struct as default parameter of a function using struct literal?

2023-09-11 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Sep 11, 2023 at 07:59:37PM +, ryuukk_ via Digitalmars-d-learn wrote: [...] > Recent version of D added named arguments so you can do something > like: > > ```D > void someFunction(Options option = Options(silenceErrors: false)) > ``` > > I don't like the useless repeating "option

Re: malloc error when trying to assign the returned pointer to a struct field

2023-09-09 Thread H. S. Teoh via Digitalmars-d-learn
On Sat, Sep 09, 2023 at 09:21:32AM +, rempas via Digitalmars-d-learn wrote: > On Saturday, 9 September 2023 at 08:54:14 UTC, Brad Roberts wrote: > > I'm pretty sure this is your problem. You're allocating size bytes > > which is only going to work where sizeof(T) == 1. Changing to > >

Re: malloc error when trying to assign the returned pointer to a struct field

2023-09-08 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Sep 08, 2023 at 06:59:21PM +, rempas via Digitalmars-d-learn wrote: > On Friday, 8 September 2023 at 16:02:36 UTC, Basile B. wrote: > > > > Could this be a problem of copy construction ? > > I don't think so. The assertion seems to be violated when `malloc` is used. > And when I

Re: Keeping data from memory mapped files

2023-09-01 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Sep 01, 2023 at 03:53:42AM +, Alexibu via Digitalmars-d-learn wrote: > Why do I need to copy data out of memory mapped files to avoid seg faults. > This defeats the purpose of memory mapped files. > Shouldn't the GC be able to manage it if I keep a pointer into it. The GC does not

Re: Unicode in strings

2023-07-27 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Jul 27, 2023 at 10:15:47PM +, Cecil Ward via Digitalmars-d-learn wrote: > How do I get a wstring or dstring with a code point of 0xA0 in it ? > That’s a type of space, is it? I keep getting a message from the LDC > compiler something like "Outside Unicode code space" in my unittests >

Re: Pre-expanding alloc cell(s) / reserving space for an associative array

2023-07-10 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Jul 10, 2023 at 09:30:57AM +, IchorDev via Digitalmars-d-learn wrote: [...] > From the spec it sounds as though (but good luck testing for sure) > that if you have (for example) 6 big dummy key-value pairs in the AA > to begin with, then if you use `.clear` it "Removes all remaining

Re: Dynamic array of strings and appending a zero length array

2023-07-08 Thread H. S. Teoh via Digitalmars-d-learn
On Sat, Jul 08, 2023 at 05:15:26PM +, Cecil Ward via Digitalmars-d-learn wrote: > I have a dynamic array of dstrings and I’m spending dstrings to it. At > one point I need to append a zero-length string just to increase the > length of the array by one but I can’t have a slot containing

Re: Bug in usage of associative array: dynamic array with string as a key

2023-06-30 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Jun 30, 2023 at 07:05:23PM +, Cecil Ward via Digitalmars-d-learn wrote: [...] It would help if you could post the complete code that reproduces the problem. Or, if you do not wish to reveal your code, reduce it to a minimal case that still exhibits the same problem, so that we can

Re: Debugging by old fashioned trace log printfs / writefln

2023-06-30 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Jun 30, 2023 at 03:43:14PM +, Cecil Ward via Digitalmars-d-learn wrote: [...] > Since I can pass my main function some compile-time-defined input, the > whole program should be capable of being executed with CTFE, no? So in > that case pragma( msg ) should suffice for a test

Re: is Dlang support Uniform initialization like c++

2023-06-30 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Jun 30, 2023 at 03:18:41PM +, lili via Digitalmars-d-learn wrote: > struct Point { > int x; > int y; > this(int x, int y) { this.x =x; this.y=y;} > } > > void addPoint(Point a, Point b) { >... > } > > How too wirte this: addPoint({4,5}, {4,6})

Re: static if - unexpected results

2023-06-23 Thread H. S. Teoh via Digitalmars-d-learn
On Friday, 23 June 2023 at 15:22:36 UTC, DLearner wrote: On Friday, 23 June 2023 at 14:31:45 UTC, FeepingCreature wrote: On Friday, 23 June 2023 at 14:22:24 UTC, DLearner wrote: [...] ``` static assert(__traits(isPOD, int)); // ok. static assert(__traits(isPOD, byte)); // ok. ``` It's a bug

Re: A couple of questions about arrays and slices

2023-06-21 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Jun 21, 2023 at 02:09:26AM +, Cecil Ward via Digitalmars-d-learn wrote: > First is an easy one: > > 1.) I have a large array and a sub-slice which I want to set up to be > pointing into a sub-range of it. What do I write if I know the start > and end indices ? Concerned about an

Re: How does D’s ‘import’ work?

2023-06-18 Thread H. S. Teoh via Digitalmars-d-learn
On Sun, Jun 18, 2023 at 03:51:14PM -0600, Jonathan M Davis via Digitalmars-d-learn wrote: > On Sunday, June 18, 2023 2:24:10 PM MDT Cecil Ward via Digitalmars-d-learn > wrote: > > I wasn’t intending to use DMD, rather ldc if possible or GDC > > because of their excellent optimisation, in which

Re: ldc link error on new machine: undefined reference to `_D6object9Throwable7messageMxFNbNfZAxa'

2023-06-14 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Jun 15, 2023 at 12:49:30AM +, mw via Digitalmars-d-learn wrote: > Hi, > > I switched to a different machine to build my project, suddenly I got > lots of link errors. (It builds fine on the old machine, and my > software version are the same on both machines LDC - the LLVM D >

Re: byte and short data types use cases

2023-06-10 Thread H. S. Teoh via Digitalmars-d-learn
On Sat, Jun 10, 2023 at 09:58:12PM +, Cecil Ward via Digitalmars-d-learn wrote: > On Friday, 9 June 2023 at 15:07:54 UTC, Murloc wrote: [...] > > So you can optimize memory usage by using arrays of things smaller > > than `int` if these are enough for your purposes, but what about > > using

Re: byte and short data types use cases

2023-06-09 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Jun 09, 2023 at 11:24:38AM +, Murloc via Digitalmars-d-learn wrote: [...] > Which raised another question: since objects of types smaller than > `int` are promoted to `int` to use integer arithmetic on them anyway, > is there any point in using anything of integer type less than `int`

Re: How does D’s ‘import’ work?

2023-05-31 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, May 31, 2023 at 06:43:52PM +, Cecil Ward via Digitalmars-d-learn wrote: > Is there an explanation of how D’s ‘import’ works somewhere? I’m > trying to understand the comparison with the inclusion of .h files, > similarities if any and differences with the process. Unlike C's

Re: How get struct value by member name string ?

2023-05-29 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, May 30, 2023 at 01:24:46AM +, John Xu via Digitalmars-d-learn wrote: > On Monday, 29 May 2023 at 11:21:11 UTC, Adam D Ruppe wrote: > > On Monday, 29 May 2023 at 09:35:11 UTC, John Xu wrote: > > > Error: variable `column` cannot be read at compile time > > > > you should generally

Re: Concepts like c++20 with specialized overload resolution.

2023-05-27 Thread H. S. Teoh via Digitalmars-d-learn
On Sat, May 27, 2023 at 05:49:27PM +, vushu via Digitalmars-d-learn wrote: > On Saturday, 27 May 2023 at 16:38:43 UTC, Steven Schveighoffer wrote: [...] > > void make_lava(T)(ref T lava) if (hasMagma!T) { > > lava.magma(); > > } > > > > void make_lava(T)(ref T lava_thing) if

Re: Proper way to handle "alias this" deprecation for classes

2023-05-10 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, May 10, 2023 at 10:57:13PM +, Chris Piker via Digitalmars-d-learn wrote: > On Wednesday, 10 May 2023 at 20:25:48 UTC, H. S. Teoh wrote: > > On Wed, May 10, 2023 at 07:56:10PM +, Chris Piker via > > Digitalmars-d-learn wrote: [...] > > I also suffer from left/right confusion, and

Re: Proper way to handle "alias this" deprecation for classes

2023-05-10 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, May 10, 2023 at 07:56:10PM +, Chris Piker via Digitalmars-d-learn wrote: [...] > My problem with the terms lvalue and rvalue is much more basic, and is > just a personal one that only affects probably 0.1% of people. I just > can't keep left vs. right straight in real life. "Right"

Re: Proper way to handle "alias this" deprecation for classes

2023-05-10 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, May 10, 2023 at 03:24:48PM +, Chris Piker via Digitalmars-d-learn wrote: [...] > It's off topic, but I forget why managing memory for rvalues* was > pushed onto the programmer and not handled by the compiler. I'm sure > there is a good reason but it does seem like a symmetry breaking

Re: quick question, probably of little importance...

2023-04-26 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Apr 26, 2023 at 11:07:39PM +, WhatMeWorry via Digitalmars-d-learn wrote: > On Wednesday, 26 April 2023 at 23:02:07 UTC, Richard (Rikki) Andrew > Cattermole wrote: > > Don't forget ``num % 2 == 0``. > > > > None should matter, pretty much all production compilers within the > > last

Re: D style - member functions

2023-04-26 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Apr 26, 2023 at 06:24:08PM +, DLearner via Digitalmars-d-learn wrote: > Consider: > ``` > struct S1 { >int A; >int B; >int foo() { > return(A+B); >} > } > > struct S2 { >int A; >int B; > } > int fnAddS2(S2 X) { >return (X.A + X.B); > } > > void

Re: How can a function pointer required to be extern(C)?

2023-04-12 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Apr 12, 2023 at 08:23:51PM +, rempas via Digitalmars-d-learn wrote: > Sorry if the title doesn't make any sense, let me explain. So, I do have the > following code that does not compile: > > ```d > import core.sys.posix.pthread; /* The library */ > > struct Thread { > private: >

Re: foreach (i; taskPool.parallel(0..2_000_000)

2023-04-05 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Apr 06, 2023 at 01:20:28AM +, Paul via Digitalmars-d-learn wrote: [...] > Yes I understand, basically, what's going on in hardware. I just > wasn't sure if the access type was linked to the container type. It > seems obvious now, since you've both made it clear, that it also >

Re: foreach (i; taskPool.parallel(0..2_000_000)

2023-04-05 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Apr 05, 2023 at 10:34:22PM +, Paul via Digitalmars-d-learn wrote: > On Tuesday, 4 April 2023 at 22:20:52 UTC, H. S. Teoh wrote: > > > Best practices for arrays in hot loops: [...] > > - Where possible, prefer sequential access over random access (take > > advantage of the CPU cache

Re: foreach (i; taskPool.parallel(0..2_000_000)

2023-04-04 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Apr 04, 2023 at 09:35:29PM +, Paul via Digitalmars-d-learn wrote: [...] > Well Steven just making the change you said reduced the execution time > from ~6-7 secs to ~3 secs. Then, including the 'parallel' in the > foreach statement took it down to ~1 sec. > > Boy lesson learned in

Re: better video rendering in d

2023-03-21 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Mar 21, 2023 at 05:29:22PM +, monkyyy via Digitalmars-d-learn wrote: > On Tuesday, 21 March 2023 at 17:18:15 UTC, H. S. Teoh wrote: > > On Tue, Mar 21, 2023 at 04:57:49PM +, monkyyy via > > Digitalmars-d-learn wrote: > > > My current method of making videos of using raylib to

Re: better video rendering in d

2023-03-21 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Mar 21, 2023 at 04:57:49PM +, monkyyy via Digitalmars-d-learn wrote: > My current method of making videos of using raylib to generate screenshots, > throwing those screenshots into a folder and calling a magic ffmpeg command > is ... slow. [...] How slow is it now, and how fast do you

Re: LDC 1.32.0

2023-03-12 Thread H. S. Teoh via Digitalmars-d-announce
On Sun, Mar 12, 2023 at 04:11:21PM +, kinke via Digitalmars-d-announce wrote: > Glad to announce LDC 1.32.0. Major changes: [...] Awesome! Big thanks to all the LDC contributors for their hard work to bring us this awesome compiler. T -- A bend in the road is not the end of the road

Re: @nogc and Phobos

2023-03-11 Thread H. S. Teoh via Digitalmars-d-learn
On Sat, Mar 11, 2023 at 04:21:40PM +, bomat via Digitalmars-d-learn wrote: [...] > Although I come from a C++ background, I'm not exactly a fanboy of > that language (you can probably tell, otherwise I wouldn't be here). > But after hearing praise for D for being a cleaner and better version >

Re: Bug in DMD?

2023-03-02 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Mar 02, 2023 at 09:55:55PM +, ryuukk_ via Digitalmars-d-learn wrote: > On Thursday, 2 March 2023 at 21:38:23 UTC, ryuukk_ wrote: > > On Thursday, 2 March 2023 at 21:21:14 UTC, Richard (Rikki) Andrew > > Cattermole wrote: [...] > > > 2. Dustmite, so we have something we can work with. >

Re: Transform static immutable string array to tuple.

2023-02-19 Thread H. S. Teoh via Digitalmars-d-learn
On Sun, Feb 19, 2023 at 11:08:34AM +, realhet via Digitalmars-d-learn wrote: > Hello, > > Is there a better way to transform a string array to a tuple or to an > AliasSeq? > > ``` > mixin(customSyntaxPrefixes.format!`tuple(%(%s,%))`) > ``` > > I'd like to use this as variable length

Re: Deciding one member of iteration chain at runtime

2023-02-17 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Feb 17, 2023 at 05:30:40PM +, Chris Piker via Digitalmars-d-learn wrote: [...] > In order to handle new functionality it turns out that operatorG needs > to be of one of two different types at runtime. How would I do > something like the following: > > ```d > auto virtualG; // <--

Re: Non-ugly ways to implement a 'static' class or namespace?

2023-02-16 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Feb 16, 2023 at 08:51:39AM +, FeepingCreature via Digitalmars-d-learn wrote: [...] > Springboarding off this post: > > This thread is vastly dominated by some people who care very much > about this issue. Comparatively, for instance, I care very little > because I think D already

Re: Simplest way to convert an array into a set

2023-02-13 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Feb 13, 2023 at 06:04:40PM +, Matt via Digitalmars-d-learn wrote: > Obviously, there is no "set" object in D, Actually, bool[T] could be used as a set object of sorts. Or even void[0][T], though that's a little more verbose to type. But this can be aliased to something nicer (see

Re: Hipreme Engine is fully ported to WebAssembly

2023-02-07 Thread H. S. Teoh via Digitalmars-d-announce
On Fri, Feb 03, 2023 at 01:41:35PM +, Hipreme via Digitalmars-d-announce wrote: > This has been finished for quite a time but I was polishing some features. > > I'll save this post to 4 things: > > **Advertise that [Hipreme Engine](https://github.com/MrcSnm/HipremeEngine) > is now

Re: betterC DLL in Windows

2023-02-06 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Feb 06, 2023 at 03:54:40PM +, bachmeier via Digitalmars-d-learn wrote: > On Sunday, 5 February 2023 at 08:48:34 UTC, Tamas wrote: [...] > > This is the specification for the D Programming Language. > > I've been bitten by that a few times over the years, though to be > honest, I'm

  1   2   3   4   5   6   7   8   9   10   >