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

2021-04-08 Thread evilrat via Digitalmars-d-learn

On Thursday, 8 April 2021 at 21:36:02 UTC, Alain De Vos wrote:

The most important task is
"give me a list of to include .d files"
"give me a list of the link libraries .a .so"


sure, use -v flag, this will give you compiler flags and other 
info

```
   dub build -v
```
this will give you extensive build information in json
```
   dub describe
```
also if you don't like dub going internet just add this flag
```
   --skip-registry=all
```


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

2021-04-08 Thread Paul Backus via Digitalmars-d-learn

On Thursday, 8 April 2021 at 22:27:38 UTC, Alain De Vos wrote:

So which concrete types do you give for the two auto's.


The first `auto` is the return type of `to!(ubyte[])`--so, it's 
`ubyte[]`.


The second `auto` is the return type of `map`. If you look at the 
documentation [2], you'll see that it doesn't give a concrete 
type for the return value; it just says that `map` returns "an 
input range." That's because the concrete type is a so-called 
"Voldemort type" [1]--a type whose name is private to the 
function, and can't be used externally.


Why use such a type? Because it gives the authors of `map` the 
freedom to change the concrete type without breaking code that 
uses `map`, as long as the type they change it to still supports 
the input range interface.


[1] https://wiki.dlang.org/Voldemort_types
[2] 
https://phobos.dpldocs.info/std.algorithm.iteration.map.map.html


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

2021-04-08 Thread Alain De Vos via Digitalmars-d-learn

So which concrete types do you give for the two auto's.


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

2021-04-08 Thread Imperatorn via Digitalmars-d-learn

On Thursday, 8 April 2021 at 22:02:47 UTC, Alain De Vos wrote:

I resume in the 4 ways presented,

import std;
void main(){
auto a=[1,0,1,1,1,0,1,0,1,1,1,0];

string s = format!"%-(%s%)"(a);
writeln(s);

dchar[12] b = a.map!(to!string).joiner.array;
writeln(b);

auto conv = a.to!(ubyte[]);
conv[]+='0';
   writeln(cast(string)conv);

auto r = a.map!(i => cast(char)(i + '0'));
writeln(r);
}

Why do the last two ways need "auto" as type ?


auto is not a type, it's inferring the type, like var in C#. It's 
just convenient, saves you a few keystrokes.


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

2021-04-08 Thread Alain De Vos via Digitalmars-d-learn

I resume in the 4 ways presented,

import std;
void main(){
auto a=[1,0,1,1,1,0,1,0,1,1,1,0];

string s = format!"%-(%s%)"(a);
writeln(s);

dchar[12] b = a.map!(to!string).joiner.array;
writeln(b);

auto conv = a.to!(ubyte[]);
conv[]+='0';
   writeln(cast(string)conv);

auto r = a.map!(i => cast(char)(i + '0'));
writeln(r);
}

Why do the last two ways need "auto" as type ?


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

2021-04-08 Thread Alain De Vos via Digitalmars-d-learn

The most important task is
"give me a list of to include .d files"
"give me a list of the link libraries .a .so"


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

2021-04-08 Thread Alain De Vos via Digitalmars-d-learn

I think it should always be possible to build "offline".
dub does stuff and I don't now what.


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 s = a.map!(i => cast(char)(i + '0')).array;
writeln(s);

Or better yet, if you just want to output it and don't need to store the
array, just use the range directly:

int a = [1, 0, 1, 0, 1, ...];
auto r = a.map!(i => cast(char)(i + '0'));
writeln(r);


T

-- 
People say I'm arrogant, and I'm proud of it.


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

2021-04-08 Thread Kagamin via Digitalmars-d-learn

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?


Theoretically an rdmd-like tool can automatically infer 
dependencies from imports (autodub?). But it can also easily 
expose you to a supply chain attack.


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

2021-04-08 Thread Alain De Vos via Digitalmars-d-learn
The ascii code of 0 is 48 so I think you can add everywhere 48 
(but I'm not a specialist)


Re: Gui toolkits alive and gui toolkits dead

2021-04-08 Thread Imperatorn via Digitalmars-d-learn

On Wednesday, 7 April 2021 at 13:00:37 UTC, Alain De Vos wrote:

I meant dlang bindings.


Is the binding dead or alive, Schrödinger's binding. Who knows...


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

2021-04-08 Thread Meta via Digitalmars-d-learn

On Thursday, 8 April 2021 at 18:01:56 UTC, Meta wrote:

On Thursday, 8 April 2021 at 12:19:29 UTC, WebFreak001 wrote:


```d
string to01String(int[] x) @safe
{
auto conv = x.to!(ubyte[]); // allocates new array, so 
later cast to string is OK
conv[] += '0'; // assume all numbers are 0-9, then this 
gives the correct result

return (() @trusted => cast(string)conv)();
}
```


The @trusted lambda can also be replaced with 
[std.exception.assumeUnique](https://dlang.org/library/std/exception/assume_unique.html).


Never mind me, assumeUnique is @system (or at least it's inferred 
as @system), and anyway, you can't implicitly convert 
`immutable(ubyte)[]` to `immutable(char)[]`.


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

2021-04-08 Thread Meta via Digitalmars-d-learn

On Thursday, 8 April 2021 at 12:19:29 UTC, WebFreak001 wrote:


```d
string to01String(int[] x) @safe
{
auto conv = x.to!(ubyte[]); // allocates new array, so 
later cast to string is OK
conv[] += '0'; // assume all numbers are 0-9, then this 
gives the correct result

return (() @trusted => cast(string)conv)();
}
```


The @trusted lambda can also be replaced with 
[std.exception.assumeUnique](https://dlang.org/library/std/exception/assume_unique.html).


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

2021-04-08 Thread Jack via Digitalmars-d-learn

On Thursday, 8 April 2021 at 16:45:14 UTC, Jack wrote:

On Thursday, 8 April 2021 at 04:02:26 UTC, Ali Çehreli wrote:

On 4/7/21 8:57 PM, Brad wrote:


     auto a = [1,0,1,1,1,0,1,0,1,1,1,1,0];


I want to come out of this with a string that looks like 
this: 101110100


Me, me, me, me! :)

import std;
void main()
{
  auto a = [1,0,1,1,1,0,1,0,1,1,1,1,0];

  string s = format!"%-(%s%)"(a);
  writeln(s);
}

Ali


What does %-%s% do?


nevermind, someone just asked this too[1]

[1]: 
https://forum.dlang.org/thread/immypqwvbealjqrvb...@forum.dlang.org





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

2021-04-08 Thread Jack via Digitalmars-d-learn

On Thursday, 8 April 2021 at 04:02:26 UTC, Ali Çehreli wrote:

On 4/7/21 8:57 PM, Brad wrote:


     auto a = [1,0,1,1,1,0,1,0,1,1,1,1,0];


I want to come out of this with a string that looks like this: 
101110100


Me, me, me, me! :)

import std;
void main()
{
  auto a = [1,0,1,1,1,0,1,0,1,1,1,1,0];

  string s = format!"%-(%s%)"(a);
  writeln(s);
}

Ali


What does %-%s% do?


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

2021-04-08 Thread WebFreak001 via Digitalmars-d-learn

On Thursday, 8 April 2021 at 03:57:23 UTC, Brad wrote:
I am trying to take an array and convert it to a string.  I 
know that Split will let me easily go the other way.  I 
searched for the converse of Split but have not been able to 
locate it.  I can think of two brute force methods of doing 
this.  I found an answer to something similar in the forum and 
adapted it - but it is so much code for such a simple procedure:


```d
import std;
void main()
{
auto a = [1,0,1,1,1,0,1,0,1,1,1,1,0];

string b = to!string(a.map!(to!string)
 .chunks(a.length)
 .map!join);

string f = b[2..b.length-2];  //needed to strip the first 
two and las two characters

writeln(f);

}
```

I want to come out of this with a string that looks like this: 
101110100


Thanks in advance.


```d
string to01String(int[] x) @safe
{
auto conv = x.to!(ubyte[]); // allocates new array, so later 
cast to string is OK
conv[] += '0'; // assume all numbers are 0-9, then this gives 
the correct result

return (() @trusted => cast(string)conv)();
}
```