-
Notifications
You must be signed in to change notification settings - Fork 162
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add functions to View, Display, and Code (formerly Print) to a stream #895
Conversation
Are we intending that these should have the magic 'indent/unindent' markers? Assuming we still like them, they probably should, as they are easy to strip out when don't want them (outputting the stream to a string for example), if we do it in the kernel the time won't be measurable. |
Also want to give an ordering (I assume each will delegate in some order, need to define clearly what that order is). |
Codecov Report
@@ Coverage Diff @@
## master #895 +/- ##
==========================================
+ Coverage 61.69% 62.82% +1.12%
==========================================
Files 970 970
Lines 295646 295320 -326
Branches 13057 13055 -2
==========================================
+ Hits 182395 185521 +3126
+ Misses 110612 106997 -3615
- Partials 2639 2802 +163
|
I am not even sure whether I want delegation at this level, or just fallback to some reasonably uninformative Is there a good argument to delegate? Does python delegate between There is of course also the question whether both |
1e011df
to
f126580
Compare
As for the markers: At least for "formatted output" the markers are of course useful. I somewhat would wish that The goal should in my opinion be to do less implicit magic, but be able to do it explicitly if wanted. |
As for the markers: It is of course possible to strip them out when generating a string; we'd then want a special string stream "subtype" which does that for us, I guess (to minimize the overhead)? But for completeness, here is another alternative: instead of "printing" marker strings into streams, use special "marker objects", and perhaps a special "marker aware" print function... I'll try to illustrate this with a hypothetical example. Consider this, from the GAP library: Print("PartialPerm(\>\> ", DomainOfPartialPerm(f), "\<, \>",
ImageListOfPartialPerm(f), "\<\< )"); It might become something like this: PrintWithMarkers(stream,
"PartialPerm(", Indent,
Indent, ", DomainOfPartialPerm(f), Unindent, ", ",
Indent, ImageListOfPartialPerm(f), Unindent, Unindent, " )"); or perhaps PrintWithMarkers(stream,
"PartialPerm(", Indent(2), ", DomainOfPartialPerm(f), Indent(-1), ", ",
Indent(1), ImageListOfPartialPerm(f), Indent(-1), " )"); Here, the function The whole thing is inspired by C++'s Yet another alternative would be to have a separate (un)indent function, like so: PrintTo(stream, "PartialPerm(");
ChangeIndent(stream, 2);
PrintTo(stream, ", DomainOfPartialPerm(f)")
ChangeIndent(stream, -1);
PrintTo(stream, ", ");
ChangeIndent(stream, 1);
PrintTo(stream, ImageListOfPartialPerm(f))
ChangeIndent(stream, -1);
PrintTo(stream, " )"); This is perhaps easier to implement, but more cumbersome, and IMHO harder to read. |
The main problem in my eyes with the whole In addition, the semantics of Display/ViewObj/Print resp. DisplayString/ViewString/String are inconsistent and confusing, making things even more painful. To resolve this, using streams is IMHO the right approach: It is less cumbersome and fragile than trying to capture the output of a print operation to the screen. And it has the potential of avoiding the performance problem that is caused if one first prints into a string and then outputs the string, which can become serious if one prints a lot of data (but note that I say it has the potential -- it all depends on how much overhead the streams cause by themselves. I'd be more comfortable with this work if it included some benchmarks that studied the performance different between, say, Moreover, there should be a clear plan on what to do with this. At the very least, a few "real" methods for Another question: What's up with Finally, we really would have to document how the various methods are supposed to interact -- the GAP manual has already something on this, which would have to be extended for the stream functions. |
About the The reason for this is that I'll rebase and make a fresh go at this, maybe on the train next week (though my train time is dangerously overcommitted as well again). |
Don't start too many projects, it's fine to leave this sitting for another day. It's probably better to leave this for the relase after 4.9 anyway. I'd rather see us resolve open issues, impove the package build system etc |
f126580
to
7bcc72e
Compare
7bcc72e
to
f720a4f
Compare
Just as a small remark: I added I have also been experimenting with pretty printers in the pull request #1132 borrowing from Wadlers "prettier printers" paper, but that is very much a work-in-progress. |
f720a4f
to
b23b4c6
Compare
## In order to achieve a special behaviour of records as in &GAP; 3 such | ||
## that a record can be regarded as equal to objects in other families | ||
## or such that a record can be compared via `<' with objects in other | ||
## families, one can load the file `compat3c.g'. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might as well remove the reference to compat3c.g
.
Also, I think this renaming and splitting of record.g
is of independent interest, so we could merge it before the rest of this PR (which would reduce the diff in this PR, making it easier to review).
@@ -0,0 +1,311 @@ | |||
# record.g |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change this to record.gi
?
This pull request is part of an attempt (and a first step) at cleaning up GAP's output path, it is part of an attempt to provide
libgap
functionality as well as a cleaner Jupyter interface within the GAP codebase.I propose to first add the operations
ViewObjToStream
,CodeObjToStream
, andDisplayObjToStream
. The added code is to be understood as a first suggestion, is fully backwards compatible, and does not change any of GAP's behaviour yet.This change should make it possible to implement
ViewObj
,ViewString
,PrintObj
,PrintString
,Display
, andDisplayString
in terms of the above operations, removing the need to implement two variants of every function (one for the direct output and one for theString
variant).(I am aware of the existence of
PrintTo
andAppendTo
)