There are two ways that sage sends data to GAP.  The first is to send it line 
by line, and the second is to send it via a file.  This last is used when there 
is a lot of data because, IIRC, it's faster.  However, this messes up the use 
of stdout e.g. Print.  So what's happening is if the input is long enough, it 
goes to a file.  That's why removing some of the prints makes a difference.  
You can also get the same effect by adding a bunch of spaces in the middle 
(they are stripped from the beginning and the end).

One way around this is to use 

gap.eval(...., allow_use_file=False)

which allows you to see that this is in fact the cause of the problem.  The 
second method is to change the cutoff (default is 100)

gap._eval_using_file_cutoff = 1000

or disable it entirely

self._eval_using_file_cutoff = None

You can set it in ~/.sage/init.sage to make it "permanent".  

As for a truly permanent solution, we could try disabling it if we see a 
function that prints to stdout like Print or Display, but it wouldn't work for 
custom functions.  I don't think there is a way around this based on how GAP is 
currently written (except not using a file), but I could be wrong.

-Ivan

On Jun 29, 2012, at 5:05 AM, kcrisman wrote:

> On Thursday, June 28, 2012 10:39:01 PM UTC-4, kcrisman wrote:
> Hi Walter!
> 
> On Thursday, June 28, 2012 8:11:55 PM UTC-4, Walter Carlip wrote:
> I am having trouble using Gap within Sage. Often things fail to print or to 
> work from Sage even though they do work directly in Gap.  How do I report 
> bugs and get help?  Here is a sample program my tutors devised that does not 
> print under Sage, but works fine directly in Gap:
> for n in [1..10] do
>    for m in [1..10] do
>       Print(m*n);
>       Print(" - ");
>     od;
>    Print("\n");
> od;
> 
> (Removing the second Print command makes it work.  We have found many other 
> things like this that seem to fail without explanation.
> 
> 
> Are you using this in the notebook?   I can confirm this behavior in a %gap 
> cell.
> 
> There was, once upon a time, a problem with comments - see 
> http://trac.sagemath.org/sage_trac/ticket/3752 .  I feel like I've seen this 
> before as well in the lists, but can't quite find it yet.  #5043 and #3152 
> are conceivably, but unlikely to be, related.  I'll keep looking.
> 
> 
> 
> We can see exactly what is going on with this in the source code at 
> http://hg.sagemath.org/sage-main/file/9ab4ab6e12d0/sage/interfaces/gap.py#l365
> 
> Notice that this has nothing to do with the notebook - if you make a raw 
> Python string
> 
> str = r"""
> for n in [1..10] do
>    for m in [1..10] do
>       Print(m*n);
>       Print(" - ");
>     od;
>    Print("\n");
> od;
> """
> 
> and do gap.eval(str) in Sage, the same problem happens.
> 
> Maybe one of the tutors can track down.  Notice that 
> 
> str1 = r"""
> 
> for n in [1..10] do
>    for m in [1..10] do
>       Print(m*n);
>       Print(" - ");
>    od;
> od;
> """
> gap.eval(str1)
> 
> erroneously adds newlines.
> 
> '1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 2 - 4 - 6 - 8 - 10 - 12 - 14 -
> 16 - \n18 - 20 - 3 - 6 - 9 - 12 - 15 - 18 - 21 - 24 - 27 - 30 - 4 - 8 -
> 12 - 16 - \n20 - 24 - 28 - 32 - 36 - 40 - 5 - 10 - 15 - 20 - 25 - 30 -
> 35 - 40 - 45 - \n50 - 6 - 12 - 18 - 24 - 30 - 36 - 42 - 48 - 54 - 60 - 7
> - 14 - 21 - 28 - 35 - \n42 - 49 - 56 - 63 - 70 - 8 - 16 - 24 - 32 - 40 -
> 48 - 56 - 64 - 72 - 80 - 9 - \n18 - 27 - 36 - 45 - 54 - 63 - 72 - 81 -
> 90 - 10 - 20 - 30 - 40 - 50 - 60 - \n70 - 80 - 90 - 100 -'
> 
> Oh, that's the problem.
> 
> gap.eval(str,newlines=False)
> 
> gives the correct answer.  Now the question is, why?
> 
> This is now http://trac.sagemath.org/sage_trac/ticket/13178.  Gap experts are 
> welcome here; maybe a newline is surreptitiously entered at the end of a "od"?
> 
> - kcrisman
> 
> -- 
> To post to this group, send email to sage-support@googlegroups.com
> To unsubscribe from this group, send email to 
> sage-support+unsubscr...@googlegroups.com
> For more options, visit this group at 
> http://groups.google.com/group/sage-support
> URL: http://www.sagemath.org

-- 
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org

Reply via email to