Opened 10 years ago
Last modified 7 years ago
#13178 new defect
problem with newlines in gap eval
Reported by: | kcrisman | Owned by: | was |
---|---|---|---|
Priority: | major | Milestone: | sage-6.4 |
Component: | interfaces | Keywords: | gap |
Cc: | Merged in: | ||
Authors: | Reviewers: | ||
Report Upstream: | N/A | Work issues: | |
Branch: | Commit: | ||
Dependencies: | Stopgaps: |
Description (last modified by )
See this sage-support thread.
Basically,
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, while
str = r""" for n in [1..10] do for m in [1..10] do Print(m*n); Print(" - "); od; Print("\n"); od; """ gap.eval(str)
doesn't return anything at all (well, the empty string).
gap.eval(str,newlines=False)
doesn't help, though it seems like there must be something going on related to it, given the first command.
This makes (for instance) a lot of stuff not work in the notebook with %gap.
Change History (8)
comment:1 Changed 10 years ago by
- Description modified (diff)
comment:2 Changed 10 years ago by
comment:3 Changed 10 years ago by
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.
comment:4 Changed 10 years ago by
Hmm, I don't know that one would want to completely disable it, but at least MUCH better documentation on exactly when to expect this problem - and how to work around it, like your suggestions - would be really helpful to close this ticket.
Also, how horrible would it be to expand the cutoff to something higher in general?
comment:5 Changed 8 years ago by
- Milestone changed from sage-5.11 to sage-5.12
comment:6 Changed 8 years ago by
- Milestone changed from sage-6.1 to sage-6.2
comment:7 Changed 8 years ago by
- Milestone changed from sage-6.2 to sage-6.3
comment:8 Changed 7 years ago by
- Milestone changed from sage-6.3 to sage-6.4
Yeah, this is maddening.