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

rdmd --eval and --loop prints last @statement #320

Closed
wants to merge 2 commits into from

Conversation

timotheecour
Copy link
Contributor

@timotheecour timotheecour commented Feb 15, 2018

/cc @wilzbach @andralex @marler8997 @WebDrake

TLDR

if no trailing ;, print last statment starting with @

rdmd --eval="@1+2"
3
rdmd --eval="auto a = 10; auto b = [a, a + 1]; @b"
[10, 11]

this PR avoids some of the disadvantages of https://github.com/dlang/tools/pull/317/files
I was using this idea for a repl i was working on and seemed useful.

Advantages:

proposed syntax

use a delimiter (eg @ but let's not bikeshed about which one to use too much) to split the statment that shall be writeln'd:

NOTES

  • not sure what's the best symbol, @ is a good choice as easy to type and unlikely to appear by accident
  • TODO: could use something more robust based on tokenization to avoid pulling the wrong @ from:
rdmd --eval='"@"foo@bar"'

workaround: in this case the user can just use:

rdmd --eval='"writeln("foo@bar");'

and things will work. So tokenization could happen in future PR to improve things later

[1] no breaking behavior: what changes is that stuff that didnt' compile could now compile; that's acceptable tradeoff as it gives a meaning to previously invalid input

@dlang-bot
Copy link
Contributor

Thanks for your pull request and interest in making D better, @timotheecour! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
Please verify that your PR follows this checklist:

  • My PR is fully covered with tests (you can see the annotated coverage diff directly on GitHub with CodeCov's browser extension
  • My PR is as minimal as possible (smaller, focused PRs are easier to review than big ones)
  • I have provided a detailed rationale explaining my changes
  • New or modified functions have Ddoc comments (with Params: and Returns:)

Please see CONTRIBUTING.md for more information.


If you have addressed all reviews or aren't sure how to proceed, don't hesitate to ping us with a simple comment.

Bugzilla references

Your PR doesn't reference any Bugzilla issue.

If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog.

@joseph-wakeling-sociomantic

The goal here has nice aspects, but what's not nice is changing --eval's behaviour so that in magic special cases it does something different from evaluating normal D code. It feels quite unnatural for --eval to have behavioural differences from normal D evaluation, and even more so for --eval to allow special magic syntax that's not allowed in normal D code.

How do you feel about the idea of instead implementing a new flag (--write ... ?) that is specifically dedicated to printing out the result of the provided statement?

@joseph-wakeling-sociomantic

Slightly bigger picture concern: how do you decide what kind of statement is valid for these output purposes?

rdmd --write='"Hello, World!"'

... is obvious, but what about

rdmd --write='return'

... ?

@marler8997
Copy link
Contributor

FWIW, I slightly preferred #317, but I don't have a strong opinion either way.

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

Successfully merging this pull request may close these issues.

5 participants