latin9 characters in filesystem and command line; std.encoding [ISO-8859-15]

2019-03-17 Thread kdevel via Digitalmars-d-learn

This program:

```ls.d
import std.stdio;
import std.file;
void main (string [] args)
{
   auto entries = dirEntries (args[1], SpanMode.shallow, false);
   foreach (e; entries)
  writeln (e.name);
}
```

lists the contents of a directory even if args[1] and the 
filesystem contain names encoded in latin9 (ISO-8859-15). I 
wonder if this behavior can be relied on. Does this use conform 
to the "spirit of D" where strings are assumed to be in in UTF-8 
format [1]?


Second question: Has anybody ever managed to extend std.encoding 
which lacks a latin9 encoding?


[1] https://dlang.org/spec/arrays.html#strings


Re: Can't make inout work.

2019-03-17 Thread aliak via Digitalmars-d-learn

On Sunday, 17 March 2019 at 17:22:13 UTC, Kagamin wrote:

struct S(T) {
T value;
bool opEquals(U:S!V,V)(in U r) const
{ return value==r.value; }
}


Hmm, that actually works for opEquals. But now you just hit the 
same problem with some other construct, unfortunately:


auto x = [make("hello"), S!string("hi")];

same error.



Re: Can't make inout work.

2019-03-17 Thread Paul Backus via Digitalmars-d-learn

On Sunday, 17 March 2019 at 10:49:03 UTC, aliak wrote:

Ah! Thanks! So next problem with that:

import std.stdio;

struct S(T) {
T value;
}

auto make(T)(inout auto ref T val) {
return inout(S!T)(val);
}

void main() {
writeln(make("hello") == S!string("hello"));
}

Error: Error: incompatible types for (make("hello")) == 
(S("hello")): immutable(S!(char[])) and S!string


I think that's just this bug (which is marked as a diagnostic 
for some reason): https://issues.dlang.org/show_bug.cgi?id=19126


Thoughts on any workarounds?


For some reason, when you call `make("hello")`, the template 
argument T is being inferred as char[] instead of string. (You 
can see this by putting `pragma(msg, T)` in the body of make.) It 
works if you instantiate make explicitly with 
`make!string("hello")`.


This seems like a bug to me. If you remove inout from the code, T 
is correctly deduced as string.


Re: Can't make inout work.

2019-03-17 Thread Kagamin via Digitalmars-d-learn

On Saturday, 16 March 2019 at 14:57:35 UTC, Paul Backus wrote:
This code fails to compile if you change `auto s2` to `const 
s2`--in other words, it has the same problem as the original 
example.


Maybe there's not much need for qualifiers anyway.

struct S(T) {
T value;
}

auto make(T)(ref T value) {
return S!T(value);
}

auto f(T)(ref T s) {
return make(s.value);
}

void f() {
class C {}
C c;
auto s1 = S!C(c);
const s2 = make!C(c);
auto s3 = f(s2);
}


Re: Can't make inout work.

2019-03-17 Thread Kagamin via Digitalmars-d-learn

struct S(T) {
T value;
bool opEquals(U:S!V,V)(in U r) const
{ return value==r.value; }
}


Re: Can't make inout work.

2019-03-17 Thread aliak via Digitalmars-d-learn

On Saturday, 16 March 2019 at 03:49:26 UTC, Paul Backus wrote:

On Friday, 15 March 2019 at 23:57:15 UTC, aliak wrote:

Anyone knows how to make this work?


You need an explicit `inout` on the return value of `make`:

auto ref make(T)(inout auto ref T value) {
return inout(S!T)(value);
}


Ah! Thanks! So next problem with that:

import std.stdio;

struct S(T) {
T value;
}

auto make(T)(inout auto ref T val) {
return inout(S!T)(val);
}

void main() {
writeln(make("hello") == S!string("hello"));
}

Error: Error: incompatible types for (make("hello")) == 
(S("hello")): immutable(S!(char[])) and S!string


I think that's just this bug (which is marked as a diagnostic for 
some reason): https://issues.dlang.org/show_bug.cgi?id=19126


Thoughts on any workarounds?


Re: dub getting stuck

2019-03-17 Thread Eugene Wissner via Digitalmars-d-learn

On Sunday, 17 March 2019 at 07:20:47 UTC, Joel wrote:

macOS 10.13.6
dmd 2.085.0
dub 1.3.0

{
"name": "server",
"targetType": "executable",
"description": "A testing D application.",
"sourcePaths" : ["source"],
"dependencies":
{
"vibe-d" : "~>0.8.0"
}
}

void main()
{
import vibe.d;
listenHTTP(":8080", (req, res) {
res.writeBody("Hello, World: " ~ req.path);
});
runApplication();
}


dub -v
..
Sub package vibe-d:diet doesn't exist in vibe-d 0.8.1-alpha.1.


(gets as far as that line?!)

On another program, it gets stuck in a completely different 
situation.


dub 1.3.0 is something old. Is it reproducable with a newer 
version?


Otherwise can be related:

https://github.com/dlang/dub/issues/1345
https://github.com/dlang/dub/issues/1001


dub getting stuck

2019-03-17 Thread Joel via Digitalmars-d-learn

macOS 10.13.6
dmd 2.085.0
dub 1.3.0

{
"name": "server",
"targetType": "executable",
"description": "A testing D application.",
"sourcePaths" : ["source"],
"dependencies":
{
"vibe-d" : "~>0.8.0"
}
}

void main()
{
import vibe.d;
listenHTTP(":8080", (req, res) {
res.writeBody("Hello, World: " ~ req.path);
});
runApplication();
}


dub -v
..
Sub package vibe-d:diet doesn't exist in vibe-d 0.8.1-alpha.1.


(gets as far as that line?!)

On another program, it gets stuck in a completely different 
situation.