Weird behaviour of Print/View commands in notebook()

asked 2012-01-14 13:14:02 +0200

GaryMak gravatar image

updated 2012-01-17 11:20:24 +0200

kcrisman gravatar image

Hi not the world's biggest problem, but both on a virtual box version on Windows 7 AND on a Mac OS X 10.6.8 the following GAP code gives bizarre behaviour inside sagenb (of course I encountered it in a real program, but I have managed to distill the problem down to this silly piece of code):

b := 0;

for ii in [1..2] do

    for jj in [1..2] do

        Print( ii,jj );Print("\n");

        Print( jj,ii );Print("\n");



Now, as it stands this program prints out a series of lines containing the expected numbers. If you comment out the top (dummy) line by placing a # at the beginning of the line, there is suddenly no output. If you then comment out one of (either one!) the "Print..." lines in the middle, then the output re-appears (of course only half as much). It is possible to create other similar pathological behaviour but I guess I've given you the general idea ...

Needless to say, when this type of thing occurs in the middle of large programs it can be utterly baffling!

I presume I am missing something; but I couldn't find this anywhere on the forum ...


edit retag flag offensive close merge delete


I assume this does work in standalone gap? What if you try (from the command line) `sage -gap` or in Sage `gap_console()` - does this still happen?

kcrisman gravatar imagekcrisman ( 2012-01-17 11:21:16 +0200 )edit

Thanks for your help and for correcting my code input! Yes indeed it works fine (ie does what the code should do, as opposed to the strange stuff) in gap_console() from within ./sage in a bash terminal on my Mac.

GaryMak gravatar imageGaryMak ( 2012-01-18 06:46:01 +0200 )edit

And I assume you have chosen "gap" from the drop-down menu, or put %gap at the beginning of the cell? I'm sorry for asking the obvious, but this happens to me all the time after I've demonstrated running pure Python in the notebook...

kcrisman gravatar imagekcrisman ( 2012-01-18 09:16:57 +0200 )edit

yes I use the drop-down menu at the top. This actually occurs all the time inside large blocks of code which otherwise seem to compile fine - so it is all being interpreted correctly as far as I can see ... with the exception of course of this view/print stuff!

GaryMak gravatar imageGaryMak ( 2012-01-18 17:22:03 +0200 )edit

by the way one thing I forgot to mention which may help you pin it down: the output is suppressed in these situations even when there is an error: for example, even if I put a typo in one of the lines which would cause it to spit out the "Traceback .... " stuff, nothing comes out. (Also it happens no matter how much I click on the left to "liberate" the messages in case they had been previously hidden etc)

GaryMak gravatar imageGaryMak ( 2012-01-18 17:33:17 +0200 )edit