6
$\begingroup$

One main advantage of Mathematica over several other languages, at least in my view, is that you can create your code line by line. This makes much easier to debug your code during the development phase. After much of the code has been developed and debugged, it's just a matter of copy and paste the code from the notebook format to a batch file format (or a package).

Is there a formal nomenclature in computer science for such feature?

$\endgroup$
  • $\begingroup$ "Compositional"? "Top-down"? "Scripting"? $\endgroup$ – Patrick Stevens Nov 20 '15 at 15:42
  • 1
    $\begingroup$ Probably is 'scripting', but I'm not very sure since I've never read such nomenclature in the documentation. And without a formal nomenclature, it's not that easy to explain such feature for non-mathematica users. Take a look by yourself: programmers.stackexchange.com/questions/303122/… $\endgroup$ – Mark Messa Nov 20 '15 at 15:49
13
$\begingroup$

Mathematica is one language environment among many that features what is called a "Read-Eval-Print Loop" (or REPL), which allows the user to interact with the system by evaluating individual expressions and printing the results. The Mathematica REPL is actually a fairly bare-bones thing, and if you want to experience it for yourself, you can use it from a DOS window (on Windows) or a shell prompt (on Mac OS X or Linux). It's really not so different from the REPLs provided by many other language environments, including Python, Haskell (with it's GHCi interpreter) and Common Lisp (my personal favorite, with too many implementations to list).

At this point, I feel compelled to note that some people call REPLs "interpreters", which can sometimes be misleading because it makes people think only interpreted languages can have them. This is not the case: though Mathematica and Python are interpreted, Haskell is compiled, as are most Common Lisp implementations. There are many tradeoffs between compilation and interpretation, but this isn't one of them. Indeed, one reason I keep emphasizing the phrase "language environment" is that a REPL is not a feature of a language itself, but rather a specific tool that can be provided for a language, much like a debugger (indeed, the line between debugger and REPL can be pretty thin). Though the languages I've listed are all pretty-to-very high level, you can evidently find REPLs for C, though I've never used one myself.

While, like many Mathematica users, I find the use of a REPL to be very helpful, and prefer it to the edit-build-run cycle common to many other environments, Mathematica goes well beyond what a REPL usually provides in its "notebook" front-end. The ability to generate and display graphics, styled text, formatted tables (or Grids), decent-looking mathematical notation and even inline GUI interfaces alongside code is something that very few environments provide. Mathematica goes even further than that, in providing a powerful (if perhaps under-documented) set of tools for programmatically parsing, analyzing and creating notebooks.

$\endgroup$
  • $\begingroup$ Perfect! Now, completely off the initial question, do you know whether it is possible do have such similar REPL environment for lower-levels languages (specially for C)? ps: let me know if this would be better posted in other question topic. $\endgroup$ – Mark Messa Nov 20 '15 at 15:58
  • $\begingroup$ @MarkMessa see my edit for information about C REPLs $\endgroup$ – Pillsy Nov 20 '15 at 16:21
  • $\begingroup$ You can use Java in Mathematica and you don't need to declare variables' types this way. $\endgroup$ – faysou Nov 22 '15 at 8:30
6
$\begingroup$

Various people have tried C REPLs, and they don't work all that well. Elaborate type declarations get in the way. Declarations remote from use get in the way. The need for explicit loops gets in the way. C was designed for top-down edit-compile-test coding, not with REPL in mind.

The languages most friendly to REPL are those (like Mathematica) where one may easily solve problems by composing short functions. You code bottom-up. Write a one-line function. Try it. Write another. Try that. Compose a higher level function from those. Try that...

There is an old low-level language that supports this approach well: Forth.

$\endgroup$
  • $\begingroup$ Now comes the intriguing question: is there a demand for C REPLs? Or C programmers really don't find that useful REPL? ps: I guess I'm gonna have to post this question topic somewhere ... $\endgroup$ – Mark Messa Nov 20 '15 at 17:11

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.