NYSE_CGW_FIX_GATEWAY - Java TransactTools ttConnect based FIX Gateway for NYSE Arca Exchange
What are closures ?
In a simplest sense, a Closure is a function instance, just like class instance, with each function instance is instantiated with the specific value. In Python for example where everything is an object - modules, classes, functions, attributes etc., a closure is an object returned by a function which is instantiated with parameters it is invoked with. The object returned in this case is a function ( an inner function ) instance returned by another function (an outer function).
Now a more canonical explanation definition of closure.
"A closure is data attached to code " . A Closure is about maintaining state of some kind in functions.
Many functional languages ( Lisp, Haskel, Scala and other ) rely heavily on closures. Python, support it, but it's not at the very core of the language. Python, however, is a fine language for getting to know closures. So, even if your expertise is in some other language, you might learn a thing or two here.
An Example
Now consider this :
def make_log(level):
''' a closure that manufactures different logs'''
def _anon(message):
print ("{}: {}".format(level, message))
return _anon
if __name__ == '__main__' :
main()
print(main.__doc__)
# log_info closure
log_info = make_log("info")
# log warn closure
log_warn = make_log("warn")
# log error closure
log_error = make_log("error")
log_info("loading configuration file") #invoking log_info closure
log_warn("config value missing. using default value") # invoking log_warn closure
log_error("network socket error. can not connect to server") # invoking log_error closure
Spark - RDD how do they work ?
NYSE_CCG_FIX_Specification
NYSE_CCG_FIX_GATEWAY Specification - Java TransactTools ttConnect based FIX Gateway for NYSE Classic Exchange
Subscribe to:
Comments (Atom)