patternMinor
Is there a formal term for functions that have static state across executions?
Viewed 0 times
formaltermexecutionsthatforstateacrossfunctionstherehave
Problem
Two examples, one in PHP:
A similar effect can be achieved with closures in javascript:
In javascript I've really just created an object. Implementation details not withstanding, does stateful-functions have a formal name?
function adder($i){
static $a = 0;
$a += $i;
return $a;
}A similar effect can be achieved with closures in javascript:
var adder = (function(){
var a = 0;
return function(i){
a += i;
return a;
}
})();In javascript I've really just created an object. Implementation details not withstanding, does stateful-functions have a formal name?
Solution
Not that I know of, but "stateful function" is reasonably descriptive. In informal conversation, that's what I'd use, as long as I suspect the audience will understand what I mean. In formal writing, I might still use the same phrase but also provide a careful definition of what I meant by that phrase. Really, that's a large part of what "formal" writing is about: it's about being precise about what you mean.
Context
StackExchange Computer Science Q#45182, answer score: 3
Revisions (0)
No revisions yet.