cycling through different waves in a loop

Lets say I have ten waves (a1, a2, a3, ... a10), all of different lengths. I want to create a new wave that holds the mean value of each of those waves (i.e. a ten-point wave, where the first point is the mean of wave a1, the second point is the mean of wave a2, and so on).

I'm trying to write a do-while loop that will do this, but I'm not sure how to write a loop where it will cycle through different waves. Any help would be appreciated!

function test(lim, a1,a2,a3, a4, a5, a6, a7, a8, a9, a10, wavemeans)
    wave a1, a2, a3, a4, a5, a6, a7, a8, a9, wavemeans
    variable lim
    i = 0
    do
        wavemeans[i]=mean( //this is where I don't know how to call my different a# waves )
        i += 1
    while(i < lim)   //lim is used in case I only want to find the means of a subset of my waves
end
I believe there is no straightforward way to iterate through a list of input wave parameters. It could be done through trickery, but here is a more straightforward approach that uses a "wave wave" (a wave containing wave references):

Function/WAVE FindWaveMeans(waves, outputWaveName)
    Wave/WAVE waves     // Wave containing an array of wave references
    String outputWaveName
   
    Variable numWaves = numpnts(waves)
    Make/O/D/N=(numWaves) $outputWaveName
    Wave wOut = $outputWaveName
   
    Variable i
    for(i=0; i<numWaves; i+=1)
        Wave wIn = waves[i]
        wOut[i] = mean(wIn)
    endfor
   
    return wOut
End

Function Demo()
    Make/O/N=100 wave0=gnoise(1), wave1=1+gnoise(1), wave2=2+gnoise(1)
    Make/FREE/WAVE theWaves = {wave0, wave1, wave2}
    Wave means = FindWaveMeans(theWaves, "MeansWave")
    Print means
End

hrodstein wrote:
It could be done through trickery [...]


Out of pure curiosity, how would the trickery solution look like?
Maybe there is some undocumented support for va_arg-style functions :)
Quote:
Out of pure curiosity, how would the trickery solution look like?


Last night I thought there was a way to do it but this morning I don't think so.
Thank you, hrodstein. I think that will work perfectly, and will greatly simplify my code!