3 ms·
This is interesting, but I'm not upvoting it... I wrote something similar for dealing with calculus on tensor fields a few years back and most compilers I've wr
by jheriko 17y ago
This is interesting, but I'm not upvoting it... I wrote something similar for dealing with calculus on tensor fields a few years back and most compilers I've written use something similar for dealing with expressions.
This is different though, it doesn't let you solve any new problems that C++ can't already solve, and it also happens to produce slower expressions than, e.g. a function object or a function being pointed to.
If you want lambdas (which let you solve exactly no problems you can't already solve with C++) then use a language that supports them instead of shoehorning them in badly.
I'd recommend Haskell...
- growingconcern 17y agoThis doesn't make sense. You're saying adding lambdas doesn't help you solve any problems that can't already be solved in C++, but if you want to solve some of those problems you should use a language that supports lambdas?
- jey 17y agoHe's right. You can do anything in {C++, Python, a Turing machine}, but you might want to choose a language that's well suited for your task at hand even though any of them can do it in principle.
- jheriko 17y agoThat's exactly what I meant. My examples equally have solutions which use these C++ lambdas, but it would be a lot more work than necessary to actually produce or maintain them.
- growingconcern 17y agoThat might be what you meant. But it's not what you said.
- jheriko 17y agoI never said that problems exist which require lambdas either... I just said if you want to solve problems that way to use a language designed for it.
- fadmmatt 17y ago(Article author here.) I'd love to use Haskell, but I'm helping out on an exascale DoE project, and C++ is all we're allowed to use. Ugh. Of course, lambdas don't make C++ more powerful, but that's just reductio ad Turing tar-pit. You can turn that argument around, too: there's no problem you can solve with C++ that you can't solve with lambdas alone: http://matt.might.net/articles/church-encodings-demo-in-scheme/ http://matt.might.net/articles/church-encodings-demo-in-sche... If programming languages were about computational power, we would have stopped with Fortran. Programming languages are about the freedom of expressions.
- jheriko 17y ago"If programming languages were about computational power, we would have stopped with Fortran. Programming languages are about the freedom of expressions." I strongly disagree, /some/ programming languages are about expressive power - others are about computational power. We didn't stop with Fortran, we moved onto C then C++ - they might not be able to do anything more in the computer science theoretical sense, but in practice they produce faster executables, and in real world applications that means more computational power can be brought to bear on problems with these sorts of languages. Maybe speed doesn't matter for your problem, or lambdas are an especially nice fit. Mainly I'm just worried that you are going to produce substandard code with this kind of mindset... good code is written with the language's strengths and weaknesses in mind, not to enable the flavour-of-the-month paradigm to be used in an extremely sub-optimal fashion.