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

2021-04-07 Thread Ali Çehreli via Digitalmars-d-learn

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



How Add DUB packages path to Dlang Linter to avoid Errors?

2021-04-07 Thread Marcone via Digitalmars-d-learn
When I import modules from dub im my SublimeText, D Linter show 
as errors.

Example:

7:8  error  dmd:Error  module `core` is in file 
'vibe\core\core.d' which cannot be read


How solve it?


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

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

Here an example of using gtkd without dub :
ldc2 -I/usr/local/include/d/gtkd-3 -L-lgtkd-3 -L-ldl hello.d
When you run dub with parameters "--verbose" it informs you what 
is going on.


I have not figured out how to use tkd without dub.
It would be nice to know how.


Re: Database bindings

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

Now I see.
I need to sort the packages by score.
[ There are some dead monkeys in the package database ]


Re: Database bindings

2021-04-07 Thread mw via Digitalmars-d-learn

On Wednesday, 7 April 2021 at 14:52:25 UTC, Alain De Vos wrote:

Let's say I want to connect to the databases :
- tokyokabinet
- redis
- mongodb
- postgresql
- sqlite
- mysql
- couchdb
Which "dub add X" commands should I run for each of them ?


https://code.dlang.org/search?q=database

You need to choose the package(s) you want to use first, e.g. 
tinyredis


then "dub add tinyredis"


Re: Is this bug ? format %(%)

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

On Wednesday, 7 April 2021 at 17:31:09 UTC, Paul Backus wrote:

On Wednesday, 7 April 2021 at 17:04:56 UTC, novice2 wrote:

On Wednesday, 7 April 2021 at 13:43:18 UTC, Paul Backus wrote:

So, you should change your code to

writefln("%-(%s, %)", s);


sorry i dont read docs so carefully
thanks


It's not your fault--this is a pretty obscure feature, and it's 
not documented very well. Even after you've found the correct 
page in the documentation (the page for `formattedWrite` [1]), 
you have to scroll down past multiple examples to find the text 
that explains it.


[1] https://dlang.org/phobos/std_format.html#formattedWrite


I have created a pull request that will hopefully make this more 
prominent on the doc page:

https://github.com/dlang/phobos/pull/7944


Re: Is this bug ? format %(%)

2021-04-07 Thread Berni44 via Digitalmars-d-learn

On Wednesday, 7 April 2021 at 17:31:09 UTC, Paul Backus wrote:
It's not your fault--this is a pretty obscure feature, and it's 
not documented very well. Even after you've found the correct 
page in the documentation (the page for `formattedWrite` [1]), 
you have to scroll down past multiple examples to find the text 
that explains it.


[1] https://dlang.org/phobos/std_format.html#formattedWrite


The docs of `std.format` are currently under strong revision, 
about 90% is already done, but that "feature" is among the other 
10%. I hope to get that ready till the end of the month, so the 
next stable release will have better docs.


Unfortunately it's much more difficult to change that strange 
behavior without breaking code. Currently I hope for Phobos 2.0 
coming soon and meanwhile try to prepare `std.format` for that 
change.


Re: Is this bug ? format %(%)

2021-04-07 Thread Ali Çehreli via Digitalmars-d-learn

On 4/7/21 10:04 AM, novice2 wrote:

On Wednesday, 7 April 2021 at 13:43:18 UTC, Paul Backus wrote:

So, you should change your code to

    writefln("%-(%s, %)", s);


sorry i dont read docs so carefully
thanks


For the sake of completeness, I mention this feature in a couple of 
other places:


  http://ddili.org/ders/d.en/formatted_output.html#ix_formatted_output.%-(

  https://www.youtube.com/watch?v=dRORNQIB2wA=1146s

Ali



Re: Is this bug ? format %(%)

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

On Wednesday, 7 April 2021 at 17:04:56 UTC, novice2 wrote:

On Wednesday, 7 April 2021 at 13:43:18 UTC, Paul Backus wrote:

So, you should change your code to

writefln("%-(%s, %)", s);


sorry i dont read docs so carefully
thanks


It's not your fault--this is a pretty obscure feature, and it's 
not documented very well. Even after you've found the correct 
page in the documentation (the page for `formattedWrite` [1]), 
you have to scroll down past multiple examples to find the text 
that explains it.


[1] https://dlang.org/phobos/std_format.html#formattedWrite


Re: Is this bug ? format %(%)

2021-04-07 Thread novice2 via Digitalmars-d-learn

On Wednesday, 7 April 2021 at 13:43:18 UTC, Paul Backus wrote:

So, you should change your code to

writefln("%-(%s, %)", s);


sorry i dont read docs so carefully
thanks


Database bindings

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

Let's say I want to connect to the databases :
- tokyokabinet
- redis
- mongodb
- postgresql
- sqlite
- mysql
- couchdb
Which "dub add X" commands should I run for each of them ?


Re: Is this bug ? format %(%)

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

On Wednesday, 7 April 2021 at 13:31:59 UTC, novice3 wrote:

there is extra quotes, wich not present in firmat specifier.
is this bug, or i should change something in my code?


This is actually an intentional feature (albeit kind of a stupid 
one). From the documentation:


Inside a compound format specifier, strings and characters are 
escaped automatically. To avoid this behavior, add '-' flag to 
"%(".


So, you should change your code to

writefln("%-(%s, %)", s);


Is this bug ? format %(%)

2021-04-07 Thread novice3 via Digitalmars-d-learn

https://run.dlang.io/is/p4NVp8
```d
void main()
{
import std.stdio: writefln;
string[] s = ["a", "b", "c"];
writefln("%(%s, %)", s);
}
```
output
```d
"a", "b", "c"
```
expected
```d
a, b, c
```

there is extra quotes, wich not present in firmat specifier.
is this bug, or i should change something in my code?


Re: Read X many bytes from File to address Y

2021-04-07 Thread Adam D. Ruppe via Digitalmars-d-learn

On Wednesday, 7 April 2021 at 12:57:12 UTC, tcak wrote:
Well, I have a struct, that is defined as a variable already. I 
want to read X bytes from the file (not Struct.sizeof bytes 
though), and read into the struct variable without any extra 
buffer.


file.rawRead((cast(ubyte*) _struct)[0 .. your_length]);


Of course you can also just use the C function too:

fread(_struct, your_length, 1, file.getFP());


the std.stdio is just a wrapper around FILE* so it offers get FP 
to use for the other things.


It just isn't that different really aside from the little cast.


Re: Gui toolkits alive and gui toolkits dead

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

I meant dlang bindings.


Re: Read X many bytes from File to address Y

2021-04-07 Thread tcak via Digitalmars-d-learn

On Wednesday, 7 April 2021 at 12:50:01 UTC, Adam D. Ruppe wrote:

On Wednesday, 7 April 2021 at 11:42:56 UTC, tcak wrote:
There is rawRead, but it takes an array as parameter, which 
causes a dirty looking code with cast etc!


What did you wrote?


file.rawRead(address[0 .. desiredLength])


should do what you want.


Well, I have a struct, that is defined as a variable already. I 
want to read X bytes from the file (not Struct.sizeof bytes 
though), and read into the struct variable without any extra 
buffer.


Re: Don't allow to reassign, but content is editable

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

struct A
{
private int[] a;
this(int[] b){a=b;}
int[] c(){ return a; }
@disable void opAssign();
}
struct B
{
A a;
this(int){ a=new int[5]; }
int[] b(){ return a.c; }
void f(){ a=new int[5]; }
}


Re: Read X many bytes from File to address Y

2021-04-07 Thread Adam D. Ruppe via Digitalmars-d-learn

On Wednesday, 7 April 2021 at 11:42:56 UTC, tcak wrote:
There is rawRead, but it takes an array as parameter, which 
causes a dirty looking code with cast etc!


What did you wrote?


file.rawRead(address[0 .. desiredLength])


should do what you want.


Re: Don't allow to reassign, but content is editable

2021-04-07 Thread Adam D. Ruppe via Digitalmars-d-learn

On Wednesday, 7 April 2021 at 12:28:25 UTC, tcak wrote:
@property auto b(){ return a.ptr; }  // this is a 
possibility, but results with overhead of calling. Also, b is 
not an array anymore, just int*.


Why are you returning a.ptr instead of just a?

If you return just a, it works fine for what you want.


You can virtually guarantee no calling overhead by simply making 
that `final`; then it is easy for the compiler to inline in all 
cases.


Don't allow to reassign, but content is editable

2021-04-07 Thread tcak via Digitalmars-d-learn
In javascript, with "const" keyword, you assign an object to a 
variable. Later, you cannot assign anything else to that 
variable, but content of it still can be changed. No matter by 
using "immutable" or "const", I cannot imitate that. Is there a 
way to do this without an overhead (like calling a function to 
create a pointer)?


Example:

class Test
{
public int[] a;

public this(){ a = new int[5]; }

@property auto b(){ return a.ptr; }  // this is a 
possibility, but results with overhead of calling. Also, b is not 
an array anymore, just int*.

}

I want this to be possible:
test.a[3] = 7;

But this wouldn't be allowed:
test.a = new int[14];



Read X many bytes from File to address Y

2021-04-07 Thread tcak via Digitalmars-d-learn

I am talking about std.file.File.

I have opened the file, and at a specific offset.

I want to read X many bytes from the file, and want it to be 
written to given address directly without any Magical D-stuff 
like ranges etc.


Is there a way to do this without getting into C or Posix header 
files?


There is rawRead, but it takes an array as parameter, which 
causes a dirty looking code with cast etc!


Re: Vibe.d tutorial

2021-04-07 Thread M.M. via Digitalmars-d-learn

On Friday, 2 April 2021 at 22:29:20 UTC, Imperatorn wrote:

On Thursday, 4 March 2021 at 13:47:11 UTC, Imperatorn wrote:

On Monday, 1 March 2021 at 22:25:39 UTC, Rey Valeza wrote:
Hi, I wrote a tutorial on Vibe.d while trying to re-learn 
Vibe.d. I find that most of Kai Nacke's book need updating, 
so I wrote a tutorial while trying to re-learn it.


Here it is.

https://github.com/reyvaleza/vibed/commit/27ec3678f25d1dd414fae1390677397a7bc57721

I would be glad if you can give me some feedback so I can 
improve it.


Thanks!


https://github.com/reyvaleza/vibed/blob/main/Build%20Web%20Apps%20in%20Vibe.pdf


New link:
https://raw.githubusercontent.com/reyvaleza/vibed/main/BuildWebAppsinVibe.pdf


Looks like a really lot of work. Updating books/notes as the 
language/software advances is a tedious work which often gets 
forgotten... So cudos to you.


I think you could also post to "Announcement" section of the 
dlang forum for a much better visibility.


Re: Gui toolkits alive and gui toolkits dead

2021-04-07 Thread Jacob Carlborg via Digitalmars-d-learn

On 2021-04-06 21:57, Alain De Vos wrote:

Can we say tk ang gtk toolkits are alive.
But wxwidgets , fox an fltk are dead ?


Do you mean these libraries in general or D bindings to these libraries?

--
/Jacob Carlborg