Jump to page: 1 29  
Page
Thread overview
Do you think if statement as expression would be nice to have in D?
Jun 03, 2022
Jack
Jun 03, 2022
IGotD-
Jun 03, 2022
Jack
Jun 03, 2022
max haughton
Jun 04, 2022
z
Jun 04, 2022
monkyyy
Jun 04, 2022
Jack
Jun 04, 2022
zjh
Jun 04, 2022
forkit
Jun 04, 2022
Ali Çehreli
Jun 04, 2022
Martin B
Jun 04, 2022
Walter Bright
Jun 04, 2022
SealabJaster
Jun 04, 2022
Walter Bright
Jun 04, 2022
rikki cattermole
Jun 04, 2022
Daniel N
Jun 04, 2022
Walter Bright
Jun 05, 2022
rikki cattermole
Jun 07, 2022
Walter Bright
Jun 04, 2022
user1234
Jun 04, 2022
zjh
Jun 04, 2022
Nick Treleaven
Jun 04, 2022
user1234
Jun 04, 2022
Nick Treleaven
Jun 04, 2022
user1234
Jun 04, 2022
user1234
Jun 04, 2022
user1234
Jun 05, 2022
Walter Bright
Jun 05, 2022
Nick Treleaven
Jun 05, 2022
Nick Treleaven
Jun 07, 2022
Walter Bright
Jun 05, 2022
kdevel
Jun 04, 2022
Dukc
Jun 04, 2022
SealabJaster
Jun 06, 2022
deadalnix
Jun 06, 2022
H. S. Teoh
Jun 06, 2022
deadalnix
Jun 06, 2022
SealabJaster
Jun 06, 2022
SealabJaster
Jun 07, 2022
Walter Bright
Jun 07, 2022
bauss
Jun 07, 2022
Bruce Carneal
Jun 07, 2022
Walter Bright
Jun 07, 2022
Bruce Carneal
Jun 07, 2022
Walter Bright
Jun 07, 2022
Bruce Carneal
Jun 07, 2022
Guillaume Piolat
Jun 07, 2022
max haughton
Jun 07, 2022
Guillaume Piolat
Jun 07, 2022
Guillaume Piolat
Jun 08, 2022
Bruce Carneal
Jun 07, 2022
Walter Bright
Jun 07, 2022
zjh
Jun 07, 2022
Ali Çehreli
Jun 07, 2022
Walter Bright
Jun 07, 2022
matheus
Jun 08, 2022
Walter Bright
Jun 11, 2022
matheus
Jun 12, 2022
Walter Bright
Jun 07, 2022
max haughton
Jun 07, 2022
zjh
Jun 07, 2022
zjh
Jun 07, 2022
Guillaume Piolat
Jun 07, 2022
Walter Bright
Jun 07, 2022
Guillaume Piolat
Jun 07, 2022
max haughton
Jun 08, 2022
Walter Bright
Jun 08, 2022
zjh
Jun 07, 2022
Walter Bright
Jun 07, 2022
max haughton
Jun 08, 2022
Walter Bright
Jun 12, 2022
Timon Gehr
Jun 12, 2022
Walter Bright
Jun 04, 2022
Sergey
Jun 04, 2022
Guillaume Piolat
Jun 04, 2022
JN
Jun 06, 2022
Salih Dincer
Jun 06, 2022
Jack
June 03, 2022

Rust does support it like that:

    const limit:i32 = 30;
    let n = 10;
    let mut r = if n > limit { "big" } else { "small "};
    println!("{} is {} than {}", n, r, limit);

do you think would be nice that in D as well? I find it can increase code reability...

June 03, 2022

On Friday, 3 June 2022 at 18:33:57 UTC, Jack wrote:

>

Rust does support it like that:

    const limit:i32 = 30;
    let n = 10;
    let mut r = if n > limit { "big" } else { "small "};
    println!("{} is {} than {}", n, r, limit);

do you think would be nice that in D as well? I find it can increase code reability...

No, I don't think it helps readability. D still has the conditional operator (bool ? trueval : falseval) like C though.

People who like Rust, why not just use Rust?

June 03, 2022

On Friday, 3 June 2022 at 18:42:11 UTC, IGotD- wrote:

>

On Friday, 3 June 2022 at 18:33:57 UTC, Jack wrote:

>

Rust does support it like that:

    const limit:i32 = 30;
    let n = 10;
    let mut r = if n > limit { "big" } else { "small "};
    println!("{} is {} than {}", n, r, limit);

do you think would be nice that in D as well? I find it can increase code reability...

No, I don't think it helps readability. D still has the conditional operator (bool ? trueval : falseval) like C though.

People who like Rust, why not just use Rust?

who knows, i don't like rust

June 03, 2022

On Friday, 3 June 2022 at 18:33:57 UTC, Jack wrote:

>

Rust does support it like that:

    const limit:i32 = 30;
    let n = 10;
    let mut r = if n > limit { "big" } else { "small "};
    println!("{} is {} than {}", n, r, limit);

do you think would be nice that in D as well? I find it can increase code reability...

I don't particularly care about if expressions because we have the ternary operator but I do want pattern matching rather urgently.

June 04, 2022

On Friday, 3 June 2022 at 19:06:04 UTC, max haughton wrote:

>

I don't particularly care about if expressions because we have the ternary operator but I do want pattern matching rather urgently.

why urgently? AFAIU pattern matching is equivalent to a bunch of if(value1 == *specialvalue or enum*) *insert statement(s) here*;
There's a few ways to do them(switches) but my favorite is the one above because they are devilishly simple and easily generated both manually and programmatically(mixins...).
Pattern matching as Haskell does it requires a single value too, which means more than one value requires a struct(tuple in haskell?).
(but it's possible that i'm mistaken, i could not find an example of HS pattern matching with more than one value to match per case.)

June 04, 2022

On Saturday, 4 June 2022 at 00:44:30 UTC, z wrote:

>

(but it's possible that i'm mistaken, i could not find an example of HS pattern matching with more than one value to match per case.)

let point = CGPoint(x: 7, y: 0)
switch (point.x, point.y) {
  case (0,0): print("On the origin!")
  case (0,_): print("x=0: on Y-axis!")
  case (_,0): print("y=0: on X-axis!")
  case (let x, let y) where x == y: print("On y=x")
  default: print("Quite a random point here.")
}

https://alisoftware.github.io/swift/pattern-matching/2016/03/30/pattern-matching-2/
this would be an example of what I expect

June 04, 2022

On Saturday, 4 June 2022 at 02:24:41 UTC, monkyyy wrote:

>

On Saturday, 4 June 2022 at 00:44:30 UTC, z wrote:

>

(but it's possible that i'm mistaken, i could not find an example of HS pattern matching with more than one value to match per case.)

let point = CGPoint(x: 7, y: 0)
switch (point.x, point.y) {
  case (0,0): print("On the origin!")
  case (0,_): print("x=0: on Y-axis!")
  case (_,0): print("y=0: on X-axis!")
  case (let x, let y) where x == y: print("On y=x")
  default: print("Quite a random point here.")
}

https://alisoftware.github.io/swift/pattern-matching/2016/03/30/pattern-matching-2/
this would be an example of what I expect

that sounds also interesting

June 04, 2022

On Saturday, 4 June 2022 at 00:44:30 UTC, z wrote:

>

why urgently? AFAIU pattern matching is equivalent to a bunch of if(value1 == *specialvalue or enum*) *insert statement(s) here*;

Yes, it makes most sense if you can do nested matching.

add(mul(_,0),$x) => $x;
add(mul($x,1),$y) => add($x,$y);
add(mul($x,$y),$z) => muladd($x,$y,$z);

June 04, 2022
On Friday, 3 June 2022 at 18:33:57 UTC, Jack wrote:
> Rust does support it like that:
>
> ```rust
>     const limit:i32 = 30;
>     let n = 10;
>     let mut r = if n > limit { "big" } else { "small "};
>     println!("{} is {} than {}", n, r, limit);
> ```
>
> do you think would be nice that in D as well? I find it can increase code reability...

According to the policy laid down by Mike (in another post), it must provide a 'strong benefit', not just be something that is useful to increase code reliabiltiy/readability.

It is neither useful, nor a strong benefit, to me ;-)

June 04, 2022

On Saturday, 4 June 2022 at 02:24:41 UTC, monkyyy wrote:

>
let point = CGPoint(x: 7, y: 0)
switch (point.x, point.y) {
  case (0,0): print("On the origin!")
  case (0,_): print("x=0: on Y-axis!")
  case (_,0): print("y=0: on X-axis!")
  case (let x, let y) where x == y: print("On y=x")
  default: print("Quite a random point here.")
}

https://alisoftware.github.io/swift/pattern-matching/2016/03/30/pattern-matching-2/
this would be an example of what I expect.

I think it's worth it. The more features, the better!
Yes ,We are C++++!

« First   ‹ Prev
1 2 3 4 5 6 7 8 9