No but you can pass a list or array of values as a single parameter. That appears to me to be the best way to get the same functionality.
Come to think of it, you can also pass a single text parameter such as:
"Let ( [ A$ = 23 ; B$ = 5 ] ; 1 )"
and then use evaluate() to create variables with assigned values.
Note that these tricks work with script parameters as well.
speaking of arrays, it appears that I can't return an array as the result of a Custom Function. Any reason to think otherwise?
(i.e. $array = CustomFunction ( x ) ... $array = nothing)
You could 'pseudo-overload' the CF name by creating multiple CFs that all just call the master CF that has all the parameters.
You could 'pseudo-overload' the CF
Which was/is a common way to implement a recursive accumulator without the user having to pass it.
To erolst; and Wim: can you come up with some simple examples of this?
A working file with included CFs would be great of course. But lacking that, just a bit more explanation?
The examples could be trivial, but I'm just trying to picture this and perhaps others may as well.
I had not heard of common-accumulator method before.
Here you go.
True 'overloading' would be if we could keep the CF names the same but just have different sets of parameters. Can't do that in FM so we have to make the name different so may as well make it descriptive.
'full_name' is the master and constructs a full name out of the 3 parameters.
'full_name_no_prefix' calls the master and passes an empty for the suffix
'full_name_my_family' calls the master and passes a hard coded 'Decorte' for the last name and an empty for the suffix.
overloaded_CFs.fmp12.zip 66.9 K
1 of 1 people found this helpful
This is not limitation of return of custom function, you can't assign array values at once in FM. The workaround is using Let()
The most trivial I could think of:
The "worker CF" ...
_HowManyOdd ( aList ; acc ) =
Let ( [
val = GetValue ( aList ; 1 ) ;
isOdd = Mod ( val ; 2 ) ;
remainder = MiddleValues ( aList ; 2 ; ValueCount ( aList ) - 1 ) ;
counter = acc + isOdd
Length ( remainder ) ;
_HowManyOdd ( remainder ; counter ) ;
... that you call via:
HowManyOdd ( inAList ) =
_HowManyOdd ( inAList ; 0 )
where you only need to pass a list, without having to initialize the accumulator.
Nowadays we could do this with a single CF and a $var, but this was from way back in FM7.
Thanks, it is good technic.
But I think this is not answer for this thread, since ExecuteSQL() (or other functions having variable number of parameters like List(), Sum() etc.) can have any number of paramters (max 1000?)
Attempting to envelope the entire function into one, I'm currently using dummy parameters (here, it's just type0here). It doesn't matter what the user enters, but something has to be provided. This isn't really overloading - from the user perspective anyway.
// RECURSIVE FUNCTION
// targetVariable = the name of the global $$array
// type0here = current index, not needed by the user.
// returns the value count
If ( not IsEmpty ( sourceList );
$$tempListToArray = sourceList;
global = If ( Left ( targetVariable; 2 ) = "$$"; targetVariable; "$$" & targetVariable )
ListToArray ( ""; global; ValueCount ( sourceList ) )
// ELSE, ASSIGN OR EXIT
If ( type0here > 0;
var = targetVariable & "[" & type0here & "]";
val = GetValue ( $$tempListToArray; type0here);
string = "Let (" & var & " = " & Quote ( val ) & "; 0 )";
worker = Evaluate ( string )
ListToArray ( ""; targetVariable; type0here - 1 )
// CLEAN UP AND EXIT
listCount = ValueCount ( $$tempListToArray );
$$tempListToArray = ""
David Moyer wrote:
I'm currently using dummy parameters (here, it's just type0here). It doesn't matter what the user enters, but something has to be provided.
You don't really need a counter here because you can control the recursion by passing an ever-dwindling list.
I don't want to recursively pass a list.
Edit: let me rephrase that:
I'm trying to work around passing the list, not for efficiency reasons, but because this function will be used by another function that requires an array. And I understand that custom functions can't return an array - hence the global $$targetVariable array.