suppressing output, and a command-line flag to support it

tnb2d@brunelleschi.cs.virginia.edu
Sat, 2 Apr 94 16:13:57 EST

The hack we made to python is *very* simple and
straightforward. Matt Conway simply made an ifdef that he sets when
compiling to NOT print output from non-None expression values, and
unsets when comipiling so that it does. It's this little bit of work
in the function eval_code from the file ceval.c.

DISCLAIMER: After making this hack, in order to see the
output of an expression you must print it (e.g. 'print x' instead of
just 'x'). All code written in this fashion is FULLY COMPATIBLE with
non-hacked version of Python, it's just full of (at that point)
unnecessary 'prints'.

---------%< snip %<------------------%< snip %<---------

case PRINT_EXPR:
v = POP();
#ifdef CONWAY_HACK
/* conway hack: done to prevent the annoying printing
of expresssions without assignment statements */
/* Print value except if procedure result */
if (v != None) {
flushline();
x = sysget("stdout");
softspace(x, 1);
err = writeobject(v, x, 0);
flushline();
if (killprint) {
err_setstr(RuntimeError,
"printing expression statement");
x = 0;
}
}
#endif
DECREF(v);
break;

---------%< snip %<------------------%< snip %<---------

I propose a command-line flag, perhaps '-s' for 'suppress', that
will replace the "#ifdef CONWAY_HACK" above with something along the
lines of "if (!suppress_print) { go ahead and do it...". This must be
something other people have wished for in the past, otherwise no one
would have come up with all of those neat hacks like assigning return
values to None, or and-ing them with None, and so on and so forth.
When I stated in an earlier post that there was a flag that I
thought would do this that didn't I was talking about the '-k' flag.
It just seemed odd to me that if you wanted to produce a program that
gave no output, raising an exception when an expression might have
printed was implemented before simply not printing the expression
values!

-------> Tommy.

"Subvert the parental paradigm - Refuse Birth."