betterC main() linkage

2020-03-07 Thread drug via Digitalmars-d-learn
the specification says that in betterC mode the main function should have extern(C) linkage. Accidentally I found that dmd does not demand it in contrast to ldc. Is it bug of dmd or the specification can be relaxed?

Re: Idiomatic way to express errors without resorting to exceptions

2020-03-07 Thread Sebastiaan Koppe via Digitalmars-d-learn
On Saturday, 7 March 2020 at 15:44:38 UTC, Arine wrote: I feel as though that's it's greatest weakness. It makes the check whether there is or isn't a value hidden. The case when there isn't a value should be handled explicitly, not implicitly. Propogating a None value isn't useful and is

Re: Trying to understand a simple piece of code: dmd barray

2020-03-07 Thread Dibyendu Majumdar via Digitalmars-d-learn
On Saturday, 7 March 2020 at 14:33:29 UTC, Steven Schveighoffer wrote: It's D's version of implicit conversion. You can make the alias this a no-arg function and it will try calling that function. Okay thank you.

Re: static foreach / How to construct concatenated string?

2020-03-07 Thread Robert M. Münch via Digitalmars-d-learn
On 2020-03-07 16:40:15 +, Adam D. Ruppe said: Use regular foreach with a regular string. Put that inside a function. Then simply use that function to initialize your other thing and enjoy the magic of CTFE! Perfect! This implicit CTFE is a tricky thing to see/remember/... Feeling a bit

Re: static foreach / How to construct concatenated string?

2020-03-07 Thread Adam D. Ruppe via Digitalmars-d-learn
On Saturday, 7 March 2020 at 16:30:59 UTC, Robert M. Münch wrote: Which of course doesn't work... I didn't find any reference how to build-up strings in a statif foreach loop. Is this possible at all? Use regular foreach with a regular string. Put that inside a function. Then simply use

Re: static foreach / How to construct concatenated string?

2020-03-07 Thread MoonlightSentinel via Digitalmars-d-learn
On Saturday, 7 March 2020 at 16:30:59 UTC, Robert M. Münch wrote: Is this possible at all? You can use an anonymous lambda to build the string in CTFE: -- struct S { int a; bool b; } import std; enum string sql = { string s = "CREATE

static foreach / How to construct concatenated string?

2020-03-07 Thread Robert M. Münch via Digitalmars-d-learn
I want to create a "CREATE TABLE data (...)" where the columns are derived from struct member names. Something like: string s = "CREATE TABLE data("; static foreach(f; FieldNameTuple!myStruct) { s ~= f ~ ","; } s ~= ");"; Which of course doesn't work... I didn't find any reference how to

Re: use of struct vs class

2020-03-07 Thread mark via Digitalmars-d-learn
Steve, thank you once again. Now it compiles & runs! I now create my tree like this: auto debs = new RedBlackTree!(Deb, (a, b) => a.name < b.name); (I feel that the rbtree docs are inadequate regarding creating new empty trees, so have submitted a bug report:

Re: Idiomatic way to express errors without resorting to exceptions

2020-03-07 Thread Arine via Digitalmars-d-learn
On Saturday, 29 February 2020 at 15:23:02 UTC, Sebastiaan Koppe wrote: Like I said, I don't use optionals when I care about errors. That is not what they are designed for. If I want to type-guard potential errors I will use SumType!(T, Error). It forces you to handle both cases, either at

Re: Trying to understand a simple piece of code: dmd barray

2020-03-07 Thread Ferhat Kurtulmuş via Digitalmars-d-learn
On Saturday, 7 March 2020 at 13:06:39 UTC, Dibyendu Majumdar wrote: On Saturday, 7 March 2020 at 12:26:32 UTC, drug wrote: I am trying to understand https://github.com/dlang/dmd/blob/master/src/dmd/backend/barray.d. Two questions: 1. What does this mean and why is it needed? line 95: alias

Re: Trying to understand a simple piece of code: dmd barray

2020-03-07 Thread Steven Schveighoffer via Digitalmars-d-learn
On 3/7/20 8:06 AM, Dibyendu Majumdar wrote: On Saturday, 7 March 2020 at 12:26:32 UTC, drug wrote: I am trying to understand https://github.com/dlang/dmd/blob/master/src/dmd/backend/barray.d. Two questions: 1. What does this mean and why is it needed? line 95: alias array this; This

Re: use of struct vs class

2020-03-07 Thread Steven Schveighoffer via Digitalmars-d-learn
On 3/7/20 8:22 AM, mark wrote: 0x55701ef0 in _D3std9container6rbtree__T12RedBlackTreeTAyaVQea5_61203c2062Vbi0ZQBn5emptyMFNaNbNdNiNfZb (this=0x0)     at /home/mark/opt/ldc2-1.20.0-linux-x86_64/bin/../import/std/container/rbtree.d:967 967    return _end.left is null; (gdb) bt

Re: use of struct vs class

2020-03-07 Thread drug via Digitalmars-d-learn
07.03.2020 15:58, Steven Schveighoffer пишет: Hm... I'd say: 1. Don't use a pointer for the element. Just use the struct directly. Using a pointer is bad because it's now going to compare pointers, and not the element data. Not only that, but RBNodes are stored as heap-allocated structs, so

Re: Cool name for Dub packages?

2020-03-07 Thread jxel via Digitalmars-d-learn
On Saturday, 7 March 2020 at 11:10:01 UTC, Dennis wrote: On Saturday, 7 March 2020 at 10:49:24 UTC, Paolo Invernizzi wrote: Frankly, I simply hate all that shuffle around names ... I remember someone noting how unusual it is for D to have a name for its standard library, "Phobos". There

Re: use of struct vs class

2020-03-07 Thread mark via Digitalmars-d-learn
I've now gone back to using structs direct without pointers but I'm still doing something wrong. struct Deb { string name; ... RedBlackTree!string tags; bool valid() { return !(name.empty || description.empty); } void clear() { name = ""; ...; tags.clear; } }

Re: Trying to understand a simple piece of code: dmd barray

2020-03-07 Thread Dibyendu Majumdar via Digitalmars-d-learn
On Saturday, 7 March 2020 at 12:26:32 UTC, drug wrote: I am trying to understand https://github.com/dlang/dmd/blob/master/src/dmd/backend/barray.d. Two questions: 1. What does this mean and why is it needed? line 95: alias array this; This means that `array` can be used instead of `this`

Re: Trying to understand a simple piece of code: dmd barray

2020-03-07 Thread Steven Schveighoffer via Digitalmars-d-learn
On 3/7/20 7:26 AM, drug wrote: 07.03.2020 15:05, Dibyendu Majumdar пишет: Hi, I am trying to understand https://github.com/dlang/dmd/blob/master/src/dmd/backend/barray.d. Two questions: 1. What does this mean and why is it needed? line 95: alias array this; This means that `array` can

Re: use of struct vs class

2020-03-07 Thread Steven Schveighoffer via Digitalmars-d-learn
On 3/7/20 5:58 AM, mark wrote: change #1:     if (line.empty) {     if (deb != null && deb.valid)     debs.insert(deb);     else // report incomplete     deb = null;     continue;  

Re: Trying to understand a simple piece of code: dmd barray

2020-03-07 Thread drug via Digitalmars-d-learn
07.03.2020 15:05, Dibyendu Majumdar пишет: Hi, I am trying to understand https://github.com/dlang/dmd/blob/master/src/dmd/backend/barray.d. Two questions: 1. What does this mean and why is it needed? line 95: alias array this; This means that `array` can be used instead of `this` 2. The

Re: use of struct vs class

2020-03-07 Thread drug via Digitalmars-d-learn
07.03.2020 13:58, mark пишет: change #1:     if (line.empty) {     if (deb != null && deb.valid)     debs.insert(deb);     else // report incomplete     deb = null;     continue;   

Re: std.datetime & timzone specifier: 2018-11-06T16:52:03+01:00

2020-03-07 Thread Jonathan M Davis via Digitalmars-d-learn
On Saturday, March 7, 2020 2:43:47 AM MST Robert M. Münch via Digitalmars-d- learn wrote: > It looks like std.datetime is not anticipating the +1:00 part of a date > like: "2018-11-06T16:52:03+01:00" > > Those dates are used all over on the internet and I'mm wondering why > it's not supported. Any

Trying to understand a simple piece of code: dmd barray

2020-03-07 Thread Dibyendu Majumdar via Digitalmars-d-learn
Hi, I am trying to understand https://github.com/dlang/dmd/blob/master/src/dmd/backend/barray.d. Two questions: 1. What does this mean and why is it needed? line 95: alias array this; 2. The struct has no property called length - but this is referenced. Where does this come from? Thank

Re: Cool name for Dub packages?

2020-03-07 Thread Basile B. via Digitalmars-d-learn
On Saturday, 7 March 2020 at 10:49:24 UTC, Paolo Invernizzi wrote: On Saturday, 7 March 2020 at 09:31:27 UTC, JN wrote: Do we have any cool name for Dub packages? tapes. Rust has 'crates' Crystal has 'shards' Python has 'wheels' Ruby has 'gems' Frankly, I simply hate all that shuffle

Re: Cool name for Dub packages?

2020-03-07 Thread Dennis via Digitalmars-d-learn
On Saturday, 7 March 2020 at 10:49:24 UTC, Paolo Invernizzi wrote: Frankly, I simply hate all that shuffle around names ... I remember someone noting how unusual it is for D to have a name for its standard library, "Phobos".

Re: use of struct vs class

2020-03-07 Thread mark via Digitalmars-d-learn
change #1: if (line.empty) { if (deb != null && deb.valid) debs.insert(deb); else // report incomplete deb = null; continue; } if (deb == null)

Re: use of struct vs class

2020-03-07 Thread mark via Digitalmars-d-learn
Instead of deb.clear I'm now doing deb = null;

Re: Cool name for Dub packages?

2020-03-07 Thread Paolo Invernizzi via Digitalmars-d-learn
On Saturday, 7 March 2020 at 09:31:27 UTC, JN wrote: Do we have any cool name for Dub packages? Rust has 'crates' Crystal has 'shards' Python has 'wheels' Ruby has 'gems' Frankly, I simply hate all that shuffle around names ... it's so difficult to understand people when it's referring to

Re: use of struct vs class

2020-03-07 Thread mark via Digitalmars-d-learn
On Saturday, 7 March 2020 at 10:30:06 UTC, drug wrote: 07.03.2020 13:20, mark пишет: I have this struct (with details omitted [ snip ] Should Deb be a class rather than a struct? Do you consider using pointers in AA: ``` Deb*[string] debForName; ``` I've done some changes including using

Re: use of struct vs class

2020-03-07 Thread drug via Digitalmars-d-learn
07.03.2020 13:20, mark пишет: I have this struct (with details omitted [ snip ] Should Deb be a class rather than a struct? Do you consider using pointers in AA: ``` Deb*[string] debForName; ```

use of struct vs class

2020-03-07 Thread mark via Digitalmars-d-learn
I have this struct (with details omitted ... for brevity): struct Deb { string name; ... RedBlackTree!string tags; void clear() { name = ""; ...; tags.clear; } bool valid() { return !(name.empty || description.empty); } } I plan to store >65K of these (with potential for

std.datetime & timzone specifier: 2018-11-06T16:52:03+01:00

2020-03-07 Thread Robert M. Münch via Digitalmars-d-learn
It looks like std.datetime is not anticipating the +1:00 part of a date like: "2018-11-06T16:52:03+01:00" Those dates are used all over on the internet and I'mm wondering why it's not supported. Any reason? Is this +01:00 not ISO conforming? -- Robert M. Münch http://www.saphirion.com

Cool name for Dub packages?

2020-03-07 Thread JN via Digitalmars-d-learn
Do we have any cool name for Dub packages? Rust has 'crates' Crystal has 'shards' Python has 'wheels' Ruby has 'gems'