archives

Variation of C's inline conditional

The C language has an inline conditional statement, in the form:
condition ? exprA : exprB
Now, many times exprA is a component of the condition, for example:
(somebigexpression) != 0 ? (somebigexpression) : (defaultexpression)

I'm looking for a form of the inline conditional that doesn't repeat the "somebigexpression" in the above situation, without assigning it to an intermediate variable. I was thinking something along the lines of this syntax:
(somebigexpression) !=? 0 : (defaultexpression)
where if the "?" follows a comparison operator, then if true it will return the left side of the comparison; else it returns the right side of the ":".

So two questions... 1) Would this be useful enough in practice to bother adding it to a language (i.e., does it make the code more clear v.s. assigning the original expression to a temp variable)? and 2) Does another language already have a syntax that accomplishes the same thing that I can borrow from?

Thanks.

Languages best suited for scientific computing?

I work in a field where the standard for high-performance scientific computing is still Fortran (albeit Fortran 95 nowadays). The array-based nature of Fortran provides a relatively clean and intuitive syntax for solving the systems of equations often involved in numerical simulations. The simplicity of Fortran has also facilitated highly efficient Fortran compiler implementations.

However I'm searching for a more modern and general purpose scientific computing language. Fortran is probably not the ideal language for writing networked graphical applications, neither I would argue is MATLAB or IDL. SciPy has deservedly gained traction amongst scientists recently and it is certainly a very attractive option. Unfortunately "CPython" can exhibit underwhelming performance characteristics requiring inconvenient work-arounds for CPU intensive code (see here for an example).


I'm of the belief that the ideal language should also be functional and open-source. Some contenders I've tried:

  • SAC lacks many desirable features for a general purpose programming language.
  • Boo is one of the most promising new "main-stream" languages but multidimensional array operations are not a core feature (although it recently gained array slices). It is also tied to the CLR.
  • OCaml probably comes closest, although again multidimensional arrays/matrices are not first-class citizens and the syntax is unfamiliar for most scientists (although the "OCaml Whitespace Thing" might help here).

Any suggestions in my quest for a better language are welcome. And yes I'm aware of hacks in C++ (Blitz) and Java (JScience); neither of these are very promising going forward IMHO!