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 
computationally demanding as each subsequent call will need to 
do a check to see if it has a value as it results in an 
optional type (for binary operators). So something like `a + b 
* c` is now much more expensive than it appears. This is 
exactly the kind of abuse of operator overloading that the 
feature is shunned for.


What can I say? If you don't like the semantics, don't use it. I 
have found value in it.


Anyways not sure what you mean here with the code below. If 
"first" here returns an optional type, you can't call 
"doSomething" like that without first checking if the value 
exists. Optional just doesn't allow it and Nullable will throw 
an exception.


```
list.first.doSomething(); // error
```


You are right. Nowadays you need a `.oc` call in between. Also, 
doSomething cannot be a free-standing function (sadly).


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 dumb but, hey it works :-)


--
Robert M. Münch
http://www.saphirion.com
smarter | better | faster



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 that function to initialize your other thing and 
enjoy the magic of CTFE!


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 TABLE data(";

static foreach(f; FieldNameTuple!S) {
s ~= f ~ ",";
}

s ~= ");";
return s;
} ();

pragma(msg, sql);

--

This prints "CREATE TABLE data(a, b);"



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 
build-up strings in a statif foreach loop.


Is this possible at all?

--
Robert M. Münch
http://www.saphirion.com
smarter | better | faster



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:

https://issues.dlang.org/show_bug.cgi?id=20646 )

The other problem I had was that the Deb I created on the stack 
had its own internal rbtree that was always null.


To address this I changed tags in the Deb struct to this:

auto tags = new RedBlackTree!string;

so it always creates a new empty tree. And I renamed clear to 
reset and now do this:


void reset() {
name = "";
...
tags = new RedBlackTree!string;
...
}

I assume that I can safely rely on the GC to clean up for me.

So now I think I can safely use the pattern (1., repeat 2.1, ... 
) described earlier: certainly it builds and runs.


Next I'll have to try really populating the Debs including their 
tag trees and populating the debs tree of Debs structs.


Thank you.





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 compile 
time (with the match template), or at runtime (with the 
tryMatch template).


The power of optionals, however, lies in the following:

```
list.first.doSomething();
```

Here doSomething will only be called when the list contains at 
least one item. Here I don't care about cases where the list is 
empty, I just want to doSomething if it isn't.


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 computationally 
demanding as each subsequent call will need to do a check to see 
if it has a value as it results in an optional type (for binary 
operators). So something like `a + b * c` is now much more 
expensive than it appears. This is exactly the kind of abuse of 
operator overloading that the feature is shunned for.


Anyways not sure what you mean here with the code below. If 
"first" here returns an optional type, you can't call 
"doSomething" like that without first checking if the value 
exists. Optional just doesn't allow it and Nullable will throw an 
exception.


```
list.first.doSomething(); // error
```

Which makes it odd that it forwards operator overloading to the 
underlying type, which is basically just syntactic sugar for 
calling a method on the object. Seems like a conflicting design 
decision to me.






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


This means that `array` can be used instead of `this`


Hmm should not that change the meaning of this throughout the 
struct? is this good practice?


Thank you


This is also a way of imitating inheritance in c-ish code without 
classes.


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 means that `array` can be used instead of `this`


Hmm should not that change the meaning of this throughout the struct? is 
this good practice?


No, it's simply a fallback. If the symbol doesn't work with this.symbol, 
try this.array.symbol.


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.


-Steve


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
#0  0x55701ef0 in 
_D3std9container6rbtree__T12RedBlackTreeTAyaVQea5_61203c2062Vbi0ZQBn5emptyMFNaNbNdNiNfZb 
(this=0x0)


RedBlackTree is a class. Make sure you allocate it. The above shows 
"this = 0x0".


I saw a few other "this = 0x0" items, but perhaps that's OK for your 
code, I don't know what those types are.


-Steve


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 you are wasting a lot of memory by allocating 
another heap allocated thing to get stored inside there.


You can use predicate to solve the issue like you suggest below. But I'm 
totally missed that RBNodes are heap-allocated, thanks!


2. RedBlackTree allows you to identify the relationship that you 
consider unique by providing a "less" function. Instead of instrumenting 
your Deb type, which might affect other usages, just do:


RedBlackTree!(Deb, (a, b) => a.name < b.name)
 > No need to add opCmp and opEquals (if that doesn't make sense in other
contexts).

-Steve





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 was more than one. They had to be distinguished somehow.


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

RedBlackTree!(Deb, (a, b) => a.name < b.name) debs;

Deb deb;
auto file = File(filename);
foreach(line; file.byLine) {
line = strip(line);
if (line.empty) {
if (deb.valid)
debs.insert(deb); // XXX
else // report incomplete
deb.clear;
continue;
}
...
}
if (deb.valid)
debs.insert(deb);

This compiles & crashes with "Program exited with code -11".

What I'm trying to do but clearly don't understand is this:

1. create a struct
repeat:
 2.1. populate the struct
 2.2. copy the struct into an rbtree // XXX
 2.3. clear the original struct
 2.4. loop

At XXX does a copy take place? I thought it did with structs?

Anyway, here's the backtrace:

$ gdb DebFind
GNU gdb (Ubuntu 8.1-0ubuntu3.2) 8.1.0.20180409-git
...
Reading symbols from DebFind...done.
(gdb) run
Starting program: /home/mark/app/d/debfind/DebFind
[Thread debugging using libthread_db enabled]
Using host libthread_db library 
"/lib/x86_64-linux-gnu/libthread_db.so.1".

[New Thread 0x76e02700 (LWP 2366)]
...

Thread 1 "DebFind" received signal SIGSEGV, Segmentation fault.
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
#0  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
#1  0x55701a11 in 
qtrac.debfind.model.Model.readPackageFile(immutable(char)[]) 
(this=0x0, filename=...) at model.d:66
warning: (Internal error: pc 0x5591b874 in read in psymtab, 
but not in symtab.)


warning: (Internal error: pc 0x5591b820 in read in psymtab, 
but not in symtab.)


warning: (Internal error: pc 0x5591b874 in read in psymtab, 
but not in symtab.)


#2  0x55701671 in 
qtrac.debfind.model.Model.initialize(int) (this=0x0, 
maxDebNamesForWord=100) at model.d:31
warning: (Internal error: pc 0x5591b874 in read in psymtab, 
but not in symtab.)


#3  0x557045b0 in 
_D5qtrac7debfind9appwindow9AppWindow6__ctorMFC3gtk11ApplicationQnZCQCnQCkQCfQBy (this=0x77ece630, application=0x77ed1360) at appwindow.d:31
#4  0x55722819 in 
_D5qtrac7debfind3app4mainFAAyaZ__T12__dgliteral2TC3gio11ApplicationQnZQBkMFQBaZv (GioApplication=0x77ed1360) at app.d:16
#5  0x5575be54 in 
_D7gobject8DClosureQj__T17d_closure_marshalTDFC3gio11ApplicationQnZvZQBtUPSQCv1c5types8GClosurePSQDrQwQw6GValuekQrPvQcZv (closure=0x55c37690, return_value=0x0, n_param_values=1, param_values=0x77ef46e0, invocation_hint=0x7fffd710 "\b", marshal_data=0x0) at DClosure.d:122
#6  0x7419410d in g_closure_invoke () at 
/usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0
#7  0x741a705e in  () at 
/usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0
#8  0x741af715 in g_signal_emit_valist () at 
/usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0
#9  0x741b012f in g_signal_emit () at 
/usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0
warning: (Internal error: pc 0x5591b874 in read in psymtab, 
but not in symtab.)


#10 0x7fffee148b95 in  () at 
/usr/lib/x86_64-linux-gnu/libgio-2.0.so.0
warning: (Internal error: pc 0x5591b874 in read in psymtab, 
but not in symtab.)


#11 0x7fffee148da6 in g_application_run () at 
/usr/lib/x86_64-linux-gnu/libgio-2.0.so.0
warning: (Internal error: pc 0x5591b874 in read in psymtab, 
but not in symtab.)


#12 0x5591b875 in warning: (Internal error: pc 
0x5591b874 in read in psymtab, but not in symtab.)


_D3gio11ApplicationQn3runMFAAyaZiwarning: (Internal error: pc 
0x5591b874 in read in psymtab, but not in symtab.)


warning: (Internal error: pc 0x5591b874 in read in psymtab, 
but not in symtab.)


 (warning: (Internal error: pc 0x5591b874 in read in psymtab, 
but not in symtab.)


this=0x77ed1360, warning: (Internal error: pc 0x5591b874 
in read in psymtab, but not in symtab.)


argv=...)warning: (Internal error: pc 0x5591b874 in read in 
psymtab, but not in symtab.)


 at Application.dwarning: (Internal error: pc 0x5591b874 in 
read in psymtab, but not in symtab.)


warning: (Internal error: pc 0x5591b874 in read in psymtab, 
but not in symtab.)


:931
#13 0x55722760 in D main (args=...) at app.d:18


And thanks for helping!


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`


Hmm should not that change the meaning of this throughout the 
struct? is this good practice?


Thank you



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 be used instead of `this`


To expand on this, the compiler basically substitutes the symbol aliased 
here for the item itself if all other members are a compiler error.


So for example, if you have:

barr.length;

and barr has no member length, it tries:

barr.array.length

-Steve


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;
     }
     if (deb == null)
     deb = new Deb;

change #2: gets rid of most errors:

     bool opEquals(const Deb* other) const @safe pure nothrow {

     int opCmp(ref const Deb* other) const {

Just changed to pointers & moved to a separate file.

So now I just have one error in line 12 of model.d:

RedBlackTree!Deb* debs; // name-ordered list of deb packages LINE 12


Performing "debug" build using 
/home/mark/opt/ldc2-1.20.0-linux-x86_64/bin/ldc2 for x86_64.

gtk-d:gtkd 3.9.0: target for configuration "library" is up to date.
debfind ~master: building configuration "application"...
src/model.d(12,9): Error: template instance 
std.container.rbtree.RedBlackTree!(Deb) does not match template 
declaration RedBlackTree(T, alias less = "a < b", bool allowDuplicates = 
false)

   with T = Deb
   must satisfy the following constraint:
    is(typeof(binaryFun!less(T.init, T.init)))
/home/mark/opt/ldc2-1.20.0-linux-x86_64/bin/ldc2 failed with exit code 1.



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 you are wasting a lot of memory by allocating 
another heap allocated thing to get stored inside there.


2. RedBlackTree allows you to identify the relationship that you 
consider unique by providing a "less" function. Instead of instrumenting 
your Deb type, which might affect other usages, just do:


RedBlackTree!(Deb, (a, b) => a.name < b.name)

No need to add opCmp and opEquals (if that doesn't make sense in other 
contexts).


-Steve


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 struct has no property called length - but this is referenced. 
Where does this come from?

it comes from `array` being alias for `this`, see above


Thank you

Regards




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;
     }
     if (deb == null)
     deb = new Deb;

change #2: gets rid of most errors:

     bool opEquals(const Deb* other) const @safe pure nothrow {

     int opCmp(ref const Deb* other) const {

Just changed to pointers & moved to a separate file.

So now I just have one error in line 12 of model.d:

RedBlackTree!Deb* debs; // name-ordered list of deb packages LINE 12


Performing "debug" build using 
/home/mark/opt/ldc2-1.20.0-linux-x86_64/bin/ldc2 for x86_64.

gtk-d:gtkd 3.9.0: target for configuration "library" is up to date.
debfind ~master: building configuration "application"...
src/model.d(12,9): Error: template instance 
std.container.rbtree.RedBlackTree!(Deb) does not match template 
declaration RedBlackTree(T, alias less = "a < b", bool allowDuplicates = 
false)

   with T = Deb
   must satisfy the following constraint:
    is(typeof(binaryFun!less(T.init, T.init)))
/home/mark/opt/ldc2-1.20.0-linux-x86_64/bin/ldc2 failed with exit code 1.



try
```
RedBlackTree!(Deb*) debs;
```


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 reason? Is this +01:00 not ISO conforming?

I take it that you're asking why you don't get the time zone as part of the
string when you call one of the to*String functions? If so, then you're
using LocalTime for your time zone. LocalTime does not print out the UTC
offset as part of the ISO string, whereas other time zones types do (or z in
the case of UTC). This is because the ISO spec says that when the time zone
is not provided, it's assumed to be local time. When I wrote it, I therefore
made it so that the time zone was not put at the end of the string when it
was local time. I don't remember now if I thought that that was required, or
if I just did it, because it corresponded to what happens when you read an
ISO or ISO extended string without a time zone, but at this point, I think
that it was a mistake. Yes, the spec requires that the time zone be treated
as local time when it's not present, but that doesn't mean that the time
zone can't be printed when it's local time. And in general, generating an
ISO string without a time zone is asking for bugs, since the time then won't
match if it's read in on a computer with a different time zone (though it
isn't likely to matter much if it's just printed out).

Unfortunately, I'm not sure that it's reasonable to fix it at this point,
since there's bound to be software that relies on the current behavior.
Given the current behavior, I think that it's usually best to call toUTC
before calling any of the to*String functions unless you're just printing to
a log or something, and there's no real risk of the string being intepreted
as a time value by a program in the future.

- Jonathan M Davis






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 you

Regards


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 around names ... it's 
so difficult to understand people when it's referring to them 
...we already had to remember a gazillion on things, including 
horrible ubuntu names instead of simple numbers! :-)


That's something else, it's more related to the internal codename.
Very common for Operating systems. I've seen usage for other 
software.

Often they are forgotten quickly.



Packages are ... well packages!

:-P

/P





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)
deb = new Deb;

change #2: gets rid of most errors:

bool opEquals(const Deb* other) const @safe pure nothrow {

int opCmp(ref const Deb* other) const {

Just changed to pointers & moved to a separate file.

So now I just have one error in line 12 of model.d:

RedBlackTree!Deb* debs; // name-ordered list of deb packages LINE 
12



Performing "debug" build using 
/home/mark/opt/ldc2-1.20.0-linux-x86_64/bin/ldc2 for x86_64.
gtk-d:gtkd 3.9.0: target for configuration "library" is up to 
date.

debfind ~master: building configuration "application"...
src/model.d(12,9): Error: template instance 
std.container.rbtree.RedBlackTree!(Deb) does not match template 
declaration RedBlackTree(T, alias less = "a < b", bool 
allowDuplicates = false)

  with T = Deb
  must satisfy the following constraint:
   is(typeof(binaryFun!less(T.init, T.init)))
/home/mark/opt/ldc2-1.20.0-linux-x86_64/bin/ldc2 failed with exit 
code 1.




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 them ...we 
already had to remember a gazillion on things, including horrible 
ubuntu names instead of simple numbers! :-)


Packages are ... well packages!

:-P

/P


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 Deb* as you suggested:

struct Deb {
string name;
...
RedBlackTree!string tags;

bool valid() { return !(name.empty || description.empty); }

size_t toHash() const @safe nothrow {
return typeid(name).getHash(); // names are unique
}

bool opEquals(const Deb other) const @safe pure nothrow {
return name == other.name; // names are unique
}

int opCmp(ref const Deb other) const {
return cmp(name, other.name); // names are unique
}
}

Which I now want to store in:

RedBlackTree!Deb* debs; // name-ordered list of deb packages

And now I'm populating like this:

Deb* deb;
auto file = File(filename);
foreach(line; file.byLine) {
line = strip(line);
if (line.empty) {
if (deb != null && deb.valid) {
debs.insert(deb);
deb.clear;
}
// else report incomplete package
continue;
}
if (deb == null)
deb = new Deb;
...
}
if (deb != null && deb.valid)
debs.insert(deb);

But it crashes with:

Performing "debug" build using 
/home/mark/opt/ldc2-1.20.0-linux-x86_64/bin/ldc2 for x86_64.
gtk-d:gtkd 3.9.0: target for configuration "library" is up to 
date.

debfind ~master: building configuration "application"...
src/model.d(96,36): Error: template 
std.container.rbtree.RedBlackTree!(Deb, "a < b", 
false).RedBlackTree.stableInsert cannot deduce function from 
argument types !()(Deb*), candidates are:

/home/mark/opt/ldc2-1.20.0-linux-x86_64/bin/../import/std/container/rbtree.d(1256,12):
stableInsert(Stuff)(Stuff stuff)
  with Stuff = Deb*
  must satisfy the following constraint:
   isImplicitlyConvertible!(Stuff, Elem)
...




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 growth to 
>250K) in an AA:


Deb[string] debForName;

I plan to populate debForName by reading data files (actually 
Debian Packages files) like this:


Deb deb;
auto file = File(filename):
foreach(line; file.byLine) {
if (line.empty) {
if (deb.valid) // end of package
debForName[deb.name] = deb; // XXX
// else report incomplete package
deb.clear;
continue;
}
... // populate the deb
}
if (deb.valid)
debForName[deb.name] = deb;

I'm assuming that line XXX will copy the Deb including the tree 
(which as usual I'm using as a set -- I really miss a set class 
in D!). Will this work (I'll find out myself next week when I get 
further, but D experts can likely tell from the above).


Should Deb be a class rather than a struct?


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
smarter | better | faster



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'