Re: Template specialized functions creating runtime instructions?

2019-08-20 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, August 20, 2019 5:48:04 PM MDT ads via Digitalmars-d-learn wrote: > This piece of code creates a fizzbuzz string with template > parameters. > > auto fizzbuzz(uint N)() { > string accumulate; > return fizzbuzz!N(accumulate); > } > > auto fizzbuzz(uint N)(ref string result) if (N %

Re: Template specialized functions creating runtime instructions?

2019-08-20 Thread ag0aep6g via Digitalmars-d-learn
On 21.08.19 01:48, ads wrote: This piece of code creates a fizzbuzz string with template parameters. auto fizzbuzz(uint N)() { string accumulate; return fizzbuzz!N(accumulate); } auto fizzbuzz(uint N)(ref string result) if (N % 3 && N % 5) { import std.conv : to; result ~=

Re: Template specialized functions creating runtime instructions?

2019-08-20 Thread ads via Digitalmars-d-learn
On Wednesday, 21 August 2019 at 00:04:37 UTC, H. S. Teoh wrote: On Tue, Aug 20, 2019 at 11:48:04PM +, ads via Digitalmars-d-learn wrote: [...] 2) Deducing the string as you describe would require CTFE (compile-time function evaluation), which usually isn't done unless the result is

Re: Template specialized functions creating runtime instructions?

2019-08-20 Thread ads via Digitalmars-d-learn
On Tuesday, 20 August 2019 at 23:48:04 UTC, ads wrote: https://godbolt.org/z/hWENgc A somewhat similar translation in C++ also creates a lot of runtime instructions https://godbolt.org/z/psyUtq

Re: Template specialized functions creating runtime instructions?

2019-08-20 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Aug 20, 2019 at 11:48:04PM +, ads via Digitalmars-d-learn wrote: [...] > In the generated assembly, it looks like it is creating a lot of > runtime instructions, contrary to my belief that templated codes are > purely compile-time. I was expecting that the compiler would deduce > the

Template specialized functions creating runtime instructions?

2019-08-20 Thread ads via Digitalmars-d-learn
This piece of code creates a fizzbuzz string with template parameters. auto fizzbuzz(uint N)() { string accumulate; return fizzbuzz!N(accumulate); } auto fizzbuzz(uint N)(ref string result) if (N % 3 && N % 5) { import std.conv : to; result ~= N.to!string ~

Re: How to set a global var to a user defined section.

2019-08-20 Thread kinke via Digitalmars-d-learn
On Tuesday, 20 August 2019 at 17:33:17 UTC, lili wrote: Hi: With gcc we can use _ attribute _((section("name")) var; how to same in dlang? As for C(++), not standardized in the language itself. With LDC: import ldc.attributes : section; @section("name") __gshared int myGlobal;

Re: Linker errors to Windows functions

2019-08-20 Thread Vladimirs Nordholm via Digitalmars-d-learn
On Tuesday, 20 August 2019 at 17:29:15 UTC, Dennis wrote: On Tuesday, 20 August 2019 at 17:17:01 UTC, Vladimirs Nordholm wrote: [...] Importing only specifies that you expect the symbols to be there, it doesn't mean the functions are linked in. [...] Thank you for the explanation Dennis.

How to set a global var to a user defined section.

2019-08-20 Thread lili via Digitalmars-d-learn
Hi: With gcc we can use _ attribute _((section("name")) var; how to same in dlang?

Re: Linker errors to Windows functions

2019-08-20 Thread Dennis via Digitalmars-d-learn
On Tuesday, 20 August 2019 at 17:17:01 UTC, Vladimirs Nordholm wrote: In code I have `import core.sys.windows.winuser;`, but still get this error. Importing only specifies that you expect the symbols to be there, it doesn't mean the functions are linked in. On Windows there are three

Linker errors to Windows functions

2019-08-20 Thread Vladimirs Nordholm via Digitalmars-d-learn
Hello. I recently reinstalled Windows 10 (build 1903), and downloaded DMD (v2.087.1) and dub (v1.16.0). My project no longer compiles, giving the following errors: error LNK2019: unresolved external symbol GetSystemMetrics referenced in [...] error LNK2019: unresolved external

Re: Downloading a file and showing progress via curl.

2019-08-20 Thread Vladimir Panteleev via Digitalmars-d-learn
On Tuesday, 20 August 2019 at 11:51:03 UTC, Daniel Kozak wrote: For that you can use https://dlang.org/phobos/std_file#append Don't do that. It will reopen and close the file on every received chunk. Not only is it slow, but if the file is renamed/moved/deleted while the download is

Re: What is "dmd" Internal API, can I use it just like std Library Reference?

2019-08-20 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Aug 20, 2019 at 12:52:31PM +, BoQsc via Digitalmars-d-learn wrote: [...] > I found https://dlang.org/phobos/dmd_console.html and wanted to use > it. But it seems I'm not being successful, and I do not understand > why. [...] Because this is code inside the compiler, when you're

Re: What is "dmd" Internal API, can I use it just like std Library Reference?

2019-08-20 Thread a11e99z via Digitalmars-d-learn
On Tuesday, 20 August 2019 at 12:52:31 UTC, BoQsc wrote: Hello everyone, again, I had an idea that I want some colors in the output of Command Line (For Windows) and the Terminal (For Linux) yesterday was talks about terminal colors in IRC-channel: u can use VT-codes for changing colors:

Re: How do I execute a sql-file inside D code

2019-08-20 Thread Andre Pany via Digitalmars-d-learn
On Tuesday, 20 August 2019 at 11:33:33 UTC, Anders S wrote: I'm creating an application that connect to a database and write data from another application. Now when I start the application I want it to check if the database exists and if not create the database and it's tables. I have

Re: What is "dmd" Internal API, can I use it just like std Library Reference?

2019-08-20 Thread Daniel Kozak via Digitalmars-d-learn
On Tue, Aug 20, 2019 at 2:55 PM BoQsc via Digitalmars-d-learn wrote: > > Hello everyone, again, > > I had an idea that I want some colors in the output of Command > Line (For Windows) and > the Terminal (For Linux) > > I found https://dlang.org/phobos/dmd_console.html and wanted to > use it. >

Re: What is "dmd" Internal API, can I use it just like std Library Reference?

2019-08-20 Thread Adam D. Ruppe via Digitalmars-d-learn
On Tuesday, 20 August 2019 at 12:52:31 UTC, BoQsc wrote: And the output says that, dmd.console; do not exist? These are for when you are working on the compiler's source itself.

What is "dmd" Internal API, can I use it just like std Library Reference?

2019-08-20 Thread BoQsc via Digitalmars-d-learn
Hello everyone, again, I had an idea that I want some colors in the output of Command Line (For Windows) and the Terminal (For Linux) I found https://dlang.org/phobos/dmd_console.html and wanted to use it. But it seems I'm not being successful, and I do not understand why. Here, you can

Re: Downloading a file and showing progress via curl.

2019-08-20 Thread BoQsc via Digitalmars-d-learn
On Tuesday, 20 August 2019 at 11:51:03 UTC, Daniel Kozak wrote: For that you can use https://dlang.org/phobos/std_file#append Thank you, seems to work. import std.net.curl : HTTP; import std.stdio: writeln; import std.file : append; void main() { auto http = HTTP(); // Track

Re: Downloading a file and showing progress via curl.

2019-08-20 Thread Daniel Kozak via Digitalmars-d-learn
On Tue, Aug 20, 2019 at 1:40 PM BoQsc via Digitalmars-d-learn wrote: > > Hello everyone, > I found this snippet on > https://dlang.org/phobos/std_net_curl.html#.HTTP > > > import std.net.curl : HTTP; > > import std.stdio : writeln; > > > > void main() > > { > > auto http = HTTP(); > > //

Re: Downloading a file and showing progress via curl.

2019-08-20 Thread Daniel Kozak via Digitalmars-d-learn
On Tue, Aug 20, 2019 at 1:46 PM Daniel Kozak wrote: > > On Tue, Aug 20, 2019 at 1:40 PM BoQsc via Digitalmars-d-learn > wrote: > > > > Hello everyone, > > I found this snippet on > > https://dlang.org/phobos/std_net_curl.html#.HTTP > > > > > import std.net.curl : HTTP; > > > import std.stdio :

Downloading a file and showing progress via curl.

2019-08-20 Thread BoQsc via Digitalmars-d-learn
Hello everyone, I found this snippet on https://dlang.org/phobos/std_net_curl.html#.HTTP import std.net.curl : HTTP; import std.stdio : writeln; void main() { auto http = HTTP(); // Track progress http.method = HTTP.Method.get; http.url =

How do I execute a sql-file inside D code

2019-08-20 Thread Anders S via Digitalmars-d-learn
I'm creating an application that connect to a database and write data from another application. Now when I start the application I want it to check if the database exists and if not create the database and it's tables. I have everything working IF the database and tables exist. Use this code

Blog Post #63 - Saving Images with Cairo

2019-08-20 Thread Ron Tarrant via Digitalmars-d-learn
Today we look at how to save images using Cairo with examples for JPeg, PNG, BMP, and TIFF. https://gtkdcoding.com/2019/08/20/0063-cairo-vii-draw-save-images.html

Re: Can't add a const ubyte to a dynamic array of ubyte?

2019-08-20 Thread a11e99z via Digitalmars-d-learn
On Tuesday, 20 August 2019 at 09:49:21 UTC, Daniel Kozak wrote: On Tue, Aug 20, 2019 at 11:30 AM ads via Digitalmars-d-learn wrote: you do not allow a person to think about a problem (and it’s easy here). you carried him through a puddle now, but when he dives into Sea D, you will not be

Re: Can't add a const ubyte to a dynamic array of ubyte?

2019-08-20 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, August 20, 2019 3:27:36 AM MDT ads via Digitalmars-d-learn wrote: > import std.stdio; > > ubyte[] extend(in uint[] arr) > { > ubyte[] result; > foreach (n; arr) > { > if (n < 10) > { > result ~= n; > // source/app.d(10,11): Error:

Re: Can't add a const ubyte to a dynamic array of ubyte?

2019-08-20 Thread a11e99z via Digitalmars-d-learn
On Tuesday, 20 August 2019 at 09:27:36 UTC, ads wrote: import std.stdio; ubyte[] extend(in uint[] arr) { ubyte[] result; foreach (n; arr) { if (n < 10) result ~= n; else {

Re: Can't add a const ubyte to a dynamic array of ubyte?

2019-08-20 Thread Daniel Kozak via Digitalmars-d-learn
On Tue, Aug 20, 2019 at 11:30 AM ads via Digitalmars-d-learn wrote: > > > How can I get around this? I want to ensure that the array is not > mutated in the function in the signature too. > https://run.dlang.io/is/tehp3j import std.stdio; ubyte[] extend(in uint[] arr) { ubyte[] result;

Exercism, call for mentors

2019-08-20 Thread Björn Lindström via Digitalmars-d-learn
Hello, I've recently decided to pick up D, and have started doing some exercises on https://exercism.io/ (a non-profit programming exercise platform), which I think is an excellent way to pick up the basics in a new language. While doing the exercises on my own is rewarding already, I would

Can't add a const ubyte to a dynamic array of ubyte?

2019-08-20 Thread ads via Digitalmars-d-learn
import std.stdio; ubyte[] extend(in uint[] arr) { ubyte[] result; foreach (n; arr) { if (n < 10) { result ~= n; // source/app.d(10,11): Error: cannot append type const(uint) to type ubyte[]