[chuck-users] Identical functions

Hans Aberg haberg at math.su.se
Sun Jan 24 18:30:37 EST 2010

On 24 Jan 2010, at 23:20, Stefan Blixt wrote:

> You can declare identical functions, with the first one apparently  
> taking charge:
> fun void g(int i) {
> 	<<< "fddf" >>>;
> }
> fun void g(int i) {
> 	<<< "fdfd" >>>;
> }
> g(3);

By contrast, return types can't differ, for some strange reason:

fun int g(int i) {
	<<< "fddf" >>>;

fun float g(float i) {
	<<< "fdfd" >>>;

   function signatures differ in return type...

In C++, I recall this is so for polymorphic functions, as then the  
argument selects which function copy to use at runtime, and it isn't  
possible to let the static return type vary.

That is, in ChucKish pseudocode
   fun int h(T); // Declaration.
   g => h; // g is some of the copies above.
   h(...) => s; // Syntax is statically checked, so s must be at most  
a polymorphic that
                // can hold all possible return values of h.

But that is not possible in ChucK yet.

> I have a feeling this is old news, but I can't recall this specific  
> issue being mentioned. It doesn't feel right. It's the same if the  
> functions are inside classes. Could it have something to do with  
> enabling cross-shred referencing?

It's likely a bug. Or how would that enable cross-shred referencing?


More information about the chuck-users mailing list