-
Notifications
You must be signed in to change notification settings - Fork 12
PROOF OF CONCEPT: a function to write extension functions with warning #106
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
base: master
Are you sure you want to change the base?
Conversation
|
I did something similar here: https://github.com/WIAS-PDELib/ExtendableGrids.jl/tree/jpt/extension-error-proof-of-concept May be this is even sufficient. Let us see what the others say. |
|
I have now fiddled around with custom errors. |
|
Mid term the plan would be to put this in its own package since it's useful in many places.
|
|
@pjaap @j-fu I have now figured out how to do multiple arguments as well but would have restructure a lot to test it here as well. But I have tested it in a small separate file. I have also build this small macro: Then, calling |
pjaap
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting work :)
| function prepare_extension_function(fname::Symbol, weakdeps::Vector{Symbol}, args::Vector{Symbol}) | ||
| expr = quote | ||
| function $fname($(args...); kwargs...) | ||
| if mapreduce(x -> isdefined(Main, x) && isa(getfield(Main,x),Module), &, $weakdeps) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess you want to reduce by the operator && and not the binary &? I think they behave the same, but && is clearer
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would but reduce does not like that operator for some reason
| end | ||
|
|
||
| function simplexgrid_from_gmsh end | ||
| prepare_extension_function(:simplexgrid_from_gmsh, [:Gmsh], [:filename]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer to enforce key word arguments here:
prepare_extension_function(:simplexgrid_from_gmsh, weakdeps = [:Gmsh], args = [:filename])
Do not get your hands too dirty with macros 😉 Does this work if the extension function is type-annotated? |
The function in the extension actually has to be annotated otherwise you get a precompile error about overwriting the function in the extension. |
|
Ah I messed up the link in my previous post. I am not sure if we need more of this. It can certainly make sense to have an extra error type though. |
|
As for multiple extensions: And to increase visual difference I would add a convenience function that takes a single vector and calls the vector of vectors function internally. |

Thanks, Philip, let's discuss this.