News for hackers. Stuff that matters.
Re:Fortran adds conditional expressions by Bostonian on Thursday July 01, 2021 @02:24PM (#27702558)
The current equivalent to the one-liner I presented is

   if (i>=1 .And. i<=Size(a)) then
      y = a(i) 
   else
      y = -Huge(y)
   end if
Re:Fortran adds conditional expressions by walshemj on Thursday July 01, 2021 @03:02PM (#27703096)
This to me looks more readable than a one liner
Re:Fortran adds conditional expressions by skywal_l on Thursday July 01, 2021 @03:52PM (#27703791)
Depends on the language I guess. For me this is easier to read (and reason with) in JS:

    const y = (i <== 1 && i < a.length()) ? a[i] : -Huge(i);
than:

    let y; // What do I initialize this too.
    if (i <== 1 && i < a.length()) {
      y = a[i]; // a side effect
    } else {
      y = -Huge(i); // another side effect
    }
 
And you end up with a mutable variable that might change later on (true only for language with mutable/non mutable variable of course).

Besides, it blends well with functional programming where side effect are better avoided.

Re:Fortran adds conditional expressions by Someone on Thursday July 01, 2021 @05:53PM (#27705365)
Also depends on what you assign to. If you read an if/else statement, you have to check whether both branches assign to the same value. If that’s a complex expression, that isn’t trivial.
Re:Fortran adds conditional expressions by pklausler on Thursday July 01, 2021 @07:02PM (#27705965)
Fortran’s ASSOCIATE construct can help with that.

associate (x=>(complicated variable))

  if (test) then

   x = …

  else

   x = …

  end if 

 end associate
Re:Fortran adds conditional expressions by veltas on Friday July 02, 2021 @08:44AM (#27710765)
You have cheated by adding that comment noise.