Re: Associative arrays with keys containing mutable indirections

2017-10-29 Thread Jonathan M Davis via Digitalmars-d-learn
On Sunday, October 29, 2017 22:24:57 Nordlöw via Digitalmars-d-learn wrote:
> Shouldn't associative arrays with key types (K) having mutable
> indirections (std.traits.hasAliasing!K) such as
>
>  string[ubyte[]]
>
> be disallowed?
>
> If not, in what cases do we want this?

Well, the built-in associative arrays _are_ kind of a mess (though the
situation has improved somewhat over time), but the way that this was
handled does make _some_ sense, even if it's still not correct. If you had
something like

string[ubyte[]] aa;
pragma(msg, (typeof).string);

This will print

string[const(ubyte)[]]

So, similar to C++'s std::map, const gets added for you underneath the hood
for the keys, which does prevent _some_ bad assignments. Unfortunately,
that's still not enough - it really should be immutable. For instance,

void main()
{
string[ubyte[]] aa;
ubyte[] a = [1, 2, 3];
aa[a] = "hello";
}

fails to compile and gives the error

q.d(5): Error: associative arrays can only be assigned values with immutable 
keys, not int[]

but this code

void main()
{
string[ubyte[]] aa;
ubyte[] a = [1, 2, 3];
const b = a;
aa[b] = "hello";
}

does compile. So, the way it handles this avoids forcing you to explicitly
put the const or immutable on the key type, which makes for less typing, but
the fact that it's using const and not immutable is definitely a bug. Based
on the error message, clearly it was acknowledged that the keys need to be
immutable, but clearly that hasn't quite made it how the rest of it was
implemented. IIRC, the implementation using void* and casts everywhere, so
it's pretty trivial for it to break the type system if anything gets screwed
up.

But as I said, the built-in AAs are a mess. They work reasonably well for
basic cases but start falling apart when you do stuff like use classes for
keys. While the situation is better than it used to be, historically, we've
had tons of bugs in the implementation, and overall, I'd argue that having
AAs in the language was a mistake. It probably made more sense in the D1
days, but at this point, the only real advantage over a library type is that
the built-in AAs work with AA literals, and a library type wouldn't (though
with a solid DIP, I'm sure that that could be fixed).

Work has been done on templatizing the AA implementation, which should help,
but we'd be much better off sorting out a proper library type and
encouraging its use. One of the suggestions of how to improve things has
been to restrict keys for the built-in AAs to simpler types (e.g. no
classes), but there hasn't been agreement on that, and we'd actually need a
proper library type in Phobos before doing something like that (and the
situation with Phobos and containers is its own mess).

The whole AA mess comes up probably just about every dconf, and I expect
that it will be sorted out eventually, but when that will be, I don't know.
A big part of the question is what's going to happen with Martin's work on
templatizing the implementation. It may be that that can salvage things, but
in the interim, bugs in in the built-in AAs are no surprise. If anything,
it's probably a miracle that they work as well as they do.

- Jonathan M Davis




Associative arrays with keys containing mutable indirections

2017-10-29 Thread Nordlöw via Digitalmars-d-learn
Shouldn't associative arrays with key types (K) having mutable 
indirections (std.traits.hasAliasing!K) such as


string[ubyte[]]

be disallowed?

If not, in what cases do we want this?


Re: dub optional dependency

2017-10-29 Thread Andre Pany via Digitalmars-d-learn

On Sunday, 29 October 2017 at 03:26:14 UTC, Mike Parker wrote:

On Sunday, 29 October 2017 at 01:55:22 UTC, evilrat wrote:



This is dub design choice, optional requires manual 
fetching(dub fetch 'package'). I don't see other options, but 
you can try hack this using 'preBuildCommands' by adding dub 
fetch. Of course this defeats the purpose.


No, they don't need to be manually fetched. Optional packages 
are downloaded when they are specified in the 
dub.selections.json file.




Isn't it possible to put dependencies in specific 
configuration?


What the OP wants is to have dependencies in a configuration be 
downloaded only when the configuration is specified. Currently, 
dependencies are always downloaded unless they are optional, no 
matter where they're listed in the file. And optional 
dependencies are only downloaded when they are specified in 
dub.selections.json.


It would be a nice feature to have.


In my case the eager dependency resolution is a serious problem. 
In my work environment access to the internet is forbidden for 
the official build due to software lifecycle requirements. The 
consequence is that I have to fetch all dependencies into the dub 
project (--cache = local).
In addition every time open source software is used, for each 
open source software product a process has to be fulfilled.


As example I would like to use the unit test framework d-unit. 
This dub package has for a specific configuration a decency to 
unit-threaded. The official build will fail as unit-threaded can 
not be found (no internet access). Including unit-threaded is not 
an option due to the open source process. Doing this process for 
the sake of a dub issue is not acceptable.


There is an additional dub build option --nodeps. In my opinion 
this option should solve the problem but it is not working as 
expected. Maybe to due a bug.

I created dub issue 1272 regarding this issue.

Kind regards
Andre


Re: CSV with empty values for integer fields

2017-10-29 Thread Jesse Phillips via Digitalmars-d-learn
Not really you'll need to parse it out as a string and do the 
conversion later.


It probably would be good to support nullable!int pretty sure it 
doesn't currently.


std.format and floating point issue

2017-10-29 Thread codephantom via Digitalmars-d-learn
Can anyone help me to understand why the format in the second 
writeln below, does not format the output with commas?




void main()
{
import std.stdio, std.format;

writeln( format("%,.1f", 84543432.951172) ); // 84,543,433.0
writeln( format("%,.0f", 84543432.951172) ); // 84543433

}

--