Sugestion: when "my_fun" is a function signature interpret "my_fun(f)" or "my_fun f" as "cast<my_fun> f ".

Started by
2 comments, last by Zero_One_01 3 years, 4 months ago

Hi. I'm new here. This is my first post. I've been working on a reactive-programing library in Angel-Script (as in games you usually want to do temporal sequences of events) , that makes heavy use of functional-programing style. Based on my limited experience with the language and this project, I'd like to offer the following suggestion:

funcdef int int_function(int); 
funcdef int void_function(); 

int counter(int_function @a){return a(0);}
int counter(void_function @a){return a();}

Consider the following 3 possible lines of code:

int b = counter(function(int c){return c;}); 

It would be wonderful if this worked from the get-go, but the compiler considers this ambiguous. It gives multiple matching signatures to 'counter($func@const) error.

int b = counter(int_function(function(int c){return c;})); 

This looks nice (enough), and should work, but doesn't. The error is: No matching signatures to 'int_function($func@const)'. I don't know how to define anything that has that signature.

int b = counter(cast<int_function>(function(int c){return c;})); 

This finally works, but feels cumbersome to write.

Conversion of anonymous functions to their intended function signatures should be easier. You can usually tell what signature it's “supposed” to have by looking at the types of their arguments and return values.

Advertisement

Thanks for the suggestion. I will evaluate this to decide what can be done.

The syntax int_function(x) is used to create a new delegate object (when x is an object method), so it shouldn't be used to cast a lambda function to the appropriate signature.

However I think I'll be able to improve the auto detection of the correct function override so no explicit cast is needed. Alternatively I can make it so that it is possible to declare the full signature of the lambda function, including the return type.

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

Imho, being able to put more type information into the anonymous function signature would be nice.

This topic is closed to new replies.

Advertisement