i'd like to see it written without a loop, using map or filter...
notes = concat $ repeat ["c", "c#", "d", "d#", "e", "f", "f#", "g", "g#", "a", "a#", "b"]
majorSteps = [1,1,0,1,1,1,0]
scale key steps =
key : skip notesFromKey majorSteps
where
(_:notesFromKey) = dropWhile ((/=) key) notes
skip list skips =
fst $ foldl next ([], list) skips
where
next (m, xs) s = (m ++ [xs !! s], drop (s + 1) xs)
edit: cleaned it up a lot. This is Haskell by the way. The loop is replaced by a 'fold' in the skip function that reduces the list by skipping through it taking the skip distances from the skips argument. notes = cycle ["c", "c#", "d", "d#", "e", "f", "f#", "g", "g#", "a", "a#", "b"]
majorSteps = [2, 2, 1, 2, 2, 2] :: [Int]
scale note = map (dropWhile (/= note) notes !!) . scanl (+) 0
I think it's less clear, but if you want to avoid the rescan via (!!), then scale note = map head . scanl (flip drop) (dropWhile (/= note) notes)
Both result in λ> scale "d" majorSteps
["d","e","f#","g","a","b","c#"]