Skip to content
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

stream-line-column missing? #12

Open
rtoy opened this issue Oct 14, 2022 · 7 comments
Open

stream-line-column missing? #12

rtoy opened this issue Oct 14, 2022 · 7 comments

Comments

@rtoy
Copy link

rtoy commented Oct 14, 2022

As mentioned in http://www.nhplace.com/kent/CL/Issues/stream-definition-by-user.html, stream-line-column must be defined for every character output stream. Perhaps trivial-gray-streams should include a defgeneric for it? There might be other methods that are required; I didn't check. But stream-start-line-p says you need to define that or stream-fresh-line if stream-line-column returns nil. Don't know how that should be handled.

@avodonosov
Copy link
Member

avodonosov commented Oct 14, 2022

Question 1: Who should provide this method, the Gray Streams user code (e.g. the YASON library) or Gray Streams subsystem itself?

Reading the Gray Streams proposal text, the wording at first sight makes impression it's the user code responsibility. I am surprised to find this. But for many other cases where default method implementation must be provided by the Gray Streams subsystem the doc explicitly says "The default method ...".

The stream-line-column description does not have the phrase "The default method."

On the other hand, the description says

For every character output stream class that is defined,
a method must be defined for this function, although it is
permissible for it to always return NIL.

The fundamental-character-output-stream class is (pre-)defined by the Gray Streams subsystem. Does this requirement of having a default method apply to fundamental-character-output-stream? If it does, then the Gray Streams subsystem must provide the method.

Later, in the Discussion section of the doc, we read:

There are some differences of opinion about whether
certain operations should have default methods or required methods:
STREAM-LISTEN, STREAM-READ-CHAR-NO-HANG, STREAM-LINE-COLUMN,
and STREAM-START-LINE-P.

Question 2: If that's a responsibility of the Gray Streams subsystem, does it mean trivial-gray-streams or the underlying Gray Streams in a lisp implementation like CMUCL?

Currently trivial-gray-streams only implements methods only for stream-position and stream-read-sequence / stream-write-sequence - these methods are absent in the Gray proposal (most likely because their counterparts in the common-lisp package are absent in the "Common Lisp the Lanuguage" book). So the lisp implementations differ in generic function names and parameters for such functions, and trivial-gray-streams defines a portable interface for them, creates methods for implementation-specific functions from which it calls its portable version.

For all other functions we just re-export from the trivial-gray-streams package the symbols we imported from the current implementation-specific package.

Similarly to stream-position and to stream-read/write-sequence, since we see in practice the lisp implementations differ in existence of default method for stream-line-column, trival-gray-streams could be a point of unification. It can define a default method for (stream-line-column fundamental-character-output-stream) to return NIL on all implementations, or to signal an "user code must define stream-line-column" error on all implementations.

I personally see only advantages in having the NIL default method. What reasons could have those people mentioned in the Discussion section of the Gray proposal, who were against the default method for stream-line-column?

@rtoy
Copy link
Author

rtoy commented Oct 15, 2022

I'm not really sure; I've never really used gray streams before.

However, it seems useful for trivial-gray-streams to re-export stream-line-column from the implementation-specific package so that user code doesn't need to know about the implementation package. I guess this goes for all the other methods in gray-streams?

@avodonosov
Copy link
Member

Yes, stream-line-column and alll other gray function symbols are re-exported.

@rtoy
Copy link
Author

rtoy commented Oct 16, 2022

Oh, sorry, I didn't notice that it was re-exported. So we're all good here. I don't think trivial-gray-streams needs to define anything. It's up to the user to define a method for stream-line-column.

Closing issue. Thanks for your help!

@rtoy rtoy closed this as completed Oct 16, 2022
@avodonosov
Copy link
Member

avodonosov commented Oct 17, 2022

As a portability layer, trivial-gray-steams could shield users from differences in treatment of the Gray proposal by lisp implementations. To avoid cases when a code written and tested on an implementation where the default NIL method exists, suddenly fails on another implementation, as this happened with the YASON library.

I will reopen the issue, at least to keep this question more visible for now.

@avodonosov avodonosov reopened this Oct 17, 2022
@avodonosov
Copy link
Member

avodonosov commented Oct 17, 2022

BTW, regarding this quote from the Gray proposal:

There are some differences of opinion about whether
certain operations should have default methods or required methods:
STREAM-LISTEN, STREAM-READ-CHAR-NO-HANG, STREAM-LINE-COLUMN,
and STREAM-START-LINE-P.

and my question "What reasons could have those people mentioned in the Discussion section of the Gray proposal, who were against the default method for stream-line-column"

I guess for STREAM-LISTEN, STREAM-READ-CHAR-NO-HANG the reason is that the default methods are blocking (because implemented in terms of STREAM-READ-CHAR). The reasons for STREAM-START-LINE-P and STREAM-LINE-COLUMN are still unclear to me.

Of course, one thing is to not have default methods of these functions, for whatever reasons, and another thing is to sometimes (on some lisp implementations) have them, and sometimes not (on other lisp implementations). Such unpredictable situations is probably worse than clear choice for presence or absence of the default NIL method.

It is interesting that of the four functions only STREAM-LINE-COLUMN description is so vague. For the other three, the doc says exactly what is the algorithm of the default method.

@rtoy
Copy link
Author

rtoy commented Oct 17, 2022

For cmucl, I see that it's implementation defines methods for stream-start-line-p and stream-advance-to-column for fundamental-character-output-streams. These methods call stream-line-column.

I think cmucl should provide a method for stream-line-column for a fundamental-character-output-stream. See cmucl issue 147

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants