Re: curses/ncurses liberary in D

2021-11-02 Thread harakim via Digitalmars-d-learn
On Wednesday, 3 November 2021 at 01:39:02 UTC, H. S. Teoh wrote: On Wed, Nov 03, 2021 at 01:33:28AM +, dangbinghoo via Digitalmars-d-learn wrote: On Wednesday, 3 November 2021 at 00:50:31 UTC, pascal111 wrote: > How can I include "ncurses" liberary in D? I'm using Ubuntu > and GDC!

Re: Using "strcpy" to assign value to dynamic char array

2021-11-02 Thread tsbockman via Digitalmars-d-learn
On Monday, 1 November 2021 at 21:32:21 UTC, Ali Çehreli wrote: Joking aside, I liked the nested struct and its opAssign to mimic internal `arr.length = 42` syntax. (I know it involves a potentially expensive delegate but still...) The nested struct is not needed. UFCS works for setters, too:

Re: A problem in converting C code

2021-11-02 Thread Ali Çehreli via Digitalmars-d-learn
On 11/2/21 6:49 PM, zjh wrote: On Tuesday, 2 November 2021 at 23:02:42 UTC, Ali Çehreli wrote: On 11/2/21 3:57 PM, Ali Çehreli wrote:   const x = readln.strip; this is very interesting .`readln` then `strip;`,Very natural. Yes, UFCS (universal function call syntax) makes code natural,

Re: Using "strcpy" to assign value to dynamic char array

2021-11-02 Thread Steven Schveighoffer via Digitalmars-d-learn
On 11/1/21 9:03 PM, pascal111 wrote: On Monday, 1 November 2021 at 21:32:21 UTC, Ali Çehreli wrote: Joking aside ... This function seems smart and flexible and higher than my current level, I'll study it. Please please, do NOT study this code. It is bad all around. Ali should know

Re: A problem in converting C code

2021-11-02 Thread zjh via Digitalmars-d-learn
On Tuesday, 2 November 2021 at 23:02:42 UTC, Ali Çehreli wrote: On 11/2/21 3:57 PM, Ali Çehreli wrote: const x = readln.strip; this is very interesting .`readln` then `strip;`,Very natural.

Re: curses/ncurses liberary in D

2021-11-02 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Nov 03, 2021 at 01:33:28AM +, dangbinghoo via Digitalmars-d-learn wrote: > On Wednesday, 3 November 2021 at 00:50:31 UTC, pascal111 wrote: > > How can I include "ncurses" liberary in D? I'm using Ubuntu and GDC! > > Search ncurses in Dub registray shows that there's 3 ncurses D >

Re: curses/ncurses liberary in D

2021-11-02 Thread dangbinghoo via Digitalmars-d-learn
On Wednesday, 3 November 2021 at 00:50:31 UTC, pascal111 wrote: How can I include "ncurses" liberary in D? I'm using Ubuntu and GDC! Search ncurses in Dub registray shows that there's 3 ncurses D bingdings. https://code.dlang.org/search?q=ncurses

Re: Completing C code with D style

2021-11-02 Thread pascal111 via Digitalmars-d-learn
On Wednesday, 3 November 2021 at 00:57:38 UTC, Ali Çehreli wrote: On 11/2/21 5:50 PM, Siarhei Siamashka wrote: Your code can be changed to something like this: And I over-engineered it. :) import std.stdio; import std.algorithm; import std.range; import std.exception; import std.format; . .

Re: Completing C code with D style

2021-11-02 Thread pascal111 via Digitalmars-d-learn
On Wednesday, 3 November 2021 at 00:50:51 UTC, Siarhei Siamashka wrote: On Tuesday, 2 November 2021 at 23:45:39 UTC, pascal111 wrote: By "vertical" vs. "horizontal" thinking, do you mean imperative vs. functional style?

Re: Completing C code with D style

2021-11-02 Thread Ali Çehreli via Digitalmars-d-learn
On 11/2/21 5:50 PM, Siarhei Siamashka wrote: Your code can be changed to something like this: And I over-engineered it. :) import std.stdio; import std.algorithm; import std.range; import std.exception; import std.format; // A readable name; corresponds to C's typedef alias FilterFunction =

Re: Completing C code with D style

2021-11-02 Thread pascal111 via Digitalmars-d-learn
On Wednesday, 3 November 2021 at 00:50:51 UTC, Siarhei Siamashka wrote: On Tuesday, 2 November 2021 at 23:45:39 UTC, pascal111 wrote: It's supported in many modern programming languages and it's not a unique feature of the D language alone. Your code can be changed to something like this:

Re: Completing C code with D style

2021-11-02 Thread Siarhei Siamashka via Digitalmars-d-learn
On Tuesday, 2 November 2021 at 23:45:39 UTC, pascal111 wrote: Next code originally was a classic C code I've written, it's pure vertical thinking, now, I converted it successfully to D code, but I think I made no much changes to make it has more horizontal thinking style that it seems D

curses/ncurses liberary in D

2021-11-02 Thread pascal111 via Digitalmars-d-learn
How can I include "ncurses" liberary in D? I'm using Ubuntu and GDC!

Completing C code with D style

2021-11-02 Thread pascal111 via Digitalmars-d-learn
Next code originally was a classic C code I've written, it's pure vertical thinking, now, I converted it successfully to D code, but I think I made no much changes to make it has more horizontal thinking style that it seems D programmers care in horizontal thinking style. Is there any

Re: A problem in converting C code

2021-11-02 Thread pascal111 via Digitalmars-d-learn
On Tuesday, 2 November 2021 at 23:02:42 UTC, Ali Çehreli wrote: On 11/2/21 3:57 PM, Ali Çehreli wrote: Here is a more idiomatic version: import std.stdio; import std.string; void main() { const x = strip(readln()); writeln(x); if (x == "hello world!") { writeln("yes"); } } The

Re: A problem in converting C code

2021-11-02 Thread pascal111 via Digitalmars-d-learn
On Tuesday, 2 November 2021 at 22:57:14 UTC, Ali Çehreli wrote: On 11/2/21 3:36 PM, pascal111 wrote: can we keep the C style of it as it is As you hint, this really is not D but still... :) I had to make three changes: import std.stdio; // Ali - Importing stdin under a different name // to

Re: A problem in converting C code

2021-11-02 Thread Ali Çehreli via Digitalmars-d-learn
On 11/2/21 3:57 PM, Ali Çehreli wrote: Here is a more idiomatic version: import std.stdio; import std.string; void main() { const x = strip(readln()); writeln(x); if (x == "hello world!") { writeln("yes"); } } The first line in main can be written with UFCS syntax as well:

Re: A problem in converting C code

2021-11-02 Thread Ali Çehreli via Digitalmars-d-learn
On 11/2/21 3:36 PM, pascal111 wrote: can we keep the C style of it as it is As you hint, this really is not D but still... :) I had to make three changes: import std.stdio; // Ali - Importing stdin under a different name // to prevent name conflict with std.stdio.stdin; import

A problem in converting C code

2021-11-02 Thread pascal111 via Digitalmars-d-learn
In next program I intend it to be the D version of a C program, but I found some troubles with it, can we keep the C style of it as it is as we can and fix the must-be-fixed parts to make it works under D compiler? // D programming language import std.stdio; import core.stdc.stdio; import

Re: Are there anything like leetcode.com but that supports D?

2021-11-02 Thread Dr Machine Code via Digitalmars-d-learn
On Friday, 29 October 2021 at 17:29:57 UTC, harakim wrote: On Sunday, 24 October 2021 at 05:46:48 UTC, Dr Machine Code wrote: I'd like that to some friends getting start with programming. Sadly that platform doesn't support D. I wouldn't mind helping out by reviewing code or answering

Re: Average function using Variadic Functions method

2021-11-02 Thread Ali Çehreli via Digitalmars-d-learn
On 11/2/21 9:35 AM, pascal111 wrote: > "input..." seems nice, where can I get more information about it? I include most of the language in this free book: http://ddili.org/ders/d.en/index.html which has an Index Section that I find useful to locate information:

Re: Average function using Variadic Functions method

2021-11-02 Thread Mike Parker via Digitalmars-d-learn
On Tuesday, 2 November 2021 at 16:35:40 UTC, pascal111 wrote: "input..." seems nice, where can I get more information about it? "Typesafe variadic functions" https://dlang.org/spec/function.html#typesafe_variadic_functions

Re: Average function using Variadic Functions method

2021-11-02 Thread pascal111 via Digitalmars-d-learn
On Tuesday, 2 November 2021 at 16:29:07 UTC, rikki cattermole wrote: You probably don't want to be using C variadics. Instead try the typed one: float mean(float[] input...) { // you don't want to divide by zero if (input.length == 0) return 0; float

Re: Average function using Variadic Functions method

2021-11-02 Thread rikki cattermole via Digitalmars-d-learn
You probably don't want to be using C variadics. Instead try the typed one: float mean(float[] input...) { // you don't want to divide by zero if (input.length == 0) return 0; float temp = 0; // floats and double initialize to NaN by default, not

Average function using Variadic Functions method

2021-11-02 Thread pascal111 via Digitalmars-d-learn
I'm programming average calculating function by using Variadic Functions method, but I didn't get yet what is the wrong in my code: // D programming language import std.stdio; import core.vararg; import std.conv; float foo(...) { float x=0; for(int i=0; i<_arguments.length; ++i){

Re: __cpuid like in C

2021-11-02 Thread WebFreak001 via Digitalmars-d-learn
On Monday, 1 November 2021 at 16:16:12 UTC, Arsium wrote: On Monday, 1 November 2021 at 16:02:20 UTC, Paul Backus wrote: On Monday, 1 November 2021 at 16:00:05 UTC, Arsium wrote: Hello, Currently, I'm working to implement myself WinAPI functions. However, I could not find anything matching