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

Change the default behaviour of the :r modifier #8

Open
terrycojones opened this issue Dec 2, 2020 · 2 comments
Open

Change the default behaviour of the :r modifier #8

terrycojones opened this issue Dec 2, 2020 · 2 comments
Assignees

Comments

@terrycojones
Copy link
Owner

Swap this around to make the order in which args are specified for special commands like join and apply and store are more natural. See discussion in #6.

@nfraprado
Copy link
Contributor

OK, so I just tested the PR on #9 and it's great!

The store receiving the variable name from the top of the stack is just how it's supposed to be. Also, map receiving the function from the top and join receiving the string delimiter from the top feel very good.

What you had commented on it being inconsistent I don't think is a problem, as rpnpy already defines a join function, although in pure python it is a member function called on strings. I think that's ok as long as it is documented (like, "In rpnpy, map should be called with the function after the iterable"). To me rpnpy is all about being convenient to use (without parenthesis!) as well as giving the flexibility and extensibility of python.

The thing I was worried about was that rpnpy would reverse the parameter order on all functions, including those defined by the user, which I think would be very confusing, but I just tested here and that's not the case. From what I could tell, only store, map, join and apply are reversed, although I still don't understand how that criteria is defined. I'd expect there to be a list_of_functions_that_should_be_reversed, but there doesn't seem to be one.

I also wonder if this should be something exposed to the user so they could import a function in their startup file and use it reversed inside rpnpy, although on second thought they could just define a function of same name that calls the imported function with parameters reversed. Simple enough and no additional work required.

@terrycojones
Copy link
Owner Author

Hi. Thanks. Yes, I agree, the #1 priority should be that it's pleasant & natural to use, and this change certainly feels more natural to me too.

The reason function args aren't also reversed is because I switched around the behaviour of _findWithArgs (exactly as you suggested, thanks) but I didn't change the code in _runFunction where it says if modifiers.reverse and args:.

So if you consider that func(a, b, c) and map(str, (1, 2, 3)) are both functions in which you specify a set of arguments corresponding the the things that have commas between them, then there's the inconsistency (i know you already see it, I'm just putting it in terms that I think of it in). I think you're right, the README should just say that there's a class of functions that take one special thing off the stack and then some others, and that in those cases the special thing (a function, a string) should be pushed on last & that that's what we (the only users in the world, AFAICT :-)) find most natural.

So I'll update the README a bit.

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

No branches or pull requests

2 participants