"if" statement

2019-03-24 Thread Francesco Mecca via Digitalmars-d-learn
https://run.dlang.io/is/zRcj59 ``` alias Alg = Algebraic!(int, string); void main() { int n = 2; Alg value; value = n == 2 ? 2 : "string"; } ``` The original code used SumType but the effect is the same. I suppose that I could write the following: ``` if(n == 2) value = 2

Re: "if" statement

2019-03-24 Thread ag0aep6g via Digitalmars-d-learn
On 24.03.19 13:45, Francesco Mecca wrote: ``` alias Alg = Algebraic!(int, string); void main() { int n = 2;     Alg value;     value = n == 2 ? 2 : "string"; } ``` The original code used SumType but the effect is the same. I suppose that I could write the following: ```     if(n == 2

Re: "if" statement

2019-03-25 Thread Benjamin Schaaf via Digitalmars-d-learn
On Sunday, 24 March 2019 at 12:45:13 UTC, Francesco Mecca wrote: https://run.dlang.io/is/zRcj59 ``` alias Alg = Algebraic!(int, string); void main() { int n = 2; Alg value; value = n == 2 ? 2 : "string"; } ``` The original code used SumType but the effect is the same. I suppo

Re: "if" statement

2019-03-25 Thread Michelle Long via Digitalmars-d-learn
On Sunday, 24 March 2019 at 12:45:13 UTC, Francesco Mecca wrote: https://run.dlang.io/is/zRcj59 ``` alias Alg = Algebraic!(int, string); void main() { int n = 2; Alg value; value = n == 2 ? 2 : "string"; } ``` The original code used SumType but the effect is the same. I suppo

Variable below zero but if statement doesn't grab?

2015-12-27 Thread TheDGuy via Digitalmars-d-learn
Any idea what i am doing wrong? https://www.youtube.com/watch?v=j_VCa-5VeP8

type of if statement used for operator overloading?

2013-02-05 Thread Jeremy DeHaan
I've seen operator overloading done 3 different ways. In the examples I provide they all compile and work as far as I can tell. Is there any major difference between using a static if vs a regular if, or any situation that one would be better than the other? struct Something1 { Something1

Re: Variable below zero but if statement doesn't grab?

2015-12-27 Thread TheDGuy via Digitalmars-d-learn
On Sunday, 27 December 2015 at 16:00:34 UTC, jkpl wrote: On Sunday, 27 December 2015 at 15:53:55 UTC, TheDGuy wrote: Any idea what i am doing wrong? https://www.youtube.com/watch?v=j_VCa-5VeP8 You could post the code also, personnaly I'm always almost at 2 meters from my screen, with zoom, so

Re: Variable below zero but if statement doesn't grab?

2015-12-27 Thread jkpl via Digitalmars-d-learn
On Sunday, 27 December 2015 at 15:53:55 UTC, TheDGuy wrote: Any idea what i am doing wrong? https://www.youtube.com/watch?v=j_VCa-5VeP8 You could post the code also, personnaly I'm always almost at 2 meters from my screen, with zoom, so I can't read the code...

Re: Variable below zero but if statement doesn't grab?

2015-12-27 Thread SimonN via Digitalmars-d-learn
On Sunday, 27 December 2015 at 16:01:37 UTC, TheDGuy wrote: Sry: if((x1 < 0) & (x2 >= 0)){ This looks like a bug, with & instead of &&. -- Simon

Re: Variable below zero but if statement doesn't grab?

2015-12-27 Thread TheDGuy via Digitalmars-d-learn
On Sunday, 27 December 2015 at 16:39:18 UTC, SimonN wrote: On Sunday, 27 December 2015 at 16:01:37 UTC, TheDGuy wrote: Sry: if((x1 < 0) & (x2 >= 0)){ This looks like a bug, with & instead of &&. -- Simon It looks like the debugger is not working correctly because i

Re: Variable below zero but if statement doesn't grab?

2015-12-27 Thread SimonN via Digitalmars-d-learn
On Sunday, 27 December 2015 at 16:41:10 UTC, TheDGuy wrote: It looks like the debugger is not working correctly because i changed the code to this: [...] and the same problem appears. I can't watch youtube here. What numbers does your input generate? Which 'if' doesn't fire? What results woul

Re: Variable below zero but if statement doesn't grab?

2015-12-27 Thread TheDGuy via Digitalmars-d-learn
does your input generate? Which 'if' doesn't fire? What results would you like instead? -- Simon I don't understand why my program goes into the if statement if the debugger shows, that the variable "discriminant" is below zero even though: "if(discriminant > 0)"?

Re: Variable below zero but if statement doesn't grab?

2015-12-27 Thread SimonN via Digitalmars-d-learn
On Sunday, 27 December 2015 at 16:52:39 UTC, TheDGuy wrote: I don't understand why my program goes into the if statement if the debugger shows, that the variable "discriminant" is below zero even though: "if(discriminant > 0)"? I have a hard time believing this.

Re: Variable below zero but if statement doesn't grab?

2015-12-27 Thread Bubbasaur via Digitalmars-d-learn
On Sunday, 27 December 2015 at 15:53:55 UTC, TheDGuy wrote: Any idea what i am doing wrong? https://www.youtube.com/watch?v=j_VCa-5VeP8 Tell me one thing, what is the value returned? Well It's working here: http://dpaste.dzfl.pl/18b27ea26b08 Maybe you would like to change the code above to l

Re: Variable below zero but if statement doesn't grab?

2015-12-27 Thread TheDGuy via Digitalmars-d-learn
fl.pl/18b27ea26b08 Maybe you would like to change the code above to look like yours and see what happens? Bubba. Okay, thanks. It actually returned the right value but it looked like as if it would jump into the 2nd if-statement (as you can see on the video). Strange...

Re: Variable below zero but if statement doesn't grab?

2015-12-27 Thread Ali Çehreli via Digitalmars-d-learn
On 12/27/2015 07:53 AM, TheDGuy wrote: Any idea what i am doing wrong? https://www.youtube.com/watch?v=j_VCa-5VeP8 YouTube says that the video has been removed by the user. That's exactly the reason why I don't like even dpaste. There is no guarantee that such threads will be useful forever.

Re: Variable below zero but if statement doesn't grab?

2015-12-27 Thread TheDGuy via Digitalmars-d-learn
On Sunday, 27 December 2015 at 22:51:27 UTC, Ali Çehreli wrote: On 12/27/2015 07:53 AM, TheDGuy wrote: Any idea what i am doing wrong? https://www.youtube.com/watch?v=j_VCa-5VeP8 YouTube says that the video has been removed by the user. That's exactly the reason why I don't like even dpaste.

Re: Variable below zero but if statement doesn't grab?

2015-12-28 Thread jkpl via Digitalmars-d-learn
On Sunday, 27 December 2015 at 16:00:34 UTC, jkpl wrote: On Sunday, 27 December 2015 at 15:53:55 UTC, TheDGuy wrote: Any idea what i am doing wrong? https://www.youtube.com/watch?v=j_VCa-5VeP8 You could post the code also, personnaly I'm always almost at 2 meters from my screen, with zoom, so

Re: Variable below zero but if statement doesn't grab?

2015-12-28 Thread Basile B. via Digitalmars-d-learn
On Monday, 28 December 2015 at 15:07:08 UTC, jkpl wrote: On Sunday, 27 December 2015 at 16:00:34 UTC, jkpl wrote: On Sunday, 27 December 2015 at 15:53:55 UTC, TheDGuy wrote: Any idea what i am doing wrong? https://www.youtube.com/watch?v=j_VCa-5VeP8 You could post the code also, personnaly I'

Re: Variable below zero but if statement doesn't grab?

2015-12-28 Thread rumbu via Digitalmars-d-learn
On Sunday, 27 December 2015 at 23:24:55 UTC, TheDGuy wrote: On Sunday, 27 December 2015 at 22:51:27 UTC, Ali Çehreli wrote: On 12/27/2015 07:53 AM, TheDGuy wrote: Any idea what i am doing wrong? https://www.youtube.com/watch?v=j_VCa-5VeP8 YouTube says that the video has been removed by the us

Re: Variable below zero but if statement doesn't grab?

2015-12-28 Thread jkpl via Digitalmars-d-learn
On Monday, 28 December 2015 at 15:50:06 UTC, Basile B. wrote: On Monday, 28 December 2015 at 15:07:08 UTC, jkpl wrote: On Sunday, 27 December 2015 at 16:00:34 UTC, jkpl wrote: On Sunday, 27 December 2015 at 15:53:55 UTC, TheDGuy wrote: Any idea what i am doing wrong? https://www.youtube.com/wa

Re: Variable below zero but if statement doesn't grab?

2015-12-28 Thread jkpl via Digitalmars-d-learn
On Monday, 28 December 2015 at 18:02:53 UTC, jkpl wrote: On Monday, 28 December 2015 at 15:50:06 UTC, Basile B. wrote: On Monday, 28 December 2015 at 15:07:08 UTC, jkpl wrote: On Sunday, 27 December 2015 at 16:00:34 UTC, jkpl wrote: On Sunday, 27 December 2015 at 15:53:55 UTC, TheDGuy wrote:

Re: Variable below zero but if statement doesn't grab?

2015-12-28 Thread jkpl via Digitalmars-d-learn
On Monday, 28 December 2015 at 18:12:24 UTC, jkpl wrote: On Monday, 28 December 2015 at 18:02:53 UTC, jkpl wrote: On Monday, 28 December 2015 at 15:50:06 UTC, Basile B. wrote: On Monday, 28 December 2015 at 15:07:08 UTC, jkpl wrote: On Sunday, 27 December 2015 at 16:00:34 UTC, jkpl wrote: On

Re: Variable below zero but if statement doesn't grab?

2015-12-28 Thread jkpl via Digitalmars-d-learn
On Monday, 28 December 2015 at 18:33:16 UTC, jkpl wrote: On Monday, 28 December 2015 at 18:12:24 UTC, jkpl wrote: On Monday, 28 December 2015 at 18:02:53 UTC, jkpl wrote: On Monday, 28 December 2015 at 15:50:06 UTC, Basile B. wrote: On Monday, 28 December 2015 at 15:07:08 UTC, jkpl wrote: On

Re: Variable below zero but if statement doesn't grab?

2015-12-28 Thread jkpl via Digitalmars-d-learn
On Monday, 28 December 2015 at 19:22:00 UTC, jkpl wrote: On Monday, 28 December 2015 at 18:33:16 UTC, jkpl wrote: On Monday, 28 December 2015 at 18:12:24 UTC, jkpl wrote: On Monday, 28 December 2015 at 18:02:53 UTC, jkpl wrote: On Monday, 28 December 2015 at 15:50:06 UTC, Basile B. wrote: On

Re: Variable below zero but if statement doesn't grab?

2015-12-28 Thread TheDGuy via Digitalmars-d-learn
Get used to it :) Unfortunately, DMD is not emitting the best debug information. The program flow is correct, but the line info is not, that's why the execution step will not be triggered in the real location of the source code. The simplest example is this: import std.stdio; void foo(int x)

Re: Variable below zero but if statement doesn't grab?

2015-12-31 Thread Marcel mauss via Digitalmars-d-learn
On Monday, 28 December 2015 at 18:02:53 UTC, jkpl wrote: On Monday, 28 December 2015 at 15:50:06 UTC, Basile B. wrote: On Monday, 28 December 2015 at 15:07:08 UTC, jkpl wrote: On Sunday, 27 December 2015 at 16:00:34 UTC, jkpl wrote: On Sunday, 27 December 2015 at 15:53:55 UTC, TheDGuy wrote:

Re: Variable below zero but if statement doesn't grab?

2016-01-05 Thread Basile B. via Digitalmars-d-learn
On Monday, 28 December 2015 at 18:02:53 UTC, jkpl wrote: On Monday, 28 December 2015 at 15:50:06 UTC, Basile B. wrote: On Monday, 28 December 2015 at 15:07:08 UTC, jkpl wrote: On Sunday, 27 December 2015 at 16:00:34 UTC, jkpl wrote: On Sunday, 27 December 2015 at 15:53:55 UTC, TheDGuy wrote:

Re: Variable below zero but if statement doesn't grab?

2016-01-15 Thread Basile B. via Digitalmars-d-learn
On Tuesday, 5 January 2016 at 23:52:05 UTC, Basile B. wrote: On Monday, 28 December 2015 at 18:02:53 UTC, jkpl wrote: On Monday, 28 December 2015 at 15:50:06 UTC, Basile B. wrote: On Monday, 28 December 2015 at 15:07:08 UTC, jkpl wrote: On Sunday, 27 December 2015 at 16:00:34 UTC, jkpl wrote:

can't access an alias created inside an if statement

2020-08-05 Thread Flade via Digitalmars-d-learn
I have used an if-else statement to create an alias to avoid code duplication but it doesn't let me access it outside the if statement. Is there a way to solve this?

Re: type of if statement used for operator overloading?

2013-02-05 Thread Jonathan M Davis
On Wednesday, February 06, 2013 07:24:10 Jeremy DeHaan wrote: > I've seen operator overloading done 3 different ways. In the > examples I provide they all compile and work as far as I can > tell. Is there any major difference between using a static if vs > a regular if, or any situation that one wo

Re: type of if statement used for operator overloading?

2013-02-05 Thread Jeremy DeHaan
On Wednesday, 6 February 2013 at 06:38:11 UTC, Jonathan M Davis wrote: On Wednesday, February 06, 2013 07:24:10 Jeremy DeHaan wrote: I've seen operator overloading done 3 different ways. In the examples I provide they all compile and work as far as I can tell. Is there any major difference betwe

Re: type of if statement used for operator overloading?

2013-02-05 Thread Jonathan M Davis
On Wednesday, February 06, 2013 08:41:14 Jeremy DeHaan wrote: > Out of curiosity, what exactly happens when we don't constrain > what operators are being overloaded? Is it undefined behavior or > will the program just not compile? With no template constraint, a template will match anything with th

Re: can't access an alias created inside an if statement

2020-08-05 Thread Simen Kjærås via Digitalmars-d-learn
On Wednesday, 5 August 2020 at 09:05:36 UTC, Flade wrote: I have used an if-else statement to create an alias to avoid code duplication but it doesn't let me access it outside the if statement. Is there a way to solve this? You're probably looking for static if: static if

Re: can't access an alias created inside an if statement

2020-08-05 Thread Flade via Digitalmars-d-learn
On Wednesday, 5 August 2020 at 09:25:23 UTC, Simen Kjærås wrote: On Wednesday, 5 August 2020 at 09:05:36 UTC, Flade wrote: I have used an if-else statement to create an alias to avoid code duplication but it doesn't let me access it outside the if statement. Is there a way to solve

Re: can't access an alias created inside an if statement

2020-08-05 Thread Simen Kjærås via Digitalmars-d-learn
On Wednesday, 5 August 2020 at 09:32:58 UTC, Flade wrote: Thanks! You see it should work but the thing is. I'm using it inside a function. I'm checking for one of the function's parameter (if parameter == false) and it says that "the variable `parameter` cannot be read at compile time. Do you

Re: can't access an alias created inside an if statement

2020-08-05 Thread Flade via Digitalmars-d-learn
On Wednesday, 5 August 2020 at 09:39:47 UTC, Simen Kjærås wrote: On Wednesday, 5 August 2020 at 09:32:58 UTC, Flade wrote: Thanks! You see it should work but the thing is. I'm using it inside a function. I'm checking for one of the function's parameter (if parameter == false) and it says that "

Unable to access a variable declared inside an if statement (Error: is shadowing variable)

2020-05-27 Thread BoQsc via Digitalmars-d-learn
I'm lacking knowledge on how to achieve what I want and getting an error. What is the correct way to do what I tried to achieve in this code? Everything was intuitive until I started to add notice variable to the writeln. Rdmd says variable `notice` is shadowing variable. rdmd output: C:\Us

Re: Unable to access a variable declared inside an if statement (Error: is shadowing variable)

2020-05-27 Thread Simen Kjærås via Digitalmars-d-learn
On Wednesday, 27 May 2020 at 11:03:51 UTC, BoQsc wrote: I'm lacking knowledge on how to achieve what I want and getting an error. What is the correct way to do what I tried to achieve in this code? Everything was intuitive until I started to add notice variable to the writeln. Rdmd says variab

Re: Unable to access a variable declared inside an if statement (Error: is shadowing variable)

2020-05-27 Thread BoQsc via Digitalmars-d-learn
On Wednesday, 27 May 2020 at 11:13:09 UTC, Simen Kjærås wrote: On Wednesday, 27 May 2020 at 11:03:51 UTC, BoQsc wrote: I'm lacking knowledge on how to achieve what I want and getting an error. What is the correct way to do what I tried to achieve in this code? Everything was intuitive until I s