-
Notifications
You must be signed in to change notification settings - Fork 3
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
override of list (with a python-like list) #36
Comments
Another (maybe more general option) would be to define an operator that imitates python's If this works in function calls as well it could also be more intuitive than |
Let’s do this systematically. I’ll use Python for comparison here but the same works similarly in other interpreted languages.
@mschubert, I’m not sure what you’ve had in mind specifically for That said, I’d like a |
So I tried playing around with this, but Any way around this? |
We should coordinate better (that’s why I assigned this to myself …). 😉 I’ve pushed the branch with my experiments. But yes, this doesn’t actually work with modules, because objects are locked (for good reason!) and R insists on performing a useless assignment in this code. Incidentally, the code still works, despite the error message. But to use it properly, one of two things has to be done:
A third alternative would be to modify “modules” to allow objects to be modified. However, I consider this a very bad idea in general, and I cannot think of any other use-case. |
How about using option 2 and using b = import('ebits/base')
b$call$unpack[x, y] = 1 :2 You cold also add other functions to the Alternatively, I could picture a |
Good approach. However, how do we document this? Modules will never search nested environments for documentation. |
Only easy option would be to document |
Coming back to this: wouldn't it be much easier to implement it as a function? I still see value in this, e.g. combining with `unpack<-` = function(...) {
# take rhs and export to `parent.frame()`
...
}
unpack(a, c=b) = some_fun_returning_a_and_b() |
@mschubert Try it — this won’t work in the general case unless |
For future reference, a more ergonomic unpack syntax (that does not pollute the calling environment with bogus objects!) is described in my package ‘unpack’. Note that this is a proof of concept implementation, and is not intended for production use. In particular, it does not support nested structures or named (“destructuring”) unpacking. |
The following function was created by Gabor Grothendieck
who provided it graciously on the r-help list in June 2004.
https://stat.ethz.ch/pipermail/r-help/2004-June/053343.html
This function allows you to have multiple variables as output
He originally named the function list (overriding then the built-in function).
However, I have preferred to rename it for avoiding confusion.
The text was updated successfully, but these errors were encountered: