-
Notifications
You must be signed in to change notification settings - Fork 40
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
Re runs all previous commands generates unexpected results #127
Comments
Yup. That's actually how ICR works. I thought we had a message that printed when you ran icr to actually tell you this 🤔 this thing... not sure why it didn't show for you. Since Crystal doesn't have an interpreter, the only way to evaluate the code is to shove it in to a file, compile that file, and run it. Each time you run some code, it appends to that temp file, compiles it and runs it. If it didn't do this, then variables wouldn't work line to line. So in your case, it's calling Unfortunately, until Crystal gets a built-in repl, this is just how it's going to work. Here's more discussion on it #79 if you'd like to chime in on that. |
Hey @jwoertink
All points are working as expected except #1 for which I could not find the way to retrieve all the local variables from the command, something like this: https://ruby-doc.org/core-3.0.1/Kernel.html#method-i-local_variables macro print_vars
var1 = 10
var2 = 10
{% puts @type.instance_vars %}
end
print_vars # ==> []
Maybe you @jwoertink or some else can help me with this and then create the corresponding PR. Best regards! |
@owen2345 Could you explain how this will work when a variable is, for example, a file that points to an open file descriptor? The file descriptor will be gone. You just have to accept the limitations of icr. The other way to do this would be:
I think there's no fix for icr that will work all the time. Do you know about the command |
Also not every type is JSON serializable. Finally, I saw you posted a request on the forums to get the local vars. You don't need that in the compiler. You can parse the source code provided to |
Hey @owen2345, I applaud you for attempting this. I tried for a bit with the idea of using something like redis to store data between compiles, and memoize each call. Crystal doesn't have a way to Marshal data though, and like @asterite said, not every type is JSON serializable, so eventually my path was bunk. I know it's not the best answer, but really I think there's not much you can do about the limitations. If using the I don't want to discourage you, but I also would hate to have you waste a ton of hours and energy on something that could be better spent elsewhere. |
Hey @jwoertink @asterite thanks for answering. Of course it is possible, check this in progress PR: #128 |
Hi,
I am using this cli with Amber and having the following:
Every time I run any new command, all the previous commands are called again, in this case Article is being created.
The text was updated successfully, but these errors were encountered: