News for hackers. Stuff that matters.
Re:Fortran adds conditional expressions by DonaldFisk on Thursday July 01, 2021 @03:14PM (#27703253)
Although they weren't built into the language, conditional expressions were first used in Fortran in 1957 by John McCarthy: "I invented conditional expressions in connection with a set of chess legal move routines I wrote in FORTRAN for the IBM 704 at M.I.T. during 1957-58. This program did not use list processing. The IF statement provided in FORTRAN 1 and FORTRAN 2 was very awkward to use, and it was natural to invent a function XIF(M,N1,N2) whose value was N1 or N2 according to whether the expression M was zero or not. The function shortened many programs and made them easier to understand, but it had to be used sparingly, because all three arguments had to be evaluated before XIF was entered, since XIF was called as an ordinary FORTRAN function though written in machine language. This led to the invention of the true conditional expression which evaluates only one of N1 and N2 according to whether M is true or false and to a desire for a programming language that would allow its use." From http://jmc.stanford.edu/articles/lisp/lisp.pdf
Re:Fortran adds conditional expressions by wumpus on Thursday July 01, 2021 @06:45PM (#27705811)
And for those wondering why IF was awkward, there was no ELSE until Fortran 77, and doing that with GOTOs was a little ugly.
Re:Fortran adds conditional expressions by ggm on Thursday July 01, 2021 @06:57PM (#27705929)
Thanks. you helped confirm I must have learned some early state of F77 in 76/7. Since F77 was 1978 and I left school in 78, it can't have been full standard. I was sure I remembered an ELSE so now I wonder if this is a mis-memory, or languages intercepted this somehow. (cards on an ICL 1900 system)
Re:Fortran adds conditional expressions by wyager on Thursday July 01, 2021 @03:48PM (#27703728)
One nice thing about lazy languages is you get the desired operator behavior for conditional operators, short-circuiting logical operators, etc “for free” without having to build it into the language.
Re:Fortran adds conditional expressions by gnufx on Thursday July 01, 2021 @05:12PM (#27704938)
Well-disposed as I am towards laziness, you may well not want short-circuiting, depending on the application. I just re-wrote the C implementations of logical reductions using bitwise operators instead to && and || to get them vectorized -- avoiding "conditional in loop". (They're Fortran-callable.)

Incidentally, gfortran treats the reduction like C, which seems a deficiency as the standard allows it not to.

Re:Fortran adds conditional expressions by sfblah on Thursday July 01, 2021 @04:30PM (#27704377)
I'm too lazy even to click and read it, but you mean stuff like:

const x = y || 3;

?

Re:Fortran adds conditional expressions by thaumasiotes on Thursday July 01, 2021 @04:40PM (#27704526)
That would be a short-circuiting logical operator.
Re:Fortran adds conditional expressions by jstanley on Thursday July 01, 2021 @04:40PM (#27704517)
Probably more like:

  $y>5 || die "y should be greater than 5";
Re:Fortran adds conditional expressions by xioxox on Friday July 02, 2021 @01:22AM (#27708053)
Doesn't Fortran 90 have the MERGE(IFTRUE,IFFALSE,CONDITIONAL) function as standard which is similar to the XIF used here? (as usual, Fortran chooses some weird names for its functions).

Perhaps the difference with the conditional discussed here is that in a function all the arguments are usually calculated before evaluation, so the conditional may avoid an error if one of the arguments can be invalid depending on the condition. It's a bit unclear from the proposed language addition, however.