As with global variables, the use of static variables in this function introduces mutators into the code, and so the code is no longer in purely functional. The retain purely functional code it is necessary to pass the additional state into the function. IdiomMonadicProgramming and IdiomStreams are two structured ways of handling this sort of state.
This is also a good way to remove so-called "magic numbers" from code. By defining constants within a let expression they are hidden from the global namespace. This use of the let-before-the-lambda trick remains a pure-functional method of programming.
This method can also avoids unnecessary allocation in any code that uses constant values. For example the code below allocates a new string to hold the magic phrase every time it is called.
(define (magic-phrasename)
(let ((phrase"abracadabra"))
(string-appendname" the magic phrase is "phrase)))
By using the static variable idiom we can ensure only a single allocation:
(definemagic-phrase
(let ((phrase"abracadabra"))
(lambda (name)
(string-appendname" the magic phrase is "phrase))))
The general case of this optimisation is known as lambda-lifting.
The term static variables comes from C. C does not provide closures but are limited form of closure can be imitated by declaring variables as static.