-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
overload call / () operators? #2403
Comments
+1 I kept wanting to do this to make it easier to package a function with its gradient as a single object. |
See also (but not dup of) #1974. |
Jeff and I were just talking about making |
By "can't mean the same thing" I mean even though they look syntactically similar, they can't have the same meaning or you're defining |
@StefanKarpinski, I'm not sure I understand the circularity. Make |
Because |
But you just need a single special case in the parser to eliminate this. |
Right, but that special case is precisely to avoid the circularity. Anyway, I'm being concrete enough for this to be very helpful. I'll try to come up with something more concrete soon. |
I'm not being concrete enough, rather. |
+1 The various polynomial packages define ApproxFun ended up overloading getindex instead, as a partly justified workaround. There was some interesting discussion on the mailing list at the time. Today I'm working on the Fast Gauss Transform for evaluating the convolution of a set of points with a gaussian kernel (similar to the existing KernelDensity package, but with a different algorithm). So far I have an api that looks like t = fastgausstransform(points, values, bandwidth)
evaluate(t, 2.0) but I have some anxiety about collisions if I export a function called t = fastgausstransform(points, values, bandwidth)
t(2.0) I realize I could return an anonymous function instead, but I would like to support more operations on the transforms, like differentiating or adding them. |
I would imagine this would also lend to a nicer solution here, so you know, it should probably be a high priority and stuff... |
Regarding syntax, I guess we would need syntax for defining functions and their superfunctions ( / supertypes) and not just syntax for methods as we have now. Would we differentiate between abstract and concrete functions, or should all functions be subtypable? (I guess it comes down to what's needed for efficiency?) |
Wouldn't it be useful to have |
I'm a little dubious about that. Up to now, |
See the working branch #8008. |
I think this idea is not compatible with |
@rfourquet, if you have a function named |
It might make sense to have something about mutating functions built into the language, but using a magic |
Rust's ownership model is quite interesting but seems far to finicky to use as is in Julia. I wonder if we could borrow some of the ideas and make a system that's less challenging for the proverbial "non-professional programmer" but keeps enough of the benefits to be worth it. |
Implemented by #8712. |
It might be nice if we could overload
call
(i.e.()
), so that one could provide a callable object and still have access to other data within it.For example, I'm running into this with my PyCall module. Many Python objects are callable as functions, but I don't want to automatically convert all of them into anonymous functions because you still want to have access to other members/attributes of the objects. Currently, you have to do
pycall(object, ...)
, but it would be much nicer if I could overload()
so thatobject(...)
was converted into apycall
as users expect.The text was updated successfully, but these errors were encountered: