-
Notifications
You must be signed in to change notification settings - Fork 6
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
Command to store from stack into variable #6
Comments
Hello again! I think this makes good sense. In I think it would make sense to have a special
I'm not sure if the value(s) should then be popped off the stack, but I think they should (which matches Something like that? |
I'm not sure I understand how the command could be given an optional variable name without passing it through the stack. Would it be passed through the modifiers field, like
Sounds great to me! |
Yeah..... I'm just looking at the code and I don't see how to do that (cleanly) either. So I suggest we just start with the simple case (variable name on the stack) and see how that works. You can do it if you like, though I am also doing it :-) |
OK, have a look at #7 BTW, I think the default way of putting args onto the stack feels really backwards! It feels to me much more natural to think only afterwards that you want to store something into a variable, or that you want to join some strings or apply some function. You can use the Anyway, see what you think of this. If you don't want to fetch it & test it out I'll just merge it & you can update and try it that way. Thanks! |
Actually, I think I see where I did it wrong. When working with RPN you do things from the inside out, so for So I think this thing has its default wrong. |
Indeed what I had in mind was to pass the variable name last, since as you said it, you normally realize that you want to save the value to a variable at that time (Also, if the variable was passed first, to save the whole stack you would need to start by pushing the variable name, which doesn't make much sense to me). So the function should really be And no need to merge it right now, I can test from your branch no problem. |
OK, but the I think we should put out a version 2 that changes the default argument order. |
Oh, I see. I hadn't looked closer at the code yet. What makes this "variable name before variable value" order is So what you're suggesting is to change the order assumed by |
Actually essentially what needs to be done is to switch the All in all this seems very good as it makes the default behavior more postfix-like. |
Yes, that's what I'm suggesting. I don't know if the code change would be that simple. Many tests would break (which is fine). I'd bump up the major version number since this is backwards incompatible. I would also consider just getting rid of the |
OK, I think I'll merge this branch, assuming you think it's ok. And I'm going to open a ticket to reverse the default arg order. I could add a command-line option to let people keep the old behaviour. Though I don't know if there any other users in the whole world! :-) It would make things quite messy (IMO). Let's see. |
Yeah, go ahead and merge it. The reversed default arg order makes me more confused the more I think of it hahaha. But I guess that's a separate issue and I can think it over and we can discuss it better in its own issue. The store command added in this PR shouldn't have any impact on that, and looks great to me. Also, thanks for going ahead and implementing it :). |
OK, merged & uploaded. Thanks! I've realized that what I did last night re reversing makes things feel more comfortable but is actually inconsistent. Anyway, will say more over in #8 at some point. |
I'm not sure this is something that makes part of the RPN workflow (I admit to not having used RPN much before), but I find myself wanting to save the value that is on top of the stack to a variable for later use, but from what I saw it seems this is not currently possible.
To me the most convenient/intuitive syntax would be to input
my_var=
, and with that, the value on top of the stack would be stored in themy_var
variable, but it isn't much like the rest of rpnpy's syntax, so perhaps it would complicate the parsing code too much...In any case, I think at least what could be done is to input the variable name as a string in the stack:
'my_var'
, and then use a special commandstore
, that accepts two parameters, the first is the value and the second, the variable name. After that the value would be accessible in themy_var
variable as usual.While we're at it, might as well make the
store
special command accept a list, so that it is possible to save the whole stack with'my_var'
, and thenstore:*
. Then, with the stack stored as a list in themy_var
variable, one could later restore the stack (assuming the stack is now empty) withmy_var:i
.What do you think, @terrycojones ? Is this a reasonable idea at all? Is some of this already available in rpnpy? Any more thoughts?
The text was updated successfully, but these errors were encountered: