Flat function with repeated sequence

There are functions like Join[ ] that accept a variable number of arguments. Join is a flat function, as the order of arguments matters, but Join[a,b,c] equals Join[a,Join[a,c]]. I want to create a module that has the same behavior.

It's no problem to create a function with two variables. In this example nested lists are joined horizontally:

JoinH[f_,g_] := Transpose[Join[Transpose[f],Transpose[g]]];

How do I rewrite this function/module so that I can pass a variable number of arguments to this function, like JoinH[a,b,c]?

• You mean something like adding the definition JoinH[a_, b_, rest___] := joinH[a, JoinH[b, rest]]? – jVincent May 17 '13 at 12:48
• Yes, but is it possible to write this in one line/function/ in a closed form without having two declarations of the same function? – kromuchi May 17 '13 at 13:01
• Can you change the Attributes ? – b.gates.you.know.what May 17 '13 at 13:10
• I guess you found my answer useful. I'm glad I could help, and thanks for the Accept. However, waiting longer may encourage additional answers that bring a different perspective. – Mr.Wizard May 17 '13 at 13:38
• Alright, let's wait then ;) – kromuchi May 17 '13 at 15:36

First, I'd like to point out that your "JoinH" function is already implemented by Join:

a = {{1, 2}, {3, 4}};
Join[a, a + 5, 2]
{{1, 2, 6, 7}, {3, 4, 8, 9}}

Second, you don't need Flat or whatever if you write the function to natively handle multiple arguments:

jh[m__] := Transpose[Join @@ Transpose /@ {m}]

jh[a, jh[a + 5, a + 11]]
jh[a, a + 5, a + 11]
{{1, 2, 6, 7, 12, 13}, {3, 4, 8, 9, 14, 15}}
{{1, 2, 6, 7, 12, 13}, {3, 4, 8, 9, 14, 15}}

Third, you should also look at the documentation for Fold.