Stream: helpdesk (published)

Topic: How to properly define a function as argument?


view this post on Zulip Davi Sales Barreira (May 13 2021 at 17:32):

The package I'm working has a function myfunc( c, x::Vector), where c needs to be a function that receives two variables and returns a real, e.g. c(x,y) = x^2 + y^2. My question is, how do I specify this when declaring my function? Should I just write down in the documentation that c should have this form, or is there a more "correct" way of doing this?

view this post on Zulip Fredrik Ekre (May 13 2021 at 17:34):

Typically you would just document it, and let the code throw a runtime error.

view this post on Zulip Davi Sales Barreira (May 13 2021 at 17:36):

I see, so I could just leave like that. No need to restrict the type of c. Great, thanks :D


Last updated: Nov 06 2024 at 04:40 UTC