lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


> Is there any reason not to support metatables for functions? Obviously  
> the __call metamethod is superfluous for functions, but I could imagine 
> uses for other cases. In particular, one could then consider using 
> operators to combine functions. Since these cases would currently just 
> end in an error or in the generic metatable for functions and given that 
> functions aren't particularly tiny objects to begin with, the cost seems 
> like it ought to be small.
>
> I'll have to think about whether this would be truly useful or just  
> interesting, but I was wondering whether there is a reason why it would 
> be a bad idea.

The main problem is that function metatables are global. So, if a
library defines * as function composition (for instance), all other
libraries (and the main application) cannot use * for other purposes.

-- Roberto