3
$\begingroup$

I want to run my Mathematica scripts from the terminal and I want it to print lines like MATLAB would. That is, suppress output by ending a line with ;, and otherwise print the output of the line. Get (<<) only prints the last line.

Without using Print[var] and saving variables after every line... Is this possible?

$\endgroup$
9
  • 2
    $\begingroup$ Your scripts ought to have Print[] lines somewhere in the file, then... $\endgroup$ Oct 31, 2012 at 12:50
  • $\begingroup$ "...without using Print[var]..." - why? $\endgroup$ Oct 31, 2012 at 14:42
  • 2
    $\begingroup$ I think adding // Print after every line is the best I can do, saves me from having to Print specific variables... $\endgroup$ Oct 31, 2012 at 14:43
  • $\begingroup$ without using Print[var] because I don't want to have to put in specific variables, I want a general solution... $\endgroup$ Oct 31, 2012 at 14:43
  • $\begingroup$ In that case, I suppose postfix application of Print[] is what you want, indeed. $\endgroup$ Oct 31, 2012 at 14:45

1 Answer 1

3
$\begingroup$

You print by having a Print[] on the expression you want to print. End all other statements with ;.

fooToPrint = bar[...]; Print[fooToPrint];  
fooNoPrint = bar[...];

e.g.,

a = 1 + 2;
Print[a];

b = 3 + 4;

a = b;
Print[a];
$\endgroup$

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.