# How to input a list of arbitrary length into a function?

I would like to Write a function which takes a list of numerators, of arbitrary length, and produces a simple continued fraction of the form

    cf[{a,b,c,d}] =  a/(1+b/(1+c/(1+d)))


So far I did this

    cf[a_, b_, c_, d_] = Fold[g, 0, { d, c, b, a}]


but I do not know how to generalise it to a list of arbitrary length, so that user can type in any number of variables.

## 1 Answer

This should work:

cf[a__] := Fold[g, 0, {a}]

• Is this a pattern of a pattern? – Henry Wang Apr 29 '17 at 0:25
• @HenryWang I am not sure what you mean, but if you use the trusty Help, it will tell you that it is a BlankSequence, which matches any number of elements. – Igor Rivin Apr 29 '17 at 0:26
• Aha, thank you! I thought it is basically Blank of a Blank. But I think I am mistaken. – Henry Wang Apr 29 '17 at 0:35