-
-
Notifications
You must be signed in to change notification settings - Fork 368
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
Printing results #37
Comments
You provide an implicit This is describe too-briefly in http://lihaoyi.github.io/Ammonite/#Ammonite-PPrint. Could definitely use more prose. |
I haven't been able to make it work for long enough to try much out.
I guess I'm skeptical that, assuming other things worked, that if I had an implicit Show[String] which always prints "bippy" and I gave the literal String "foo" then I would see |
(Make the above PPrinter, obviously not going to save the day.) |
I'm running against 47a361e, so guessing not fixed. |
yeah imports are borked and being tracked here #36. Hopefully after playing whack-a-mole and adding a few more unit tests for all these failing cases it should be in reasonable shape. |
Oh, when you say just you really mean "just". |
A few minutes ago, yeah :-) |
note that not all tests pass yet, but it should put it in a slightly better state. I'll come back and make it better after I'm done writing puppet scripts for $$$ at work |
Update: it's not fixed :-| |
By the way, if you want to improve on the scala repl this is the hard way to do it. Trying to elicit expected behavior wrt implicits and user-given imports in a repl setting via a rat's nest of generated strings is never going to work right. You have to manage the namespace directly. |
@paulp I don't understand. I am managing the namespace directly, and have a |
@lihaoyi Yes, that's what I mean. Here are some excerpts from mine.
|
What it all leads to is taking the parse tree and attaching symbols to identifiers directly, based on the bindings you are tracking yourself. Then you hand that tree off to typer to let it go the rest of the way. |
@paulp Seems plausible. I don't know how well it'd actually work in practice: it seems pretty complicated, but stitching strings is starting to get complicated too. Likely I will keep this stuff in mind as I keep playing whack-a-mole with the string splicer, and if the string splicing gets too annoying then I'll try your approach |
This works now @ class C
defined class C
@ implicit def pprint = ammonite.pprint.PPrinter[C]((t, c) => Iterator("INSTANCE OF CLASS C"))
defined function pprint
@ new C
res2: cmd0.C = INSTANCE OF CLASS C |
Yes, it is pretty complicated, because the compiler is nothing but complicated. You haven't gotten to the real complications in in string land yet. Do you know why the repl creates all those nested objects? Do you intend to duplicate that approach? |
I know why the REPL creates nested objects, and I think I can avoid doing that. The main distinction is that I expand out imports into their individual names and the It's not 100% accurate yet (e.g. it doesn't distinguish the type namespace from the term namespace) but it's pretty darn close. If you can elaborate on what test cases w.r.t. implicits would fail, we may be able to fix them, or we may decide that some of the semantics are just broken (e.g. Scala's ambiguous-import errors) and document/wontfix them rather than trying to emulate. |
I guarantee you that you underestimate the complexity of reproducing the compiler's rules for ambiguous imports. You will never make it work well this way. I won't need to elaborate because you will discover it for yourself. |
I await my enlightenment then ^_^ |
Can you please provide a hook for how to print repl results? Pretty-printing is by default defined for most standard library types, as well as case classes and case objects. For other types not supported, it falls back to using toString says the doc. That's all undesirable for me.
I've gone to great lengths not to let toString infect everything in my library. It's essentially impossible to get out in front of scala's call to scala.runtime.ScalaRunTime.replStringOf because sbt is proguarded and bundled with a stripped down version. But Ammonite doesn't have to be as hostile to decent printing. I have a method like
If there were some way to get the ammonite repl to use it on all results it would be hugely helpful.
The text was updated successfully, but these errors were encountered: