8 ms·
Fortran adds conditional expressions
- AlexAndScripts 5y agoSome things just need to die. Fortran is one of them.
- dang 5y agoOk, but please don't post unsubstantive comments to HN.
- Bostonian 5y agoOften 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.
- tored 5y agoHonest question, why should you use FORTRAN? Does FORTRAN have any traction outside of scientific computation?
- Jtsummers 5y agoNot really. But if you’re doing scientific computation it’s still a really good language.
- gnufx 5y agoYou shouldn't -- it's decades old. Use Fortran, which is how it's written now (though your conforming FORTRAN77 will doubtless still compile).
- tored 5y agoYes, it is my phone that autocorrects to capital letters and I can’t bother to fix it.
- leephillips 5y agoI 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.
- ngcc_hk 5y agoWhen 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.
- kergonath 5y agoIt hasn’t been FORTRAN for about 30 years now.
- bigbillheck 5y agoFortran as a general-purpose language has been dead for decades. If you don't do numerics, you can freely ignore it.
- rendall 5y agoWhat do you mean by numerics?
- jon_adler 5y agoFortean is still very popular in the scientific community for numeric processing. For example, many nuclear simulations run on fortran.
- bigbillheck 5y agohttps://en.wikipedia.org/wiki/Numerical_analysis https://en.wikipedia.org/wiki/Numerical_analysis
- neatze 5y agoWhat makes you say this ?
- deleted 5y ago[deleted]
- jacobwilliamroy 5y agoHow am I supposed to aim my guns without fortan?
- colejohnson66 5y agoI’d assume with C++ so they become footguns
- Bostonian 5y agoSample 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.
- xxpor 5y agoSorry, not familiar with Fortran at all. Did ternaries already exist, and this just adds assignment or is the ternary new too?
- deleted 5y ago[deleted]
- Bostonian 5y agoThe 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.
- FabianCarbonara 5y agotoo little, too late! I am super happy with React+Js nowadays..
- neatze 5y agoInteresting to see how much slower is JS when compared to Fortran for matrix operations, no idea how to compare React to Fortran.
- FabianCarbonara 5y agoto be honest, this was just a very stupid joke. i guess there is no good reason to compare the two.
- SavantIdiot 5y agoReact 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.
- steviedotboston 5y agohow do people currently write conditional statements?
- Bostonian 5y agoThe 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
- walshemj 5y agoThis to me looks more readable than a one liner
- skywal_l 5y agoDepends 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.
- Someone 5y agoAlso 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.
- pklausler 5y agoFortran’s ASSOCIATE construct can help with that. associate (x=>(complicated variable)) if (test) then x = … else x = … end if end associate
- mmastrac 5y agoI thought modern Fortran had C like operators?
- rendall 5y agoThis is a big step for Fortran!
- zh3 5y agoWell, if Fortran is going to borrow from C, to repay the favour I trust we'll get computed GOTOs in C31.
- pontifk8r 5y agoComputed GOTOs in C are just pointer arithmetic and casts.
- whatshisface 5y agoCan you jump to a computed GOTO in C? I guess you can if you cast to a function pointer...
- wk_end 5y agoI’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.
- deleted 5y ago[deleted]
- floxy 5y agohttps://gcc.gnu.org/onlinedocs/gcc/Labels-as-Values.html https://gcc.gnu.org/onlinedocs/gcc/Labels-as-Values.html
- comex 5y agoYes, but it’s a GCC extension, not standard.
- gnufx 5y agoI remember the comp.compilers moderator calling C a Fortran-like language.
- bee_rider 5y agoI'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!
- DonaldFisk 5y agoAlthough 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.
- Russelfuture 5y agoThis 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.
- andrewf 5y agohttps://github.com/wch/r-source/search?l=fortran&p=1 https://github.com/wch/r-source/search?l=fortran&p=1 (https://github.com/wch/r-source 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)
- 5y ago
- 37ef_ced3 5y agoThe ternary operator is something I miss when using Go
- floxy 5y ago"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
- gnufx 5y agoThe better one of his, which I've probably posted before, is "ALGOL 60 is alive and well and living in FORTRAN [sic] 90."
- zoomablemind 5y agoIs 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.
- pklausler 5y agoFortran 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.
- streamofdigits 5y agoAn 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".