A complete working solution meeting the exact requirements of this question has been removed. Maybe the code is less contentious without further text.
\version "2.19.65"
myscale.sharp = #(make-semitone->pitch
(music-pitches #{ c cis d dis e f fis g gis a ais b #}))
myscale.flat = #(make-semitone->pitch
(music-pitches #{ c des d es e f ges g as a bes b #}))
sequence =
#(define-music-function (start end step scale)
(ly:pitch? ly:pitch? number? symbol?)
#{ $@(map #{ \myscale.#scale #}
(iota (1+ (/ (modulo (- (ly:pitch-semitones end)
(ly:pitch-semitones start))
(if (negative? step) -12 12))
step))
(ly:pitch-semitones start)
step))
#})
\displayLilyMusic \sequence a g 1 sharp
\displayLilyMusic \sequence f a -2 flat