News for hackers. Stuff that matters.
Re:Fortran adds conditional expressions by Russelfuture on Thursday July 01, 2021 @03:59PM (#27703922)
This is cool. Good to see. Thanx for posting this. If someone is coding some serious math hackery, drill down into the app and you'll often find someone's variant/version of the old IMSL library routines, written - in Fortran - back in the 1960's. Why? Because that code was extensively tested and was deemed trustworthy. And even better - just went to my bookshelves and found it: "Optimization Techniques With Fortran" - James L. Kuester, Joe H. Mize, McGraw-Hill, 1973, ISBN 0-07-035606-8. It's just an awesome book - it's 9inches by 11 inches, 500 pages chock full of detailed explanations of many of the state-of-the-art circa 1973 optimization techniques for search methods, linear and quadratic programming tricks, least-squares (linear and non-linear methods), dynamic programming (a math technique for making a series of interrelated decisions), and so on. The book has code, examples and detailed explanations - with numerical examples - and flowcharts even, to explain exactly how the code works, and what the program is actually doing. And its all Fortran - some of it IBM/360 Fortran - all in Courier font that's easy to read and use. I had a client that just typed in all the code for a Simplex LP program, and used it to construct a big optimization solution for how to structure the re-investment actions of a large bond portfolio in a treasury department of a big organization.

Before there were neural networks and image-hacking, there was the gritty math-hacking to optimize big gobs of interrelated stuff that had to happen in the right order. It was almost always done in Fortran, and I suspect a lot of it still is. (And if it was not done in Fortran, it was done in APL. Ask an Actuarial scientist, if you doubt this..) Please don't laugh at Fortran. It can not only help you fly your spaceship to another planet (and get you home again!), it can also make you (and your client) rich, since you can build solid, bulletproof code from those old libraries that just works, and hence create flaw-free solutions to really critically important applications. This proposed extension looks useful.

Re:Fortran adds conditional expressions by andrewf on Thursday July 01, 2021 @08:42PM (#27706702)
https://github.com/wch/r-source/search?l=fortran&p=1

(https://github.com/wch/r-source says that's 23% of the source. It includes vendored libraries, like a 5MB .f of LAPACK code. I bet a lot of the C code in R was f2c'd at some point in the past)

Re:Fortran adds conditional expressions by edgyquant on Thursday July 01, 2021 @10:35PM (#27707332)
Similarly, scipy is 18% FORTRAN (jumpy is 0.01% so I didn’t think to link it.)

https://github.com/scipy/scipy

Re:Fortran adds conditional expressions by dhosek on Friday July 02, 2021 @12:45AM (#27707883)
Oh man, just seeing those letters—I M S L—brought back the distinct smell of the IMSL documentation in the UIC computer lab in the 80s, which along with a lot of other mainframe documentation was on special racks where three ring–punched documentation could be read (but not actually brought to a terminal where it could be useful).
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.

Re:Fortran adds conditional expressions by bee_rider on Thursday July 01, 2021 @03:10PM (#27703191)
I've always thought the conditional ternary operator would map really well to masked vector operations. Since those were around in the old Cray machines, I was always confused as about the absence of ternary op in Fortran. It is a pretty well designed language, so I'm sure I'm missing something, but it seemed odd. Happy to see it show up now!
Re:Fortran adds conditional expressions by Bostonian on Thursday July 01, 2021 @01:56PM (#27702174)
Sample syntax:

    y = ( i>=1 .And. i<=Size(a) ? a(i) : -Huge(y) )
The proposal has been approved, but the final standard will be voted on, and it will take time for it to appear in compilers.
Re:Fortran adds conditional expressions by xxpor on Thursday July 01, 2021 @02:30PM (#27702644)
Sorry, not familiar with Fortran at all. Did ternaries already exist, and this just adds assignment or is the ternary new too?
Re:Fortran adds conditional expressions by Bostonian on Thursday July 01, 2021 @02:43PM (#27702823)
The ternary is new. Before, one could use the merge intrinsic function to write

    y = merge(a(i), -Huge(y), i>=1 .And. i<=Size(a))
but this is risky, because merge does not short-circuit, and the program could crash if i < 1. The ternary syntax

    y = (boolean ? expression_1 : expression_2)
only evaluates one of the expressions.
Re:Fortran adds conditional expressions by floxy on Thursday July 01, 2021 @05:11PM (#27704929)
"I don't know what the programming language of the year 2000 will look like, but I know it will be called FORTRAN." -- C.A.R. Hoare
Re:Fortran adds conditional expressions by gnufx on Thursday July 01, 2021 @05:23PM (#27705052)
The better one of his, which I've probably posted before, is "ALGOL 60 is alive and well and living in FORTRAN [sic] 90."
Re:Fortran adds conditional expressions by zh3 on Thursday July 01, 2021 @02:50PM (#27702930)
Well, if Fortran is going to borrow from C, to repay the favour I trust we'll get computed GOTOs in C31.
Re:Fortran adds conditional expressions by pontifk8r on Thursday July 01, 2021 @03:45PM (#27703683)
Computed GOTOs in C are just pointer arithmetic and casts.
Re:Fortran adds conditional expressions by whatshisface on Thursday July 01, 2021 @03:49PM (#27703739)
Can you jump to a computed GOTO in C? I guess you can if you cast to a function pointer...
Re:Fortran adds conditional expressions by wk_end on Thursday July 01, 2021 @04:22PM (#27704264)
I’m no C language lawyer, but it’s hard to imagine that sort of voodoo won’t trigger some kind of undefined behaviour that’ll cause the optimizer to erase your program at best and summon nasal demons at worst.
Re:Fortran adds conditional expressions by floxy on Thursday July 01, 2021 @05:05PM (#27704859)
Re:Fortran adds conditional expressions by comex on Thursday July 01, 2021 @10:27PM (#27707294)
Yes, but it’s a GCC extension, not standard.
Re:Fortran adds conditional expressions by gnufx on Thursday July 01, 2021 @05:14PM (#27704955)
I remember the comp.compilers moderator calling C a Fortran-like language.
Re:Fortran adds conditional expressions by wumpus on Thursday July 01, 2021 @06:48PM (#27705848)
Well, that's a joke referring to the typical Computer Science jargon of calling them both Algol-like languages.

I don't recall him saying that while I used to read that group, but I would have chuckled.

Re:Fortran adds conditional expressions by 37ef_ced3 on Thursday July 01, 2021 @04:41PM (#27704540)
The ternary operator is something I miss when using Go
Re:Fortran adds conditional expressions by bjoli on Thursday July 01, 2021 @05:00PM (#27704805)
If as an expression is something I miss almost everywhere. Trenary has always seemed like an afterthought.
Re:Fortran adds conditional expressions by WatchDog on Thursday July 01, 2021 @11:26PM (#27707539)
Kotlin doesn't have a ternary operator, although `if` is an expression, I still miss it though.
Re:Fortran adds conditional expressions by streamofdigits on Friday July 02, 2021 @04:13AM (#27709014)
An interesting question is whether the continuing modernization of fortran will at some point enable it to become the "React/JS" of data scientists and assorted tensor crunchers. Fortran had built-in vector operations since fortran 90 which could have made it a natural choice for programming GPU's. Today there is a complex ecosystem of python, julia, R, c++, fortran, but none of which seems to offer a royal route to "mass market GPU programming".
Re:Fortran adds conditional expressions by zoomablemind on Thursday July 01, 2021 @05:17PM (#27704991)
Is the ternary conditional just for the syntactic ease or there are some performance reasons for this?

I understand there are conditional assignment instructions, though optimizer could likely choose these already. Also branching prediction may take care of such assignments as well.

Re:Fortran adds conditional expressions by pklausler on Thursday July 01, 2021 @06:42PM (#27705791)
Fortran has no means for preventing execution of subexpressions in a portable way. The standard allows a compiler to short-circuit .AND./.OR. and to evaluate only one of the first two arguments to a MERGE with a scalar condition, but it is not required and a programmer can’t depend on it. Rather than strengthen the guarantees of short-circuiting and non-evaluation of existing constructs (neither of which would have invalidated any portable code), the geniuses of J3 decided to add more syntax.
Re:Fortran adds conditional expressions by mmastrac on Thursday July 01, 2021 @02:28PM (#27702612)
I thought modern Fortran had C like operators?
Re:Fortran adds conditional expressions by steviedotboston on Thursday July 01, 2021 @02:22PM (#27702515)
how do people currently write conditional statements?
Re:Fortran adds conditional expressions by renewiltord on Thursday July 01, 2021 @03:10PM (#27703190)
The word of greatest value in the headline is “expressions”. There are conditionals in FORTRAN but now you can have a conditional that evaluates to something.
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.
Re:Fortran adds conditional expressions by rendall on Thursday July 01, 2021 @02:40PM (#27702782)
This is a big step for Fortran!
[dead]
Re:Fortran adds conditional expressions by dang on Thursday July 01, 2021 @02:16PM (#27702433)
Ok, but please don't post unsubstantive comments to HN.
Re:Fortran adds conditional expressions by Bostonian on Thursday July 01, 2021 @02:19PM (#27702471)
Often such blanket statements are made by people who know little about the current state of the language they are denouncing. I am happy to use modern Fortran.
Re:Fortran adds conditional expressions by tored on Thursday July 01, 2021 @03:34PM (#27703519)
Honest question, why should you use FORTRAN?

Does FORTRAN have any traction outside of scientific computation?

Re:Fortran adds conditional expressions by leephillips on Thursday July 01, 2021 @06:22PM (#27705615)
I see this type of comment often when Fortran is mentioned, and it puzzles me. What are computers for? Mainly for games and websites, with scientific computation an obscure niche? I don’t think so. Computers are for modeling the climate, predicting the weather, simulating the economy, calculating the merger of galaxies, and designing airplanes. For any of these, the high-performing languages are Fortran, Julia, C, and C++. That’s it. Lisp, Erlang, and Smalltalk are wonderful languages, but not for this.
Re:Fortran adds conditional expressions by Jtsummers on Thursday July 01, 2021 @03:46PM (#27703696)
Not really. But if you’re doing scientific computation it’s still a really good language.
Re:Fortran adds conditional expressions by gnufx on Thursday July 01, 2021 @05:20PM (#27705022)
You shouldn't -- it's decades old. Use Fortran, which is how it's written now (though your conforming FORTRAN77 will doubtless still compile).
Re:Fortran adds conditional expressions by tored on Thursday July 01, 2021 @05:33PM (#27705157)
Yes, it is my phone that autocorrects to capital letters and I can’t bother to fix it.
Re:Fortran adds conditional expressions by ngcc_hk on Thursday July 01, 2021 @07:00PM (#27705954)
When I do Astro app I found that you want accurate calculation you need fortran. Science spill over to other areas. In fact if you check around many languages and libraries use fortran for say matrix and many other manipulation. You use matrix nearly everywhere.

Btw, My first lecture in 1979 on computer science the lecturer asked exactly this question. What is the use? Why Fortean not dead by now? Why should anyone learn fortran … ba la ba la.

No chance but I wish he had taught me lisp and c instead of Basic … even if not fortran.

Re:Fortran adds conditional expressions by kergonath on Friday July 02, 2021 @01:01AM (#27707953)
It hasn’t been FORTRAN for about 30 years now.
Re:Fortran adds conditional expressions by neatze on Thursday July 01, 2021 @02:20PM (#27702490)
What makes you say this ?
Re:Fortran adds conditional expressions by jacobwilliamroy on Thursday July 01, 2021 @02:59PM (#27703048)
How am I supposed to aim my guns without fortan?
Re:Fortran adds conditional expressions by colejohnson66 on Thursday July 01, 2021 @07:58PM (#27706390)
I’d assume with C++ so they become footguns
Re:Fortran adds conditional expressions by bigbillheck on Thursday July 01, 2021 @02:19PM (#27702484)
Fortran as a general-purpose language has been dead for decades. If you don't do numerics, you can freely ignore it.
Re:Fortran adds conditional expressions by rendall on Thursday July 01, 2021 @02:43PM (#27702816)
What do you mean by numerics?
Re:Fortran adds conditional expressions by jon_adler on Thursday July 01, 2021 @02:52PM (#27702948)
Fortean is still very popular in the scientific community for numeric processing. For example, many nuclear simulations run on fortran.
Re:Fortran adds conditional expressions by bigbillheck on Thursday July 01, 2021 @03:19PM (#27703315)
Re:Fortran adds conditional expressions by FabianCarbonara on Thursday July 01, 2021 @02:19PM (#27702470)
too little, too late! I am super happy with React+Js nowadays..
Re:Fortran adds conditional expressions by erhk on Thursday July 01, 2021 @02:40PM (#27702784)
Im quite happy with my new apartment and also will not be needing fortran
Re:Fortran adds conditional expressions by wumpus on Thursday July 01, 2021 @06:54PM (#27705901)
I just moved to the apartment upstairs because it has a familiar floor-plan, is renovated, and has a slightly better view.
Re:Fortran adds conditional expressions by neatze on Thursday July 01, 2021 @02:23PM (#27702536)
Interesting to see how much slower is JS when compared to Fortran for matrix operations, no idea how to compare React to Fortran.
Re:Fortran adds conditional expressions by SavantIdiot on Thursday July 01, 2021 @02:49PM (#27702912)
React is a responsive framework, not a compute lib. It's a joke.

Getting offtopic here from FORTRAN, but there have been several attempts at numeric libraries in javascript (math.js, numjs), they are either lightweight, or unmaintained and in a sorry state, or require async execution that expect remote hardware (Googles tensor libs) which makes them a bit difficult to use in a general setting.

Hopefully WebASM will result in a native numpy-like library for JS because numpy is a very well-thought-out library and interface, it's really addictive.

Re:Fortran adds conditional expressions by walshemj on Thursday July 01, 2021 @03:07PM (#27703154)
I have written interfaces in Fortran 77 back in the 80's
Re:Fortran adds conditional expressions by jazzyjackson on Thursday July 01, 2021 @03:35PM (#27703539)
It’s not fast but I’ve found “algebrite” to be a good CAS for JavaScript that I can break out anytime I need dot products.
Re:Fortran adds conditional expressions by FabianCarbonara on Thursday July 01, 2021 @02:36PM (#27702732)
to be honest, this was just a very stupid joke. i guess there is no good reason to compare the two.
Re:Fortran adds conditional expressions by rendall on Thursday July 01, 2021 @02:44PM (#27702846)
Jokes are difficult to pull off well on HN. Worst downvotes I ever get are when I'm joking.
Re:Fortran adds conditional expressions by gpvos on Thursday July 01, 2021 @02:50PM (#27702927)
The trick is to lay it on so heavily that there is no joke anymore.
Re:Fortran adds conditional expressions by rendall on Thursday July 01, 2021 @03:13PM (#27703236)
Sadly, yes.
Re:Fortran adds conditional expressions by cpach on Thursday July 01, 2021 @02:47PM (#27702895)
(^_^)
Re:Fortran adds conditional expressions by cpach on Thursday July 01, 2021 @02:47PM (#27702889)
Ok cool but is React+Js really a competitor to Fortran…?
Re:Fortran adds conditional expressions by lkuty on Thursday July 01, 2021 @03:04PM (#27703112)
Both are Turing complete, so it is the case
Re:Fortran adds conditional expressions by cheeze on Thursday July 01, 2021 @03:19PM (#27703325)
I prefer Excel to both, which is also Turing complete.
Re:Fortran adds conditional expressions by henvic on Thursday July 01, 2021 @03:49PM (#27703749)
What about CSS?
Re:Fortran adds conditional expressions by SiempreViernes on Thursday July 01, 2021 @04:38PM (#27704477)
Better go with TeX if you're going into the Turing complete typesetting language niche, a Knuth product has more street cred.
Re:Fortran adds conditional expressions by sellyme on Friday July 02, 2021 @03:18AM (#27708694)
I don't know why people still bother using Fortran, Magic the Gathering obsoleted it decades ago.