8
$\begingroup$

The functional paradigm of the Wolfram Language used in Mathematica is all around wonderful.

For intense numerics, Mathematica comes with the ability to Compile sections of code to the Wolfram Virtual Machine (WVM). When written correctly, this can lead to speed boosts by orders of magnitude (I am particularly proud of the code in this question that computes the Dilogarithm). Also, it is totally portable, which makes it particularly useful to include in packages for public use.

But, for extremely long and complex algorithms, it is agonizingly clumsy to write the procedural code in Mathematica's functional syntax. Especially bad is if there are lots of nested If statements, and multiple subroutines that tend to require CompilationOptions -> {"InlineExternalDefinitions" -> True}. All the [[ [ [ [[ and ]] ] ] ]] drive me totally crazy.

Is there a way to write code that is closer in syntax to C that can also compile to WVM to preserve the overall portability?

$\endgroup$
  • $\begingroup$ I try to modify individual functions for each if statement, but sometimes it becomes messy when the if statements need lots of arguments. $\endgroup$ – Bichoy Jun 7 '15 at 21:26
  • $\begingroup$ I also try to use the prefix form to reduce the number of [ ] but you are right, it can be a pain sometimes... $\endgroup$ – Bichoy Jun 7 '15 at 21:28
  • $\begingroup$ I'd disagree with the "opinion-based" close reason. Although a possible answer to this is opinion-based, I don't think this is a bad thing in this case. Such answers, opinion-based or not, will likely be useful. $\endgroup$ – LLlAMnYP Dec 1 '15 at 12:44
  • 1
    $\begingroup$ Since I wrote this question, I found out that Which is compilable, and really helps cut down on nested If statements. $\endgroup$ – QuantumDot Dec 1 '15 at 15:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.