Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Document System.write/print(object) return value #1128

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

Open
PureFox48 wants to merge 1 commit into wren-lang:main
base: main
Choose a base branch
Loading
from PureFox48:patch-1

Conversation

Copy link
Contributor

@PureFox48 PureFox48 commented Dec 26, 2022

Although System.Write(object) and System.print(object) both return their arguments, which is useful for method chaining etc., this isn't documented. The aim of this PR is therefore to remedy that.

Although `System.Write(object)` and `System.print(object)` both return their arguments, which is useful for method chaining etc., this isn't documented. The aim of this PR is therefore to remedy that.
Copy link
Contributor

Is there really a use of chaining with these methods, since it possibly produce surprising chain of methods? I mean outputting to stream should succeed or fail. In the fancier case, it should provide a fluent interface, not chain to the passed argument.
In addition, that behavior is not consistent with other printing/writing methods.

datatypevoid reacted with thumbs up emoji

Copy link
Contributor Author

TBH, I didn't even realize these methods returned anything until I read something @munificent said in this old Hacker News item:

I have the opposite feeling (possibly because Wren doesn't have implicit returns). Since library calls are expressions, they may as well return something useful when possible.

For example IO.print() returns its argument. That's handy for debugging the result of an intermediate expression. Say you've got:

someMethod(anotherOne(arg))

And something weird is going on. Giving IO.print() a return value lets you inject it in the middle:

someMethod(IO.print(anotherOne(arg)))

without having to hoist the subexpression out.

So, the use case is perhaps method injection for debugging purposes rather than method chaining and that makes sense to me.

Copy link
Contributor

mhermier commented Dec 26, 2022 via email

I think that theses are 2 separated functionality/concerns and should be decoupled. As this, I think, it provides a too rough debugging interface to be really usable even in the expressed/desired context. I suspect most users reason about it as a terminal expression. Not to mention, it allow to produce surprising expression like: System.print(42.3).floor Minimalism is nice, but what is the point if we need to relearn all the behaviors of the usual names.
datatypevoid reacted with thumbs up emoji

Copy link
Contributor Author

Although I have some sympathy with what you're saying - i certainly didn't expect these methods to return anything - the fact remains that this facility has been there for at least 8 years and, as people may be using it and there is an argument for doing so from Bob himself, we can't just remove it now.

Perhaps we should just leave it undocumented though I'll wait and see what @ruby0x1 thinks before withdrawing the PR.

datatypevoid reacted with thumbs down emoji

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /