renamed scan to mathematica's foldlist