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-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: Class-Inheritancing Error

2025-07-28 Thread H. S. Teoh via Digitalmars-d-learn
On Sun, Jul 27, 2025 at 05:02:35PM +, user1234 via Digitalmars-d-learn wrote: [...] > Simply because because if OP writes > > ``` > class Person{ > string name; > this(string name){this.name=name;} > } > class Someone:Person{ > } > void main(){ > Someone x=new Someone("Bob"); > }

Re: Class-Inheritancing Error

2025-07-27 Thread H. S. Teoh via Digitalmars-d-learn
On Sun, Jul 27, 2025 at 11:08:33AM +, David T. Oxygen via Digitalmars-d-learn wrote: > I wrote a piece of code like this: > > ```d > class Person{ > string name; > this(string name){this.name=name;} > } > class Someone:Person{ > alias super this; > } > void main(){ > S

Re: std.random.uniform(1, 101) crashes. Why, and workaround.

2025-07-24 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Jul 25, 2025 at 01:04:31AM +, Brother Bill via Digitalmars-d-learn wrote: > From "Programming in D" book: > > import std.stdio; > import std.random; > > void main() { > int number = uniform(1, 101); > > writeln("Edit source/app.d to start your project."); > } >

Re: Inherited constructor

2025-07-24 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Jul 24, 2025 at 05:19:17PM +, Andy Valencia via Digitalmars-d-learn wrote: > What is considered the "clean" way to address this error: > > ``` > tst60.d(7): Error: class `tst60.B` cannot implicitly generate a > default constructor when base class `tst60.A` is missing a default > const

Re: void[] vs ubyte[] - differences?

2025-07-16 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Jul 16, 2025 at 01:29:01PM +, z via Digitalmars-d-learn wrote: [...] > I also see this in the language documentation : > ``` > A void array cannot be indexed. > ``` > But i can slice it just fine in DMD 2.111... Probably an oversight. > Is this by design or is there a hole in the lan

Re: Is there some kind of Blocking Queue for D?

2025-07-13 Thread H. S. Teoh via Digitalmars-d-learn
On Sat, Jul 12, 2025 at 06:35:42PM -0600, Jonathan M Davis via Digitalmars-d-learn wrote: > On Saturday, July 12, 2025 5:55:39 PM Mountain Daylight Time Ali Çehreli via > Digitalmars-d-learn wrote: [...] > > Meanwhile, engineers like you suffer because of 'private'. I pick > > engineering over 'p

Re: basic pointer question

2025-07-11 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Jul 11, 2025 at 10:17:02PM +, WhatMeWorry via Digitalmars-d-learn wrote: > ``` > // working function > > SDL_Texture* changeTextureAccess(SDL_Texture *texture, SDL_TextureAccess > newAccess) > { > // pertinent code only > texture = createTexture(renderer, pixelFormat, newAcces

Re: CTFE and return statement from delegate

2025-06-30 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Jun 30, 2025 at 04:51:27AM +, Rajesh via Digitalmars-d-learn wrote: [...] > ``` > Error: variable `__capture` cannot be read at compile time > onlineapp.d(27):called from here: `Problem(0).this(1)` > auto compile_time_var = Problem(1); > ``` [...] This article may help clear up

Re: Multiply a string?

2025-06-21 Thread H. S. Teoh via Digitalmars-d-learn
On Sat, Jun 21, 2025 at 04:18:37PM +, Neto via Digitalmars-d-learn wrote: > On Saturday, 7 June 2025 at 16:42:51 UTC, Sergey wrote: [...] > > ```d > > void main() { > > string error_message = "D's desing is far from perfect"; > > writeln(" ".repeat(5).join, "[INFO]:", Clock.currTime(),

Re: InputRange for data structure without order?

2025-06-04 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Jun 04, 2025 at 12:00:57PM -0700, Ali Çehreli via Digitalmars-d-learn wrote: > On 6/4/25 4:10 AM, Monkyyy wrote: > > On Wednesday, 4 June 2025 at 02:11:18 UTC, H. S. Teoh wrote: > >> . But in general, containers should NOT be conflated with ranges. > >> That

Re: InputRange for data structure without order?

2025-06-03 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Jun 03, 2025 at 11:54:20PM +, Andy Valencia via Digitalmars-d-learn wrote: > On Tuesday, 3 June 2025 at 20:51:05 UTC, Ali Çehreli wrote: > > front() does not imply an order. It will work as long as you can > > provide the elements in a sequence. The built-in associative array > > featu

Re: Sanity check: pithiest test for static if: "is an array of ubyte"

2025-05-24 Thread H. S. Teoh via Digitalmars-d-learn
On Sat, May 24, 2025 at 08:29:52PM +, Andy Valencia via Digitalmars-d-learn wrote: > The best I"ve come up with for a "static if" to see if something's an > array of ubyte: > > ```d > (isArray!(typeof(arg))) && is(typeof(arg).init[0] == ubyte) > ``` That's totally overkill. Just do this:

Re: What the heck am i doing wrong? I'm just trying to create a 8 bit unsigned variable.

2025-05-21 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, May 21, 2025 at 05:47:20PM +, WhatMeWorry via Digitalmars-d-learn wrote: > On Friday, 16 May 2025 at 19:04:24 UTC, WhatMeWorry wrote: > > /+ SDL3 has a function > > bool SDL_SetTextureAlphaMod(SDL_Texture *texture, Uint8 alpha); > > which has a Uint8 for one of its parameters. So I tr

Re: What the heck am i doing wrong? I'm just trying to create a 8 bit unsigned variable.

2025-05-18 Thread H. S. Teoh via Digitalmars-d-learn
On Sat, May 17, 2025 at 07:09:40AM -0600, Jonathan M Davis via Digitalmars-d-learn wrote: [...] > Given that Java and C# disallow narrowing conversions, I expect that > they have similar restrictions, but I haven't done much with either of > them any time recently, so I'm not sure what they do wit

Re: What the heck am i doing wrong? I'm just trying to create a 8 bit unsigned variable.

2025-05-16 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, May 16, 2025 at 07:04:24PM +, WhatMeWorry via Digitalmars-d-learn wrote: [...] > void main() > { > ubyte a; > a = a + 5; // onlineapp.d(11): Error: cannot implicitly convert > expression `cast(int)a + 5` of type `int` to `ubyte` [...] Welcome to your first encounter with why

Re: Create module-level function using mixin template?

2025-04-25 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Apr 25, 2025 at 05:24:18PM +, Andy Valencia via Digitalmars-d-learn wrote: > On Friday, 25 April 2025 at 16:59:16 UTC, monkyyy wrote: > > its extremely unclear what your trying to do my best geuss: > > I want to use a mixin template to generate a top-level function. Your best bet act

Re: Is there anyway to Deify the following code snippet?

2025-04-16 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Apr 16, 2025 at 04:23:43AM +, Andy Valencia via Digitalmars-d-learn wrote: > On Wednesday, 16 April 2025 at 01:44:33 UTC, Paul Backus wrote: > > Nope, you're not missing anything. Using pointers is totally normal > > and idiomatic in D. > > That said, I try to code under @safe when I

Re: Is there an elegant way to non-destructively step through a red black tree?

2025-03-20 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Mar 20, 2025 at 11:51:46PM +, WhatMeWorry via Digitalmars-d-learn wrote: > Is there an elegant way, like with foreach, to step through a red black > tree non-destructively? This destructive failure is the best I've been able > to come up with. > > while(!rbt.empty) > { >

Re: simple question about UFCS and templates...wasFound(i) works but not i.wasFound()

2025-03-19 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Mar 19, 2025 at 10:26:54PM +, WhatMeWorry via Digitalmars-d-learn wrote: [...] > The above compiles and executes successfully. But the following fails > with: app.d(179,13): Error: no property `wasFound` for `i` of type > `long` > > I thought the templated function would take care of

Re: simple question about UFCS and templates...wasFound(i) works but not i.wasFound()

2025-03-19 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Mar 19, 2025 at 11:21:15PM +, monkyyy via Digitalmars-d-learn wrote: [...] > ufcs on local functions is hit or miss; [...] I thought it was always a miss. :-D At least, it's never worked for me every time I tried it. I always have to move the UFCS function to module scope, then it wo

Re: std.conv:to that does not throw?

2025-01-29 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Jan 29, 2025 at 07:08:49PM -0700, Jonathan M Davis via Digitalmars-d-learn wrote: > On Wednesday, January 29, 2025 6:38:07 PM MST Kyle Ingraham via > Digitalmars-d-learn wrote: > > Does D have a 'try' `std.conv:to` that does not throw if it fails? > > Something like: > > ```D > > string i

Re: Super easy struct construction question that I'm embarrassed to ask.

2025-01-12 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Jan 13, 2025 at 04:05:25AM +, Jim Balter via Digitalmars-d-learn wrote: > On Thursday, 9 January 2025 at 22:08:31 UTC, Dennis wrote: > > On Thursday, 9 January 2025 at 22:01:59 UTC, WhatMeWorry wrote: > > > this(Location locaction, uint f) { > > > this.location = location;

Re: How to collect "some" items of a range in an array?

2025-01-06 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Jan 06, 2025 at 07:30:27PM +, Renato via Digitalmars-d-learn wrote: > Is there any Phobos function that collects "some" items of a range > into an array/slice? > It's kind of embarrassing that I've been trying to find this for hours > now without success :(. [...] > My use case is to pa

Re: Kotlin Meta and CT programming vs D

2024-12-21 Thread H. S. Teoh via Digitalmars-d-learn
On Sat, Dec 21, 2024 at 07:06:12PM +, Jo Blow via Digitalmars-d-learn wrote: [...] > There really should be some push to get D integrated into some major > platform. Maybe D could be the "JNI language" for the Android > platform? This is the difference between a corporate-backed and funded pro

Re: Kotlin Meta and CT programming vs D

2024-12-19 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Dec 19, 2024 at 06:04:33AM +, Jo Blow via Digitalmars-d-learn wrote: [...] > I'm wondering if it would be worth the effort to try to get D to work > with android studio since it can compile to all those. E.g., write the > jetpack compose code in kotlin and hook up the business in with D

Re: unittest behaviour

2024-12-17 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Dec 17, 2024 at 07:16:55PM +, DLearner via Digitalmars-d-learn wrote: [...] > What is wrong with changing the specification of unittest so that it > recompiles/reexecutes the associated source on every unittest {} > block? That means the compiler will have to rerun your program once p

Re: Interpolated strings?

2024-12-16 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Dec 16, 2024 at 08:33:27PM +, Andy Valencia via Digitalmars-d-learn wrote: > I have a string full of JavaScript to serve up, and a couple variable > values need to be interpolated into it. I read that dlang now has > interpolated strings under i"...", so yay! A bit of example code to

Re: unittest behaviour

2024-12-15 Thread H. S. Teoh via Digitalmars-d-learn
On Sun, Dec 15, 2024 at 08:45:22AM +, DLearner via Digitalmars-d-learn wrote: [...] > I appreciate this behaviour matches the docs (so not a bug), but is it > desirable? > > To me, as a test harness, a umittest block should be a completely > fresh-from-scratch invocation of the code inside th

Re: Writing your own runtime, runtime hooks, etc.

2024-12-12 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Dec 12, 2024 at 06:52:27AM +, GrimMaple via Digitalmars-d-learn wrote: > On Wednesday, 11 December 2024 at 18:16:24 UTC, solidstate1991 wrote: > > I'm thinking about writing, or well, rather modifying the existing > > default runtime of D, mainly by stripping out the GC and moving > >

Re: Proper way to raise awareness of a bug

2024-10-29 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Oct 29, 2024 at 04:59:48PM +, Chris Piker via Digitalmars-d-learn wrote: > Hi D > > There is a bug listed in the Bugzilla tracking tool that affected me > the other day, > [15526](https://issues.dlang.org/show_bug.cgi?id=15526). It's not a > big problem, just an unexpected issue and

Re: std.algorithm.countUntil and alias

2024-10-23 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Oct 23, 2024 at 06:10:07PM +, Anton Pastukhov via Digitalmars-d-learn wrote: > On Wednesday, 23 October 2024 at 18:05:15 UTC, monkyyy wrote: > > > > Its intended and probably the right decision, but good luck finding > > relivent docs. > > What's the motivation behind it? For me, it

Re: Templates considered impressive

2024-10-01 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Oct 01, 2024 at 04:30:27PM +, Salih Dincer via Digitalmars-d-learn wrote: [...] > > ``` > Please add this to your MyCon structure: > ```d > alias value this; > // assert(num1 == 3.14); > ``` > And test it like this too, I think it's awesome! [...] IMO it's not a good idea to recommend

Re: Templates considered impressive

2024-10-01 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Oct 01, 2024 at 01:00:08AM +, Andy Valencia via Digitalmars-d-learn wrote: > I had an old atoi() I wrote when I was getting started with D. You know, > fixed type, string in, int output. Today for fun I templated the type: > > T atoi(T)(string s) [...] It's all good and fun to try

Re: Best practices for class instance variables as parameters

2024-09-28 Thread H. S. Teoh via Digitalmars-d-learn
On Sat, Sep 28, 2024 at 06:16:55PM +, Ian via Digitalmars-d-learn wrote: > Hi, > > I'm coming from C and some C++ so the way D stores class instance > variables is new to me. If I'm not mistaken the basic unadorned > instance variable is like a "hidden" pointer. So, when passing class > instan

Re: Integer precision of function return types

2024-09-27 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Sep 27, 2024 at 04:13:45PM -0400, thinkunix via Digitalmars-d-learn wrote: [...] > I've seen a lot of "use auto everywhere" especially in C++ and was > wondering where the D community stands on it's use. Is it generally > favored or not? > > Personally, I think auto makes understanding c

Re: Unexpected range assignment behaviour

2024-07-19 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Jul 19, 2024 at 05:48:37PM +, Dennis via Digitalmars-d-learn wrote: > On Friday, 19 July 2024 at 17:20:22 UTC, matheus wrote: > > couldn't this case for example be caught during the compiling time? > > The RangeError is only thrown when at runtime, the key doesn't exist, > so that can'

Re: Unexpected range assignment behaviour

2024-07-19 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Jul 19, 2024 at 09:34:13AM +, Lewis via Digitalmars-d-learn wrote: > ``` > string[3][string] lookup; > string[] dynArray = ["d", "e", "f"]; > lookup["test"] = dynArray[0..$]; > ``` > > This fails at runtime with RangeError. But if I change that last line to: > > ``` > lookup["test"] =

Re: Being reading a lot about betterC, but still have some questions

2024-07-09 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Jul 09, 2024 at 08:03:15PM +, kiboshimo via Digitalmars-d-learn wrote: > On Tuesday, 9 July 2024 at 14:42:01 UTC, monkyyy wrote: > > On Tuesday, 9 July 2024 at 07:54:12 UTC, kiboshimo wrote: [...] > > > Really liked the idea of doing it with betterC to start my systems > > > programmin

Re: Weird std.path API?

2024-07-07 Thread H. S. Teoh via Digitalmars-d-learn
On Sun, Jul 07, 2024 at 02:41:31PM +, Andrey Zherikov via Digitalmars-d-learn wrote: > Seems different functions in std.path do not work together: > ```d > import std.path; > > // Error: no property `asNormaliedPath` for > `dirName("/sandbox/onlineapp.d")` of type `string` > auto p = __FILE_F

Re: 12 line program... `main` is a nested function when trying to use redblacktree. Beginner error???

2024-06-27 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Jun 27, 2024 at 10:14:06PM +, WhatMeWorry via Digitalmars-d-learn wrote: > Thanks, that did the trick. Not sure why having the declarations at > global scope (or is it module scope in D) would work versus having > them at local scope? If you stuck 'static' to the local scope declarati

Re: 12 line program... `main` is a nested function when trying to use redblacktree. Beginner error???

2024-06-27 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Jun 27, 2024 at 08:56:13PM +, WhatMeWorry` via Digitalmars-d-learn wrote: > import std.container : RedBlackTree; > > int main() > { > > struct Location { > int x; > int y; > } > > struct Node{ > this(Location loc, uint f) { > this.loc

Re: Why is this happening to my software? An illegal instruction error.

2024-06-18 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Jun 18, 2024 at 11:07:47PM +, Murilo via Digitalmars-d-learn wrote: > I've created a software which performs the Fermat's Primality Test, > however if I input a very big number it causes an error saying > "Illegal instruction (core dumped)". Does anyone know why? > > I've used GDB and

Re: Unintentional sharing?

2024-06-06 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Jun 06, 2024 at 05:49:39PM +, Andy Valencia via Digitalmars-d-learn wrote: > I was using instance initialization which allocated a new object. My > intention was this initialization would happen per-instance, but all > instances appear to share the same sub-object? That is, f1.b and

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 t

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-a

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 commo

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, d

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 > https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference

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 pro

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 (this.cur

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

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; > >

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 > wants

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: 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 no

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

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

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 > > che

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 time

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 turni

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 exactl

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 associa

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 m

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 > ./rust,776601

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... > > > > T

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 fixe

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

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

2024-01-16 Thread H. S. Teoh via Digitalmars-d-learn
ent excluding many more matching possibilities, effectively pruning away large parts of the search tree. > @"H. S. Teoh" you implemented the solution as a Trie!! Nice, that's > also what I did when I "participated" in the study. Here's [my Trie > solut

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 s

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 enco

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 still

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 `s

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 mem

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 > mecha

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 > defi

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 inspe

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 dynami

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 time

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: >

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 y

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 into

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: 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 be

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 function.

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 accidentl

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 = Op

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. >

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 opti

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 > > malloc(

  1   2   3   4   5   6   7   8   9   10   >