Re: String front, back return code point/unit

2021-06-23 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Jun 23, 2021 at 04:01:24PM +, vit via Digitalmars-d-learn wrote: [...] > My question is not about ranges/iterators but if is good idea > autodecoding custom string or not. No. Autodecoding is one of the decisions we regret because it introduces an unavoidable overhead on basically

Re: semi-final switch?

2021-06-17 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Jun 17, 2021 at 05:41:28PM -0400, Steven Schveighoffer via Digitalmars-d-learn wrote: [.[..] > Oh, and to throw a monkey wrench in here, the value is a string, not > an integer. So I can't use std.conv.to to verify the enum is valid > (plus, then I'm running a switch twice). > > Any

Re: Arrays of variants, C++ vs D

2021-06-17 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Jun 17, 2021 at 07:44:31PM +, JN via Digitalmars-d-learn wrote: [...] > Foo[int] foos = [ > 0: Foo("abc"), > 1: Foo(5) > ]; > } > ``` > > Why does D need the explicit declarations whereas C++ can infer it? Because D does not support implicit construction. The

Re: Can not get struct member addresses at compile time

2021-06-16 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Jun 16, 2021 at 02:42:41PM -0700, Ali Çehreli via Digitalmars-d-learn wrote: [...] > Actually, it is news to me that the compiler can know (determine?) the > address of a global variable. [...] The compiler does not (and cannot) know. But the runtime dynamic linker can, and does. The

Re: Struct assignment fails, why?

2021-06-16 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Jun 16, 2021 at 08:44:46PM +, Brian via Digitalmars-d-learn wrote: [...] > struct item > { > string name; > int type; > }; [...] > new_item = { "item1", 1 }; The {...} initializer syntax is only available in variable declarations, e.g.: item i = { "item1",

Re: In general, who should do more work: popFront or front?

2021-06-15 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Jun 15, 2021 at 02:20:11PM +, Paul Backus via Digitalmars-d-learn wrote: [...] > It's a time-space tradeoff. As you say, caching requires additional > space to store the cached element. On the other hand, *not* caching > means that you spend unnecessary time computing the next element

Re: Inclusion of Parenthesis on Certain Functions

2021-06-13 Thread H. S. Teoh via Digitalmars-d-learn
On Sun, Jun 13, 2021 at 03:45:53PM +, Justin Choi via Digitalmars-d-learn wrote: > I'm currently learning D right now, and I was wondering why certain > functions like std.stdio.readln can work both with and without > parenthesis for the function call. I've tried looking through the >

Re: Unittests not firing?

2021-06-11 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Jun 11, 2021 at 02:05:31PM -0700, H. S. Teoh wrote: [...] > Huh, that doesn't look right. This was fixed since June last year, so it > *should* have made it into the latest compiler releases already. Unless > this one was missed somehow (but I doubt it). [...] Just checked on LDC 1.26.0,

Re: Unittests not firing?

2021-06-11 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Jun 11, 2021 at 08:30:28PM +, Mike Brown via Digitalmars-d-learn wrote: > On Friday, 11 June 2021 at 16:28:48 UTC, H. S. Teoh wrote: > > On Fri, Jun 11, 2021 at 03:20:49PM +, Mike Brown via > > Digitalmars-d-learn wrote: > > > On Friday, 11 June 2021 at 15:13:17 UTC, rikki

Re: Two interpretations

2021-06-11 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Jun 11, 2021 at 03:00:00PM +, JG via Digitalmars-d-learn wrote: > Is it specified somewhere which way the following program will be > interpreted? > > import std; > > struct A > { > int x=17; > } > > int x(A a) > { > return 100*a.x; > } >

Re: Unittests not firing?

2021-06-11 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Jun 11, 2021 at 03:20:49PM +, Mike Brown via Digitalmars-d-learn wrote: > On Friday, 11 June 2021 at 15:13:17 UTC, rikki cattermole wrote: [...] > Right OK, mine says 1/1 unittests failed - but this should say > Modules? > > I will interpret it as Modules, ty! This is a bug that was

Re: Faster Dlang Execution

2021-06-08 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Jun 08, 2021 at 05:10:47PM +, seany via Digitalmars-d-learn wrote: [...] > Profiling doesn't help, because different input is causing different > parts of the program to become slow. [...] Do you have any more specific information about what kind of inputs cause which parts of the

Re: how to enable safeD ? dmd.conf ? dmd switch ?

2021-06-07 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Jun 08, 2021 at 02:47:18AM +, someone via Digitalmars-d-learn wrote: > https://dlang.org/articles/safed.html > https://dlang.org/dmd-linux.html#switches > http://ddili.org/ders/d.en/functions_more.html > > Neither man dmd nor man dmd.conf appear to have a related/switch > setting. >

Re: is it possible to have a default property for any given class ?

2021-06-07 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Jun 07, 2021 at 03:26:27PM +, someone via Digitalmars-d-learn wrote: > Consider the following code: > > ```d > class classComputer { [...] > } > > class classComputers { > >classComputers lhs; >classComputers rhs; > >int opApply(int delegate(classComputers) dg) { ///

Re: regarding what seems (to me) unnecessary casts on integer expressions

2021-06-07 Thread H. S. Teoh via Digitalmars-d-learn
On Sat, Jun 05, 2021 at 01:46:45AM +, someone via Digitalmars-d-learn wrote: [...] > As I am writing code today I am encountering a lot of these situations. > > cast(ushort)(this.pintBottom1 - 1) > > My first walkaround for this was intuitive: > > this.pintBottom1 - cast(ushort) 1 /// I

Re: General rule when not to write ;

2021-05-19 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, May 19, 2021 at 05:53:12PM +, Alain De Vos via Digitalmars-d-learn wrote: > It seems I need }; for a function a delegate and an alias. > ``` > double function(int) F = function double(int x) {return x/10.0;}; > double delegate(int) D = delegate double(int x) {return c*x/10.0;}; >

Re: stack out of scope ?

2021-05-16 Thread H. S. Teoh via Digitalmars-d-learn
On Sun, May 16, 2021 at 06:33:04PM +, Alain De Vos via Digitalmars-d-learn wrote: > On Sunday, 16 May 2021 at 18:27:40 UTC, H. S. Teoh wrote: [...] > > -snip- > > import std.stdio:writeln; > > > > int [] fun() @safe {// N.B.: need @safe > >

Re: stack out of scope ?

2021-05-16 Thread H. S. Teoh via Digitalmars-d-learn
On Sun, May 16, 2021 at 05:24:40PM +, Alain De Vos via Digitalmars-d-learn wrote: > On Sunday, 16 May 2021 at 16:58:15 UTC, H. S. Teoh wrote: > > On Sun, May 16, 2021 at 04:40:53PM +, Alain De Vos via > > Digitalmars-d-learn wrote: > > > This works also, > > > > > > ``` > > > import

Re: stack out of scope ?

2021-05-16 Thread H. S. Teoh via Digitalmars-d-learn
On Sun, May 16, 2021 at 04:40:53PM +, Alain De Vos via Digitalmars-d-learn wrote: > This works also, > > ``` > import std.stdio:writeln; > > int [] fun(){ > int[3]s=[1,2,3]; > int[] r=s; > return r; > } > > void main(){ > writeln(fun()[0]); > } > ```

Re: ugly and/or useless features in the language.

2021-05-16 Thread H. S. Teoh via Digitalmars-d-learn
On Sat, May 15, 2021 at 02:31:08PM +, Alain De Vos via Digitalmars-d-learn wrote: > Which parts in dlang don't you use and why ? > > Personally i have no need for enum types, immutable is doing fine. > Auto return types i find dangerous to use. > Voldermont types. > Named initialiser. >

Re: Recommendations on avoiding range pipeline type hell

2021-05-16 Thread H. S. Teoh via Digitalmars-d-learn
On Sat, May 15, 2021 at 11:25:10AM +, Chris Piker via Digitalmars-d-learn wrote: [...] > Basically the issue is that if one attempts to make a range based > pipeline aka: > > ```d > auto mega_range = range1.range2!(lambda2).range3!(lambda3); > ``` > Then the type definition of mega_range is

Re: CTFE Assignment to anonymous union shows unexpected behavior

2021-04-22 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Apr 22, 2021 at 11:44:51PM +, Rekel via Digitalmars-d-learn wrote: > On Thursday, 22 April 2021 at 23:41:33 UTC, H. S. Teoh wrote: > > On Thu, Apr 22, 2021 at 10:47:17PM +, Rekel via Digitalmars-d-learn > > wrote: > > > I'm not sure why this is happening, but after simplifying my

Re: CTFE Assignment to anonymous union shows unexpected behavior

2021-04-22 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Apr 22, 2021 at 10:47:17PM +, Rekel via Digitalmars-d-learn wrote: > I'm not sure why this is happening, but after simplifying my code I > traced it back to what the title may suggest. Keep in mind that CTFE does not support reinterpretation via unions, i.e., reading values from a

Re: write once type?

2021-04-20 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Apr 20, 2021 at 03:56:33PM -0400, Steven Schveighoffer via Digitalmars-d-learn wrote: [...] > I'm wondering if anyone has a "Write once" type, that is, a type that > allows you to write it exactly once, and is treated like > initialization on first setting (i.e. allows writing to

Re: How do I create classes dynamically?

2021-04-15 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Apr 15, 2021 at 08:56:18PM +, mw via Digitalmars-d-learn wrote: [...] > of course, one can manually dispatch: > > if (userInputString == "cat") createCat(); > else if (userInputString == "dog") createDog(); > ... > > but this this tedious. --- // Disclaimer:

Re: Is there a more elegant way to do this in D?

2021-04-08 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Apr 08, 2021 at 08:28:44PM +, Alain De Vos via Digitalmars-d-learn wrote: > The ascii code of 0 is 48 so I think you can add everywhere 48 (but > I'm not a specialist) Why bother with remembering it's 48? Just add '0', like this: int a = [1, 0, 1, 0, 1, ...]; string

Re: what exactly is string length?

2021-04-01 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Apr 02, 2021 at 05:05:21AM +, mw via Digitalmars-d-learn wrote: [...] > This is just an example, what if the exact length is not known > statically, is there a functions to trim the `\0`s? Another way, if you want to avoid the extra allocation, slice the static array with .indexOf:

Re: what exactly is string length?

2021-04-01 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Apr 02, 2021 at 05:05:21AM +, mw via Digitalmars-d-learn wrote: [...] > This is just an example, what if the exact length is not known > statically, is there a functions to trim the `\0`s? What about `s.until('\0')`? Example: auto s = "abc\0\0\0def"; auto t = "blah"

Re: what exactly is string length?

2021-04-01 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Apr 02, 2021 at 04:32:53AM +, mw via Digitalmars-d-learn wrote: [...] > --- > import std; > import std.conv : text; > > > void main() > { > char[6] s; > s = "abc"; > writeln(s, s.length); // abc6, ok it's the static array's length > > string t = text("head-", s,

Re: Need for speed

2021-04-01 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Apr 02, 2021 at 02:36:21AM +, Jon Degenhardt via Digitalmars-d-learn wrote: > On Thursday, 1 April 2021 at 19:55:05 UTC, H. S. Teoh wrote: [...] > > It's interesting that whenever a question about D's performance pops > > up in the forums, people tend to reach for optimization flags.

Re: Need for speed

2021-04-01 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Apr 01, 2021 at 09:16:09PM +, Imperatorn via Digitalmars-d-learn wrote: > On Thursday, 1 April 2021 at 21:13:18 UTC, H. S. Teoh wrote: [...] > > Thanks for the very interesting information; so it looks like most > > of the time spent is actually in copying array elements than > >

Re: Need for speed

2021-04-01 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Apr 01, 2021 at 01:17:15PM -0700, Ali Çehreli via Digitalmars-d-learn wrote: > On 4/1/21 12:55 PM, H. S. Teoh wrote: > > > - Constructing large arrays by appending 1 element at a time with > > `~`. Obviously, this requires many array reallocations and the > > associated copying > > And

Re: Need for speed

2021-04-01 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Apr 01, 2021 at 07:25:53PM +, matheus via Digitalmars-d-learn wrote: [...] > Since this is a "Learn" part of the Foruam, be careful with > "-boundscheck=off". > > I mean for this little snippet is OK, but for a other projects this my > be wrong, and as it says here: >

Re: Need for speed

2021-04-01 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Apr 01, 2021 at 04:52:17PM +, Nestor via Digitalmars-d-learn wrote: [...] > ``` > import std.stdio; > import std.random; > import std.datetime.stopwatch : benchmark, StopWatch, AutoStart; > import std.algorithm; > > void main() > { > auto sw = StopWatch(AutoStart.no); >

Re: Why I need DUB? Will never DMD don't just use import for import packages?

2021-03-29 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Mar 29, 2021 at 07:28:23PM +, Adam D. Ruppe via Digitalmars-d-learn wrote: > On Monday, 29 March 2021 at 19:06:33 UTC, Marcone wrote: > > Why can't I just use: import vibe.vibe; for import packages like Nim > > or Python? Why I still use DUB? > > I don't use dub. Just dmd -i after

Re: What is best way to read and interpret binary files?

2021-03-29 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Mar 30, 2021 at 12:32:36AM +, mw via Digitalmars-d-learn wrote: > On Monday, 19 November 2018 at 22:32:55 UTC, H. S. Teoh wrote: > > Actually, the case is unnecessary, because arrays implicitly convert > > to void[], and pointers are sliceable. So all you need is: > > > >

Re: How to delete dynamic array ?

2021-03-16 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Mar 16, 2021 at 11:28:00PM +, mw via Digitalmars-d-learn wrote: [...] > suppose: > > double[] data; // D type: dynamic array > > As of 2021 what's the correct way to allocate and deallocate (free > memory to the system immediately) D's dynamic array? [...] Note that T[] is just a

Re: Static initialization of associative arrays

2021-03-11 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Mar 11, 2021 at 06:06:35PM +, Chris Piker via Digitalmars-d-learn wrote: [...] > Today I ran across a situation where an immutable associative array > would be handy. While perusing the language spec I noticed here: > > https://dlang.org/spec/hash-map.html#static_initialization >

Re: Broken examples

2021-03-05 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Mar 05, 2021 at 10:01:37PM +, Imperatorn via Digitalmars-d-learn wrote: > Basically none of the examples on here compile: > https://dlang.org/library/std/conv/parse.html > > Any idea why? File a bug. T -- By understanding a machine-oriented language, the programmer will tend to

Re: Can't I allocate at descontructor?

2021-03-05 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Mar 05, 2021 at 08:24:26PM +, Jack via Digitalmars-d-learn wrote: > On Friday, 5 March 2021 at 20:18:44 UTC, Max Haughton wrote: > > On Friday, 5 March 2021 at 20:13:54 UTC, Jack wrote: [...] > > > But the ones heap may never run at all, is that right? > > > > You can't rely on the

Re: Can't I allocate at descontructor?

2021-03-05 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Mar 05, 2021 at 08:03:58PM +, Jack via Digitalmars-d-learn wrote: > On Friday, 5 March 2021 at 09:23:29 UTC, Mike Parker wrote: > > On Friday, 5 March 2021 at 05:31:38 UTC, Jack wrote: > > > The following code returns a memory error. I did notice it did > > > happens whenever I did a

Re: Is there any generic iteration function that stops at first match?

2021-03-04 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Mar 05, 2021 at 02:13:39AM +, Jack via Digitalmars-d-learn wrote: > something like filter[1] but that stops at first match? are there any > native functions for this in D or I have to write one? just making > sure to not reinvent the wheel [...] Why not just .front? E.g.:

Re: How do I run multiple unittests with rdmd?

2021-03-04 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Mar 05, 2021 at 01:47:41AM +, Anthony via Digitalmars-d-learn wrote: > Hello, > > I'm trying to run multiple unittest files with rdmd. > So far I use `find` to just pipe in the files. Eg: > > > time find source -name *__tests.d -exec rdmd -unittest --main > -I../libprelude/source

Re: D's Continous Changing

2021-03-03 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Mar 04, 2021 at 06:43:57AM +, user1234 via Digitalmars-d-learn wrote: > On Thursday, 4 March 2021 at 05:44:53 UTC, harakim wrote: > > For the record, I was able to resolve all of my issues in about 7 > > hours. That included upgrading from DerelictSDL to bindbc and > > converting to

Re: How can I tell if the give parameter can be run at compile time?

2021-03-01 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Mar 01, 2021 at 08:05:57PM +, Jack via Digitalmars-d-learn wrote: > bool g(T)(T) > { > return __traits(compiles, mixin("{ enum a = t; }")); > } > > > int a; > enum s = ""; > // both return false but g(s) is expected to return true > pragma(msg, g(s)); > pragma(msg, g(a));

Re: How do I check if a type is assignable to null at compile time?

2021-02-26 Thread H. S. Teoh via Digitalmars-d-learn
On Sat, Feb 27, 2021 at 01:03:56AM +, Jack via Digitalmars-d-learn wrote: > On Friday, 26 February 2021 at 23:37:18 UTC, Murilo wrote: > > On Friday, 26 February 2021 at 05:25:14 UTC, Jack wrote: > > > I started with: > > > > > > enum isAssignableNull(T) = is(T : Object) || isPointer(T); > >

Re: Can Metaprogramming Help Here?

2021-02-26 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Feb 26, 2021 at 11:37:18AM -0800, H. S. Teoh via Digitalmars-d-learn wrote: > On Wed, Feb 24, 2021 at 08:10:30PM +, Mike Brown via Digitalmars-d-learn > wrote: > [...] > > Thank you for the reply. Im struggling extending this to get the > > nesting working. [

Re: Can Metaprogramming Help Here?

2021-02-26 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Feb 24, 2021 at 08:10:30PM +, Mike Brown via Digitalmars-d-learn wrote: [...] > Thank you for the reply. Im struggling extending this to get the > nesting working. > > I'm trying something like: > > string entry(string i, string[] inherit = []) { > return i; > } > > alias

Re: DUB is not working correctly

2021-02-26 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Feb 26, 2021 at 06:53:32PM +, evilrat via Digitalmars-d-learn wrote: > On Friday, 26 February 2021 at 18:20:38 UTC, Maxim wrote: > > On Friday, 26 February 2021 at 17:57:12 UTC, ryuukk_ wrote: > > > "targetType": "executable", > > > > > > and it should just run using "dub run" > >

Re: DUB is not working correctly

2021-02-24 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Feb 24, 2021 at 06:32:00PM +, Maxim via Digitalmars-d-learn wrote: > On Wednesday, 24 February 2021 at 18:21:40 UTC, evilrat wrote: > > On Wednesday, 24 February 2021 at 17:45:56 UTC, Maxim wrote: > > > > > > Unfortunately, I tried bindbc-sfml package but the problem is > > > still

Re: Compile-Time Function Parameters That Aren't Types?

2021-02-23 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Feb 24, 2021 at 03:52:57AM +, Kyle Ingraham via Digitalmars-d-learn wrote: [...] > I was under the impression that compile-time or template parameters > were only for types. In D, template parameters can take not only types, but almost any type (provided they are constructible at

Re: Can Metaprogramming Help Here?

2021-02-23 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Feb 23, 2021 at 10:24:50PM +, Mike Brown via Digitalmars-d-learn wrote: > Hi all, > > Im porting some C++ code, which has a mess of a section that > implements prime number type id's. I've had to smother it to death > with test cases to get it reliable, I think metaprogramming that D

Re: How to get Laptop battery level

2021-02-22 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Feb 22, 2021 at 08:59:01PM +, Greatsam4sure via Digitalmars-d-learn wrote: > Dlang is a system programming language. How do I access the battery > level of my system using code in dlang? I will appreciate vide sample There is no universal API for this. It depends on which OS you're

Re: Struct delegate access corruption

2021-02-17 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Feb 17, 2021 at 03:38:00PM +, z via Digitalmars-d-learn wrote: > So i've upgraded one of my structs to use the more flexible delegates > instead of function pointers but when the member function tries to > access the struct's members, the contents are random and the program > fails.

Re: Fastest way to "ignore" elements from array without removal

2021-02-15 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Feb 16, 2021 at 04:20:06AM +, z via Digitalmars-d-learn wrote: > What would be the overall best manner(in ease of implementation and > speed) to arbitrarily remove an item in the middle of an array while > iterating through it? > So far i've thought about simply using D's standard

Re: Trying to reduce memory usage

2021-02-12 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Feb 12, 2021 at 07:23:12AM +, frame via Digitalmars-d-learn wrote: > On Friday, 12 February 2021 at 02:22:35 UTC, H. S. Teoh wrote: > > > This turns the OP's O(n log n) algorithm into an O(n) algorithm, > > doesn't need to copy the entire content of the file into memory, and > > also

Re: Trying to reduce memory usage

2021-02-11 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Feb 12, 2021 at 01:45:23AM +, mw via Digitalmars-d-learn wrote: > On Friday, 12 February 2021 at 01:23:14 UTC, Josh wrote: > > I'm trying to read in a text file that has many duplicated lines and > > output a file with all the duplicates removed. > > If you only need to remove

Re: Real simple unresolved external symbols question...

2021-02-10 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Feb 10, 2021 at 11:35:27PM +, WhatMeWorry via Digitalmars-d-learn wrote: [...] > Okay, thanks. Then why does the README.md at > > https://github.com/dlang/druntime > > say "Runtime is typically linked together with Phobos in a release > such that the compiler only has to link to a

Re: Is there a generic type such as void* or C#'s object?

2021-02-05 Thread H. S. Teoh via Digitalmars-d-learn
On Sat, Feb 06, 2021 at 02:01:28AM +, Jack via Digitalmars-d-learn wrote: > in C/C++ you have void* and C#'s object, to create a variable to hold > a genetic type. So in C# you can do: > > class A { > object foo; > } > > and > > var a = new A(); > a.foo = any class...; > > does D have

Re: Any tools to track heap/stack corruptions?

2021-02-03 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Feb 03, 2021 at 03:47:34PM +, Imperatorn via Digitalmars-d-learn wrote: > On Wednesday, 3 February 2021 at 14:00:23 UTC, JN wrote: > > I am dealing with some nasty issue in my code. Basically random > > unrelated lines of code are crashing with access violations, and if > > I switch

Re: Any tools to track heap/stack corruptions?

2021-02-03 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Feb 03, 2021 at 02:00:23PM +, JN via Digitalmars-d-learn wrote: > I am dealing with some nasty issue in my code. Basically random > unrelated lines of code are crashing with access violations, and if I > switch from dmd to ldc the crash goes away, or crash comes back, or it > crashes

Re: What does this code snippet even do?

2021-01-29 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Jan 29, 2021 at 10:41:33PM +, WhatMeWorry via Digitalmars-d-learn wrote: > // The following four lines in run.lang.io > > int[] a; > alias T = long; > pragma(msg, is(typeof(a) : U[], U : T)); This means: "does the type of 'a' have the form U[], where U is a type that implicitly

Re: Why filling AA in shared library freezes execution?

2021-01-29 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Jan 29, 2021 at 12:45:02PM +, Imperatorn via Digitalmars-d-learn wrote: > On Wednesday, 27 January 2021 at 15:25:17 UTC, H. S. Teoh wrote: > > On Wed, Jan 27, 2021 at 02:39:08PM +, Adam D. Ruppe via > > Digitalmars-d-learn wrote: > > > On Wednesday, 27 January 2021 at 14:36:16

Re: unittests and imported modules

2021-01-28 Thread H. S. Teoh via Digitalmars-d-learn
To answer your other question: On Thu, Jan 28, 2021 at 07:44:59PM +, kdevel via Digitalmars-d-learn wrote: [...] > After inserting print statements into the other modules I found that > the additional four unittests originate from the imported files. Is > there a trick to get only the

Re: unittests and imported modules

2021-01-28 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Jan 28, 2021 at 07:44:59PM +, kdevel via Digitalmars-d-learn wrote: > Today I moved some functions to a new module within the same package > and ran > >dmd -g -i -unittest -checkaction=context -main -run . > > dmd reported > >5 unittests passed Which version of dmd is this?

Re: How to dinamically create Tuples?

2021-01-27 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Jan 27, 2021 at 05:17:18PM +, Paul Backus via Digitalmars-d-learn wrote: > On Wednesday, 27 January 2021 at 17:11:52 UTC, Leonardo wrote: > > Hi, I want to know if are some way to dinamically create Tuples, > > with variable size and types defined at runtime. Thanks. > > No. D is a

Re: Why filling AA in shared library freezes execution?

2021-01-27 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Jan 27, 2021 at 02:39:08PM +, Adam D. Ruppe via Digitalmars-d-learn wrote: > On Wednesday, 27 January 2021 at 14:36:16 UTC, Adam D. Ruppe wrote: > > (btw as for me fixing it myself > > oh edit, I should point out it also requires some degree of language > change to match what

Re: 200-600x slower Dlang performance with nested foreach loop

2021-01-26 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Jan 27, 2021 at 01:28:33AM +, Paul Backus via Digitalmars-d-learn wrote: > On Tuesday, 26 January 2021 at 23:57:43 UTC, methonash wrote: > > > Using AA's may not necessarily improve performance. It depends on > > > what your code does with it. Because AA's require random access > >

Re: 200-600x slower Dlang performance with nested foreach loop

2021-01-26 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Jan 26, 2021 at 06:13:54PM +, methonash via Digitalmars-d-learn wrote: [...] > I cannot post the full source code. Then we are limited in how much we can help you. > Regarding a reduced version reproducing the issue: well, that's > exactly what the nested foreach loop does. Without

Re: 200-600x slower Dlang performance with nested foreach loop

2021-01-26 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Jan 26, 2021 at 05:40:36PM +, methonash via Digitalmars-d-learn wrote: [...] > 1) Read a list of strings from a file > 2) De-duplicate all strings into the subset of unique strings > 3) Sort the subset of unique strings by descending length and then by > ascending lexicographic

Re: Why filling AA in shared library freezes execution?

2021-01-26 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Jan 26, 2021 at 02:12:17PM +, Adam D. Ruppe via Digitalmars-d-learn wrote: > On Monday, 25 January 2021 at 21:48:10 UTC, Vitalii wrote: > > Q: Why filling assoc.array in shared library freeze execution? > > D exes loading D dlls are very broken on Windows. You can kinda make > it

Re: dmd -O causes incorrect output

2021-01-25 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Jan 25, 2021 at 06:45:43PM +, Saurabh Das via Digitalmars-d-learn wrote: > On Monday, 25 January 2021 at 18:19:24 UTC, H. S. Teoh wrote: [...] > > It's probably a bug. File a bug on bugzilla: https://issues.dlang.org [...] > > DMD's backend is known to have obscure bugs that crop up

Re: Can we use strings with scanf?

2021-01-25 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Jan 25, 2021 at 06:43:18PM +, Rempas via Digitalmars-d-learn wrote: > On Monday, 25 January 2021 at 18:28:09 UTC, Ferhat Kurtulmuş wrote: > > On Monday, 25 January 2021 at 17:38:21 UTC, Rempas wrote: > > > On Monday, 25 January 2021 at 10:33:14 UTC, Mike Parker wrote: > > > > [...] > >

Re: dmd -O causes incorrect output

2021-01-25 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Jan 25, 2021 at 06:07:46PM +, Saurabh Das via Digitalmars-d-learn wrote: > I'm seeing what appears to be a bug with the -O flag in dmd. [...] > The assert trips when run with "rdmd -O test.d" and it does not trip > when run with "rdmd test.d". It's probably a bug. File a bug on

Re: std.algorithm.splitter on a string not always bidirectional

2021-01-22 Thread H. S. Teoh via Digitalmars-d-learn
On Friday, 22 January 2021 at 17:29:08 UTC, Steven Schveighoffer wrote: On 1/22/21 11:57 AM, Jon Degenhardt wrote: [...] Another way to look at it: If split (eager) took a predicate, that 'xyz.splitter(args).back' and 'xyz.split(args).back' should produce the same result. But they will not

Re: std.algorithm.splitter on a string not always bidirectional

2021-01-21 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Jan 21, 2021 at 05:43:37PM -0500, Steven Schveighoffer via Digitalmars-d-learn wrote: > auto sp1 = "a|b|c".splitter('|'); > > writeln(sp1.back); // ok > > auto sp2 = "a.b|c".splitter!(v => !isAlphaNum(v)); > > writeln(sp2.back); // error, not bidirectional > > Why? is it an oversight,

Re: isCallable fails

2021-01-20 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Jan 20, 2021 at 09:57:59PM +, Paul Backus via Digitalmars-d-learn wrote: > On Wednesday, 20 January 2021 at 19:01:19 UTC, frame wrote: > > On Wednesday, 20 January 2021 at 13:11:09 UTC, Paul Backus > > > > > > Please post an example with enough code to actually produce the > > >

Re: Why many programmers don't like GC?

2021-01-18 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Jan 18, 2021 at 11:43:20AM +, aberba via Digitalmars-d-learn wrote: [...] > It talks how the use of GC is desired even in a game engine like > Unreal. Several AAA title's have been built on Unreal. > > Apparently you can't convince people who have made up their mind about > GC being

Re: Why many programmers don't like GC?

2021-01-15 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Jan 15, 2021 at 09:04:13PM +, welkam via Digitalmars-d-learn wrote: > On Friday, 15 January 2021 at 07:35:00 UTC, H. S. Teoh wrote: > > (1) Refactored one function called from an inner loop to reuse a > > buffer instead of allocating a new one each time, thus eliminating a > > large

Re: To switch GC from FIFO to LIFO paradigm.

2021-01-15 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Jan 15, 2021 at 08:19:18PM +, tsbockman via Digitalmars-d-learn wrote: [...] > However, generational GCs are somewhat closer to LIFO than what we > have now, which does provide some performance gains under common usage > patterns. People have discussed adding a generational GC to D

Re: Why many programmers don't like GC?

2021-01-15 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Jan 15, 2021 at 04:22:59PM +, IGotD- via Digitalmars-d-learn wrote: [...] > Are we talking about the same things here? You mentioned DMD but I was > talking about programs compiled with DMD (or GDC, LDC), not the nature > of the DMD compiler in particular. > > Bump the pointer and

Re: Why many programmers don't like GC?

2021-01-15 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Jan 15, 2021 at 03:18:31PM +, IGotD- via Digitalmars-d-learn wrote: [...] > Bump the pointer is a very fast way to allocate memory but what is > more interesting is what happens when you return the memory. What does > the allocator do with chunks of free memory? Does it put it in a

Re: Why many programmers don't like GC?

2021-01-14 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Jan 14, 2021 at 12:36:12PM +, claptrap via Digitalmars-d-learn wrote: [...] > I think you also have to consider that the GC you get with D is not > state of the art, and if the opinions expressed on the newsgroup are > accurate, it's not likely to get any better. So while you can find

Re: Developing and running D GUI app on Android

2021-01-13 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Jan 13, 2021 at 07:51:08PM +, aberba via Digitalmars-d-learn wrote: [...] > So Adam's tool setup is pretty clear (talked to him). What remains is > calling Java classes and interacting with the Android's API. I know a > little bit of Java but not enough Android. Just the calling >

Re: Why many programmers don't like GC?

2021-01-13 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Jan 13, 2021 at 06:58:56PM +, Marcone via Digitalmars-d-learn wrote: > I've always heard programmers complain about Garbage Collector GC. But > I never understood why they complain. What's bad about GC? It's not merely a technical issue, but also a historical and sociological one.

Re: Developing and running D GUI app on Android

2021-01-12 Thread H. S. Teoh via Digitalmars-d-learn
On Sun, Jan 10, 2021 at 06:58:13PM +, aberba via Digitalmars-d-learn wrote: > I'm looking to explore running a D application on Android based on > Adams previous foundation work. However, I'm not familiar with the > Android + D integration so I need some help. > > Has any of you successfully

Re: DConf talk : Exceptions will disappear in the future?

2021-01-07 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Jan 07, 2021 at 07:00:15PM +, sighoya via Digitalmars-d-learn wrote: > On Thursday, 7 January 2021 at 18:12:18 UTC, H. S. Teoh wrote: [...] > > Wrong. Out of memory only occurs at specific points in the code > > (i.e., when you call a memory allocation primitive). > > What about

Re: DConf talk : Exceptions will disappear in the future?

2021-01-07 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Jan 07, 2021 at 05:47:37PM +, sighoya via Digitalmars-d-learn wrote: > On Thursday, 7 January 2021 at 14:34:50 UTC, H. S. Teoh wrote: > > This has nothing to do with inlining. Inlining is done at > > compile-time, and the inlined function becomes part of the caller. > > True > > >

Re: DConf talk : Exceptions will disappear in the future?

2021-01-07 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Jan 07, 2021 at 11:15:26AM +, sighoya via Digitalmars-d-learn wrote: > On Thursday, 7 January 2021 at 10:36:39 UTC, Jacob Carlborg wrote: [...] > > It's claimed that exceptions are not zero cost, even when an > > exception is not thrown. Because the compiler cannot optimize > >

Re: DConf talk : Exceptions will disappear in the future?

2021-01-07 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Jan 07, 2021 at 12:01:23AM +, sighoya via Digitalmars-d-learn wrote: > On Wednesday, 6 January 2021 at 21:27:59 UTC, H. S. Teoh wrote: [...] > > You don't need to box anything. The unique type ID already tells > > you what type the context is, whether it's integer or pointer and > >

Re: DConf talk : Exceptions will disappear in the future?

2021-01-06 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Jan 06, 2021 at 05:36:07PM +, sighoya via Digitalmars-d-learn wrote: > On Tuesday, 5 January 2021 at 21:46:46 UTC, H. S. Teoh wrote: > > 4) The universal error type contains two fields: a type field and a > > context field. > > > > a) The type field is an ID unique to every thrown

Re: DConf talk : Exceptions will disappear in the future?

2021-01-05 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Jan 05, 2021 at 06:23:25PM +, sighoya via Digitalmars-d-learn wrote: > Personally, I don't appreciate error handling models much which > pollute the return type of each function simply because of the > conclusion that every function you define have to handle errors as > errors can

Re: 64-bit compilation in Wine

2020-12-29 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Dec 29, 2020 at 07:39:14PM +, Raikia via Digitalmars-d-learn wrote: [...] > So interestingly, I actually got this to work by running "sudo wine" > instead of just "wine". No idea why wine needs root access on the > underlying system for wine to operate properly but ok... > > Now I'm

Re: Nasty supprise when using c 'anonymous struct and union' in D with 'static struct'

2020-12-29 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Dec 29, 2020 at 12:50:06PM -0500, Steven Schveighoffer via Digitalmars-d-learn wrote: > On 12/29/20 12:45 PM, H. S. Teoh wrote: [...] > > You need to add 'static' to the (outer) struct declarations in your > > unittest block, because otherwise they *will* have a context > > pointer. > >

Re: Nasty supprise when using c 'anonymous struct and union' in D with 'static struct'

2020-12-29 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Dec 29, 2020 at 05:13:19PM +, Arjan via Digitalmars-d-learn wrote: [...] > On the C/C++ side there is no static. I added those on the D side to > to make sure there is no context pointer being added, since that will > change the layout and size of struct. (in the c/c++ code those

Re: Trying to understand multidimensional arrays in D

2020-12-21 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Dec 22, 2020 at 04:47:13AM +, Rekel via Digitalmars-d-learn wrote: [...] > Defending array-notation by giving an example of explicitly not using > declared aliases makes no sense to me. > When I define 2d arrays, or index them, I think in row -> column terms > (often math notation for

Re: Avoid deallocate empty arrays?

2020-12-17 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Dec 17, 2020 at 06:57:08PM +, IGotD- via Digitalmars-d-learn wrote: [...] > How does this connect to the array with zero elements? According to > your explanation if I have understood it correctly, capacity is also > indicating if the pointer has been "borrowed" from another array >

Re: Avoid deallocate empty arrays?

2020-12-17 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Dec 17, 2020 at 06:10:25PM +, IGotD- via Digitalmars-d-learn wrote: [...] > b.m_buffer.length 2, b.m_buffer.capacity 31 > b.m_buffer.length 0, b.m_buffer.capacity 0 > > capacity 0, suggests that the array has been deallocated. Are you sure? My understanding is that capacity is

Re: Writing a really fast lexer

2020-12-11 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Dec 11, 2020 at 07:49:12PM +, vnr via Digitalmars-d-learn wrote: > For a project with good performance, I would need to be able to > analyse text. To do so, I would write a parser by hand using the > recursive descent algorithm, based on a stream of tokens. I started > writing a lexer

Re: Dude about ~ array concatenation performance

2020-12-01 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Dec 01, 2020 at 10:49:55PM +, ddcovery via Digitalmars-d-learn wrote: > Yesterday I really shocked when, comparing one algorithm written in > javascript and the equivalent in D, javascript performed better!!! [...] > With 1 million Double numbers (generated randomly): > Javascript

<    1   2   3   4   5   6   7   8   9   10   >