Subj : Re: Compiler and an interpreter To : comp.programming From : Jon Harrop Date : Thu Aug 04 2005 12:02 pm Gerry Quinn wrote: > In article <42f0c6cb$0$91528$ed2e19e4@ptn-nntp-reader04.plus.net>, > usenet@jdh30.plus.com says... >> Gerry Quinn wrote: >> > If you get 13 lines to make a copy of a list of ints with each replaced >> > by the larger of 5 and the value in the original array (which I assume >> > you are doing), you must be including curly brackets and various >> > standard includes. >> >> Those are necessary. > > But they will not increase as the problem gets more complicated. No. Witness the dozens of curly braces in my slightly longer example. >> Those 4-lines are the equivalent of "List.map (max 5)", except that the >> OCaml is more general and can be reused. > > Either takes seconds to write. As programs get bigger, I'd rather write less code. >> Are you going to say that your 4 lines of C++ are more comprehensible >> than the 16 characters of OCaml? > > To many here, they will be. I certainly had to guess from context what > you were trying to do. There is a certain vagueness attached as you > introduced what seems to be a specific spelled-out list (why not a more > efficient array, since elsewhere you talk about efficiency?) Arrays are not more efficient than lists. > and then apparently modified it, which seems futile. My code doesn't modify the list. >> The STL is designed for efficiency and my code is a simple translation of >> the maths (exactly equivalent to the OCaml). The C++ implementation can >> be optimised, of course, but not without intimate knowledge of the >> implementation of set theoretic operations in the STL. Making the >> optimisations takes quite a bit of time and effort. Oh, and the OCaml >> hasn't been optimised either... > > I have doubts whether set theoretic operations in STL are designed, or > at least implemented, for efficiency. Certainly if I wanted to write > an efficient program in the sphere referred to, I would carefully > consider my choice of data structures. You should study the STL... > In any case, C++ is a general purpose language, not one designed for > the translation of mathematical functions. OCaml is also a general purpose language, not specifically designed for the translation of mathematical functions. > Indeed, the tiny fraction > of problems that consist largely of translating mathematical equations > into programs likely constitutes a large part of the useful domain of > functional languages. Perhaps if you give some examples of applications that you believe FPLs are poorly suited to? >> > I don't believe your benchmarks are valid. >> >> These aren't benchmarks, they are real programs. > > You present them as if they are benchmarks, IMO. Yes. Why do you think these real-world performance-critical programs are "invalid" as benchmarks? >> That wasn't a "complex mathematical" formula. It was just a few set >> unions and differences. For really complicate formulae, OCaml will be >> relatively much better. > > It's complex by comparison with most of the formulae used in the vast > bulk of computer programming. I don't know what you think constitutes the "vast bulk of computer programming" but you'll find substantially more complicated algorithms and data structures in graphics, databases, games and so on. Most of these would be more easily and efficiently coded in OCaml than C++. -- Dr Jon D Harrop, Flying Frog Consultancy http://www.ffconsultancy.com .