On the fragmentation of cosmic gas clouds. I. The formation of galaxies and the first generation of stars.