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

Add @functorize #184

Merged
merged 2 commits into from Apr 22, 2016
Merged

Add @functorize #184

merged 2 commits into from Apr 22, 2016

Conversation

martinholters
Copy link
Member

The new macro @functorize(f) turns a function f into a functor object if
there is one in Base corresponding to f. E.g. @functorize(+) yields
Base.AddFun(); @functorize(<) yields < in Julia 0.3, but Base.LessFun()
in 0.4.

While at present this would more naturally be achieved by providing LessFun etc. in Compat, this PR is in anticipation of JuliaLang/julia#15804, which will deprecate all functors.

Note that the version check in this PR can only be finalized once JuliaLang/julia#15804 has been merged.

@timholy
Copy link
Sponsor Member

timholy commented Apr 20, 2016

This looks great. Very elegant and easy to read. 👍

Am I right in understand that I shouldn't merge this until JuliaLang/julia#15804 is finished?

@martinholters
Copy link
Member Author

@timholy Thanks. And yes, I'd like to adjust the version check before this is merged. I just wanted this to be ready and having received thumbs-up before JuliaLang/julia#15804 is merged so that affected packages don't have to wait too long for a strategy to handle the deprecations.

Oh, and I probably should add something for CentralizedAbs2Fun. And don't forget a short description in the README. Looks like this really still is WIP, I'm just glad the general approach didn't raise any objections.

@martinholters martinholters force-pushed the functorize branch 3 times, most recently from 28bf081 to f54230c Compare April 22, 2016 07:09
@martinholters
Copy link
Member Author

Rebased, added README entry, added a few more cases (including CentralizedAbs2Fun).

Once JuliaLang/julia#15804 has been merged and the version check fixed, this should be done.

@martinholters martinholters force-pushed the functorize branch 3 times, most recently from 3e85a00 to b3fc658 Compare April 22, 2016 07:53
export @functorize
macro functorize(f)
# TODO replace with proper condition on version once Julia#15804 is merged
if VERSION >= v"0.5.0-" && !isdefined(Base, :BitFunctorUnary)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ready?

The new macro @functorize(f) turns function f into a Functor object if
there is one in Base corresponding to f. E.g. @functorize(+) yields
Base.AddFun(); @functorize(<) yields < in Julia 0.3, but Base.LessFun()
in 0.4.
Note that `@functorize(centralizedabs2fun)` returns the type which can
then be used to construct the actual functor as e.g.
`@functorize(centralizedabs2fun)(23)`.
@martinholters
Copy link
Member Author

Updated the version check, so as long as the CI checks don't find some last-minute-errors I might have introduced, this should be good to merge.

@martinholters martinholters changed the title WIP: Add @functorize Add @functorize Apr 22, 2016
@tkelman tkelman merged commit 195de1a into JuliaLang:master Apr 22, 2016
@tkelman
Copy link
Contributor

tkelman commented Apr 22, 2016

Very nice. Thanks much!

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

Successfully merging this pull request may close these issues.

None yet

3 participants