Is passing a function as an argument discouraged?

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Is passing a function as an argument discouraged?

Douglas Bates
I am writing a simulation function that loops over simulating a data set and fitting multiple statistical models to the data.  The exact form of the output will depend on which characteristics of the fitted models I wish to preserve.  My inclination is to pass a callback function to take the set of models after each iteration and extract and save the characteristics of interest.

However, I have a vague recollection that passing a function as an argument to another function was discouraged.  I believe it made type inference awkward.  Was that ever the case and, if so, is still the case?
Reply | Threaded
Open this post in threaded view
|

Re: Is passing a function as an argument discouraged?

John Myles White
Specialization of higher-order functions should be much improved in Julia 0.5.

On Friday, June 17, 2016 at 1:10:24 PM UTC-7, Douglas Bates wrote:
I am writing a simulation function that loops over simulating a data set and fitting multiple statistical models to the data.  The exact form of the output will depend on which characteristics of the fitted models I wish to preserve.  My inclination is to pass a callback function to take the set of models after each iteration and extract and save the characteristics of interest.

However, I have a vague recollection that passing a function as an argument to another function was discouraged.  I believe it made type inference awkward.  Was that ever the case and, if so, is still the case?
Reply | Threaded
Open this post in threaded view
|

Re: Is passing a function as an argument discouraged?

Stefan Karpinski
As in there should be no performance penalty at all in the vast majority of cases :)

On Fri, Jun 17, 2016 at 4:18 PM, John Myles White <[hidden email]> wrote:
Specialization of higher-order functions should be much improved in Julia 0.5.

On Friday, June 17, 2016 at 1:10:24 PM UTC-7, Douglas Bates wrote:
I am writing a simulation function that loops over simulating a data set and fitting multiple statistical models to the data.  The exact form of the output will depend on which characteristics of the fitted models I wish to preserve.  My inclination is to pass a callback function to take the set of models after each iteration and extract and save the characteristics of interest.

However, I have a vague recollection that passing a function as an argument to another function was discouraged.  I believe it made type inference awkward.  Was that ever the case and, if so, is still the case?

Reply | Threaded
Open this post in threaded view
|

Re: Is passing a function as an argument discouraged?

Douglas Bates
On Friday, June 17, 2016 at 3:24:43 PM UTC-5, Stefan Karpinski wrote:
As in there should be no performance penalty at all in the vast majority of cases :)

Great news!  Thanks. 
 
On Fri, Jun 17, 2016 at 4:18 PM, John Myles White <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="ZjZcTUVfBwAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">johnmyl...@...> wrote:
Specialization of higher-order functions should be much improved in Julia 0.5.

On Friday, June 17, 2016 at 1:10:24 PM UTC-7, Douglas Bates wrote:
I am writing a simulation function that loops over simulating a data set and fitting multiple statistical models to the data.  The exact form of the output will depend on which characteristics of the fitted models I wish to preserve.  My inclination is to pass a callback function to take the set of models after each iteration and extract and save the characteristics of interest.

However, I have a vague recollection that passing a function as an argument to another function was discouraged.  I believe it made type inference awkward.  Was that ever the case and, if so, is still the case?

Reply | Threaded
Open this post in threaded view
|

Re: Is passing a function as an argument discouraged?

Cedric St-Jean-2
In reply to this post by Stefan Karpinski
> As in there should be no performance penalty at all in the vast majority of cases :)

Any notable exception?

On Friday, June 17, 2016 at 4:24:43 PM UTC-4, Stefan Karpinski wrote:
As in there should be no performance penalty at all in the vast majority of cases :)

On Fri, Jun 17, 2016 at 4:18 PM, John Myles White <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="ZjZcTUVfBwAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">johnmyl...@...> wrote:
Specialization of higher-order functions should be much improved in Julia 0.5.

On Friday, June 17, 2016 at 1:10:24 PM UTC-7, Douglas Bates wrote:
I am writing a simulation function that loops over simulating a data set and fitting multiple statistical models to the data.  The exact form of the output will depend on which characteristics of the fitted models I wish to preserve.  My inclination is to pass a callback function to take the set of models after each iteration and extract and save the characteristics of interest.

However, I have a vague recollection that passing a function as an argument to another function was discouraged.  I believe it made type inference awkward.  Was that ever the case and, if so, is still the case?