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."