-
-
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
finalizer function should be first argument #6454
Comments
Maybe a different name for the alternative form would be appropriate. Such as |
Why? |
Trying to avoid breakage. Or we could allow both argument orders, leaving |
Sure. Should we deprecate the |
I don't really have anything to add about the finalizer question per se. However, I have concerns about a somewhat related issue that I wanted to bring up. It is about the pipe forward operator |> and how on the one hand, I like a lot, while on the other I find it much too restrictive in Julia. In FSharp, a common pattern is to use the pipe operator as in the following pseudo code loadSomeData The map and reduce functions take (data, function). In each of the calls above, the resulting data from the previous line is used as the first input to map or reduce and the second parameter is the function. This is a pattern that is not available in Julia for a number of reasons. The first reason is that the |> operator seems to only apply to functions of one parameter only. julia> function myMap( x::Int, f::Function) julia> myMap(3, x->x^2) julia> 3 |> myMap(x->x^2) julia> exp(3) julia> 3|>exp I find that strange and unnecessarily restrictive. I doubt that it would be much harder from a parsing and compiling point of view to handle functions of multiple parameters. It is essentially done right now with the "do" construct (Thanks Stefan for pointing it out to me on the users list) `julia> function myMap2( f::Function, x::Int) julia> myMap2( x->x^2, 3) julia> myMap2(3) do x Perhaps there is a line continuation character I have not paid attention to and that part is not an issue. Perhaps the do pattern can be continuated and chained in a non obtrusive way but even if it did, I think that for full usefulness, it might have to be used in conjunction with the pipe operator because to get the pattern I describe from FSharp, the function needs to be the second parameter. So I would like to hear from you two as to whether this is something that was considered and already rejected or is this something you see might make the language more useful possibly. I for one, am a little taken aback by the limitation of the pipe forward operator. So I am suggesting that while you guys are thinking of changing the order of parameters to facilitate one pattern over another, you should take this one in consideration. Thanks for your consideration |
Check out #5571; there's been a bunch of discussion there about that very issue. |
Thanks for the pointer. So I see it has been considered. I don't really see a conclusion there though. I am still puzzled as to why the piping operator is restricted to one variable functions. I see the points made about "what is so special about the first parameter?" My take on it is that it is the simplest one to single out. And if we agree on that, then it should guide decisions for Julia API's such as the one about finalizer. By the way, I rather like tofinalize(x) do. I'll keep an eye open on issues about the pipe operator and will chime in if they come up. |
Will enable the syntax finalizer(x) do x ccall(:free_x, Void, (Ptr{None},), x) end See: JuliaLang#6454
I made a simple attempt at this, but the deprecation is creating warnings at build time. |
Will enable the syntax finalizer(x) do x ccall(:free_x, Void, (Ptr{None},), x) end See: JuliaLang#6454
Will enable the syntax finalizer(x) do x ccall(:free_x, Void, (Ptr{None},), x) end See: JuliaLang#6454
Bump, this needs a rebase. |
With so many changes do different parts of the code base, it needs to be done again, rather than a rebase. We should probably also consider changing the order of arguments in the |
We have gone two releases without changing the argument order. |
That doesn't mean we shouldn't still do it... |
I have to agree. I still think we should do this. The main hesitation is that if we completely change the way finalizers work at some point, this will have been a lot of pointless noise. Again, @JeffBezanson's input would be appreciated. |
To be consistent with other APIs and allow the use of do-block syntax, the finalizer argument to
finalizer
should be the first argument, not the second.The text was updated successfully, but these errors were encountered: