### FUNCTIONS WITH VARIABLE NUMBER OF PARAMETERS ###
==========================================================
Both compilers supports them though xHarbour is limited to all parameters
and does not support unnamed parameters. In Harbour you can declare some
named parameters and then unnamed just like in many other languages, f.e.:
func f( p1, p2, p3, ... )
The unnamed parameters can be used in different statements passing them
by '...' operator, f.e. as array items:
proc main()
AEval( F( "1", "2", "A", "B", "C" ), {|x, i| qout( i, x ) } )
func f( p1, p2, ... )
? "P1:", p1
? "P2:", p2
? "other parameters:", ...
return { "X", ... , "Y", ... "Z" }
or as array indexes:
proc main()
local a := { { 1, 2 }, { 3, 4 }, 5 }
? aget( a, 1, 2 ), aget( a, 2, 1 ), aget( a, 3 )
func aget( aVal, ... )
return aVal[ ... ]
or as function parameters:
proc main()
info( "test1" )
info( "test2", 10, date(), .t. )
proc info( msg, ... )
qout( "[" + msg +"]: ", ... )
The '...' operator saves references when push parameters and it can be
used also in codeblocks, f.e.:
bCode := { | a, b, c, ... | qout( a, b, c ), qout( "[", ..., "]" ) }
All parameters can be accessed also using hb_aParams() function but
in xHarbour it works correctly only for functions which does not use
any local parameters or declared with variable number of parameters
or when number of declared parameters is not smaller then number of
passed parameters. This code illustrates it:
proc main()
p1("A","B","C")
p2("A","B","C")
p3("A","B","C")
p4("A","B","C")
p5("A","B","C")
proc p1
? procname()+"(), parameters:", pcount()
aeval( hb_aParams(), {|x,i| qout(i,"=>",x) } )
proc p2
local l
? procname()+"(), parameters:", pcount()
aeval( hb_aParams(), {|x,i| qout(i,"=>",x) } )
proc p3(x)
? procname()+"(), parameters:", pcount()
aeval( hb_aParams(), {|x,i| qout(i,"=>",x) } )
proc p4(...)
? procname()+"(), parameters:", pcount()
aeval( hb_aParams(), {|x,i| qout(i,"=>",x) } )
proc p5(a,b,c,d,e)
? procname()+"(), parameters:", pcount()
aeval( hb_aParams(), {|x,i| qout(i,"=>",x) } )
In xHarbour it's only possible to declare all parameters as unnamed, f.e.:
func f( ... )
and then access them using hb_aParams() or PVALUE() (in Harbour it's called
HB_PVALUE()) function. There is no support for named parameters and ...
operator.
In xHarbour due to reverted behavior of references stored in array items
assign operation to items in array returned by hb_aParams() changes
corresponding parameters passed by reference. It does not happen in
Harbour where item references stored in arrays work like in Clipper.