3 ms·
Although they weren't built into the language, conditional expressions were first used in Fortran in 1957 by John McCarthy: "I invented conditional expressions
by DonaldFisk 5y ago
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 http://jmc.stanford.edu/articles/lisp/lisp.pdf
- wyager 5y agoOne 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.
- sfblah 5y agoI'm too lazy even to click and read it, but you mean stuff like: const x = y || 3; ?
- deleted 5y ago[deleted]
- jstanley 5y agoProbably more like: $y>5 || die "y should be greater than 5";
- thaumasiotes 5y agoThat would be a short-circuiting logical operator.
- gnufx 5y agoWell-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.
- wumpus 5y agoAnd for those wondering why IF was awkward, there was no ELSE until Fortran 77, and doing that with GOTOs was a little ugly.
- ggm 5y agoThanks. 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)
- xioxox 5y agoDoesn'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.