-
Notifications
You must be signed in to change notification settings - Fork 370
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
Homoiconic REPL #1246
Homoiconic REPL #1246
Conversation
2f4270f
to
488494f
Compare
Ehhh...I'm not really a fan of this one... IMO part of what I love about Hy is that it's just Python, except different. If someone starts using Hy, they likely already know Python. Using the Python syntax in the repr isn't going to be confusing. More importantly, though, this only half-way works with Python classes. Imagine a Python class that reprs with Python collection syntax. You'd probably end up having to look at something like this:
which is worse than the current behavior. In addition:
Both of these could be fixed by separating the parsing and code execution (which would allow you to put Yeah...not a big fan... :O |
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.
See comment I left (too lazy to copy-paste).
Are you saying you would approve this if I made the changes you've requested, or not? I don't understand your point or your example about "this only half-way works with Python classes". Can you be a bit more explicit?
Can you give an example of how this appears to the user? |
I'm also 👎 on this. This has come up before #220 #351 #354. Python's |
I just thought of a weird compromise, and I'm not sure how I feel about it. If we implemented some kind of Hy string eval that we could invoke from Python, then we could make valid Python => '(1 2 3)
hy_eval("'(1 2 3)") |
Ah, no. I don't think that's good enough. You'd also need the reverse, Python, eval, since the collection can only represent objects by their Python => '(1 2 {3 4})
hy_eval("'(1 2 (eval \"{3: 4}\")") Nested quotes like that could get gnarly quickly. I don't think that idea is workable either. |
Yes, that's one reason I think that this change is better than trying to make more Python syntax into valid Hy syntax.
Yeah, that sounds like a bad idea.
Yes, that's why
We don't already have that, nor is it likely to be possible. For example, at the Python prompt,
That would seem to require making Python syntax into valid Hy syntax, which we just rejected. I don't like your compromise because it will add a lot of visual noise to REPL output, which needs to be easily readable to serve its function of convenience. |
Depends on what everyone else says.
|
It seems that our options are either to allow the inconsistency or to use a generic placeholder syntax for classes with no In your example, the column number and the caret position seem to be correct. |
You're not getting my meaning. I meant that things like |
|
Yeah, I only wrote it that way because that's what came out of the AST. That really could be simplified in the |
In any case, I think that what you're proposing is orthogonal to this PR. You're proposing how to make Python representations for Hy models, and this PR is about Hy representations for all sorts of values, including Hy models. The only way to see any of this PR's changes in the Python REPL would be if you did |
@hylang/core Anybody else want to chime in on this? (Assume I'll be able to fix the bug Ryan mentioned that |
Another idea is to have a command-line option that enables use of |
@gilch @kirbyfan64 What do you think of using a command-line option for this, as I mentioned above? If you're against the feature being on by default (with an option to disable it), how about off by default (with an option to enable it)? @tuturto Can you chip in? |
I guess I wouldn't mind it if it were disabled by default... That being said, what if we put a prefix? e.g prefixing the command with something (no clue what yet) would use this repr...or maybe a reader macro? |
Then you'd have to remember to use the prefix or reader macro or whatever for every command, which again reduces newbie accessibility. |
This is the kind of thing other Lisps would use a dynamic variable for hylang/hyrule#51. It would be nice to toggle other REPL features (like --spy) this way. Still, I do not approve. Even with a separate It's also more work to implement both a Thus spake @paultag
We should expect Hy users, even newbies, to know Python, at at least a basic level--just as Clojure(Script) users must understand Java(Script). I do not approve of trying to hide the Python that is in Hy, since this is the root of many of Hy's difficulties. I might even be helpful for newbies if we turned on --spy in the repl by default. |
Like I said, there's no reason one couldn't put a generic placeholder in place of an object with no
Spitting out values in a syntax that you can actually use as input is hiding? I mean, you don't think the fact that the input syntax isn't Python is hiding, do you? |
Long and good discussion. I love seeing people hashing out some hard problem respectfully ❤️ I'm having hard time deciding either way though. I would like the idea that I can just copy/paste repl output back to input and have it work. But I'm bit hesitant if it would be confusing to people (old and new to Hy alike) that it sometimes works and sometimes doesn't. Lets run an experiment: we could bring this in, have it disabled by default, activated by command line switch and see how it behaves in the wild. After some amount of time, we can get back to the matter and see what we learned. At that point we can adjust things or even remove it completely (as if any project would remove a feature, ever) if this turned out to be a bad idea. How does this sound like? I didn't look into code really. Just got up and had interesting looking notifications from GitHub waiting 😁 Oh, and can we fix REPL printing out what |
I don't think that's a bad idea. We can at least mention it in the tutorial to maximize the chance it will actually see use in the wild. |
14d6ff6
to
fbf87b5
Compare
Okay, I fixed the |
hm.. true. No need for the shortcut. |
I would not be at all opposed to modularizing the repl. Once that's done, I wouldn't be particularly opposed to contrib experiments taking advantage of it. That invocation does seem long-winded (though I suppose one can always use aliases or shell scripts for such things). I wonder what a good interface would be. Perhaps
If you want to mix-and match, say |
I can think of another advantage of the config module approach. You could set state in the module through a special repl command in the |
Okay. In the spirit of YAGNI, I'll just implement |
@gilch Done. |
5e5070a
to
2611723
Compare
Also, realized that => (macroexpand '(if (= a 1) "one" (= a 2) "two" "many"))
'(if* (= a 1) "one" (if (= a 2) "two" "many")) Somehow missed this fact while testing earlier. |
Okay, this should finally be ready to go. |
hy/cmdline.py
Outdated
tokens = tokenize(source) | ||
except PrematureEndOfInput: | ||
return True | ||
tokens = tokenize("(do " + source + "\n)") |
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.
Last thing, I swear!! :O
Would this be better as:
tokens = tokenize(source)
do = HyExpression([HySymbol('do')] + tokens)
do.start_line = do.end_line = do.start_column = do.end_column = 1
do.replace(do)
that way the (do ...)
doesn't appear in the stack traces/compile errors?
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.
In the current implementation, (do ...)
already doesn't appear. (Your example above no longer has do
in its output.)
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.
Hmm, but the underline from a HyMacroExpansionError
seems to be misaligned. I'll take a look at it.
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.
Done.
@tuturto Do you have any objections since you last approved 8 days ago, or are we good to go? |
@kirbyfan64 we're good to go |
This reverts commit 5db0fbf.
Thanks, folks. I redid the merge without squashing so the changes between commits are differentiated. |
This pull request adds a function
hy-repr
and uses it to print out stuff in the REPL (edit: only when you launch Hy with--hy-repr
).Closes #351.
#1244 is a prerequesite. Merge that first and I'll rebase this.
An annoying consequence of this change (edit: now fixed, using the method listed second below) is that
setv
at the REPL now prints the value of whatever you assigned. I think this is bad because when I'm doing data analysis on the REPL, I often say things like(setv x (some-function-that-produces-a-huge-pandas-dataframe))
, and I don't want that printed. I see two ways around this:setv
always returnNone
. The question of whatsetv
should return, particularly in the REPL, is kind of a mess, anyway (setv on tuple returns the tuple? #249, inconsistent return behavior for setv in repl #871, Do we *really* want setv to return a tuple? #1049), so this change would eliminate another weird corner of the language.ast.Assign
, and if so, don't print the value.As for the documentation examples, I don't think we should bother systematically updating them before we have documentation tests.