Question: procedure overload

Hi

 

I want to make an overloaded function with two possible behaviours.

If the function is called with a list as parameter it shoud make something; if it's called with TWO lists as parameters, it shoud make another thing.

I tried first something like:

 

name:= overload ( [

proc(R::list) option overload;
print (" this is the version with a list");
body;
end,

proc(R::list , S:: list) option overload;
print (" this is the version with TWO list");
body
end

])

but what happens in this case is that no matter  I call name() with one or two lists, it's always the version with a list which starts.
 

Then I tried to write the code with an inverse order, ie with the procedure which takes two lists as the first in the overload:

 

name:= overload ( [



proc(R::list , S:: list) option overload;


print (" this is the version with TWO list");


body


end,

proc(R::list) option overload;


print (" this is the version with a list");


body;


end


])

with this version of the code, the overload works, but there is a little problem: if I call name(R), is the version with a parameter that is called (and this is good), but the print which refers to the TWO parameter version is nevertheless executed. So I get for exemple:

 

name([1,1]);

                      "this is the version with TWO list"
                      "this is the version with a list"
                                /  /750                 \
                          2   2 | |           1         |
                   -16 Enn  Pi  | |     ------------- df|
                                | |      (1/3)          |
                                \/40    f      S_h(f)   /

(the aswer is correct, so it really executed the one-parameter version of name()

Then my questions are:

1) Why must I write the code in this order, two parameters versione first in the overload, and one parameter second?
2) Why is the two-parameter print always executed?

thanks
S.

Please Wait...