nested-function

Are nested functions possible in VBA?

落花浮王杯 提交于 2019-12-22 08:19:23
问题 I'm trying to clean up code by stripping parameters from a function within a private scope, like this: Function complicatedFunction(x as Double, param1 as Double, param2 as Double) ... End Function Function mainActionHappensHere(L as Double, U as Double ...) Function cleaner(x) cleaner = complicatedFunction(x, L, U) End Function ... cleaner(x) 'Many calls to this function ... End Function Is this possible? Compiler complains, "Expected End Function", since I'm beginning a function before

Is self captured within a nested function

人盡茶涼 提交于 2019-12-20 11:38:11
问题 With closures I usually append [weak self] onto my capture list and then do a null check on self: func myInstanceMethod() { let myClosure = { [weak self] (result : Bool) in if let this = self { this.anotherInstanceMethod() } } functionExpectingClosure(myClosure) } How do I perform the null check on self if I'm using a nested function in lieu of a closure (or is the check even necessary...or is it even good practice to use a nested function like this) i.e. func myInstanceMethod() { func

Is self captured within a nested function

你说的曾经没有我的故事 提交于 2019-12-20 11:38:02
问题 With closures I usually append [weak self] onto my capture list and then do a null check on self: func myInstanceMethod() { let myClosure = { [weak self] (result : Bool) in if let this = self { this.anotherInstanceMethod() } } functionExpectingClosure(myClosure) } How do I perform the null check on self if I'm using a nested function in lieu of a closure (or is the check even necessary...or is it even good practice to use a nested function like this) i.e. func myInstanceMethod() { func

How do closures capture values from previous calls?

孤街醉人 提交于 2019-12-18 22:31:14
问题 typealias IntMaker = (Void)->Int func makeCounter() ->IntMaker{ var n = 0 // Line A func adder()->Integer{ n = n + 1 return n } return adder } let counter1 = makeCounter() counter1() // returns 1 counter1() // returns 2 counter1() // returns 3 Isn't 'Line A' called each time we call counter1() ? meaning that var n = 0 should be called every time... Why is that the counter returns different values? Shouldn't they always be returning '1' ? 回答1: You've called makeCounter() once. That creates

Passing argument from Parent function to nested function Python

做~自己de王妃 提交于 2019-12-17 07:51:17
问题 here is my code: def f(x): def g(n): if n < 10: x = x + 1 g(n + 1) g(0) When I evaluate f(0), there would be an error "x referenced before assignment". However, when I use "print x" instead of "x = x + 1" , it will work. It seems that in the scope of g, I can only use x as an "use occurrence" but not a "binding occurrence". I guess the problem is that f passes to g only the VALUE of x. Am I understanding it correctly or not? If not, can someone explain why the left side of "x = x + 1" is not

Portable nested functions in C

梦想的初衷 提交于 2019-12-12 11:07:35
问题 Is it possible to write portable C code using nested functions/blocks? I understand that gcc only supports nested functions as an non-standard extension, and clang only supports blocks - but is there a way to write code that will compile on both using standard C with MACROS? If it is not possible - what is the best work around? As an example, how would one implement a portable version of the following sort that takes a parameter? Trivial example in GCC: int main(int argc, char*[] argv) { char

Variable scope in nested functions

孤街醉人 提交于 2019-12-12 08:12:42
问题 Could someone explain why the following program fails: def g(f): for _ in range(10): f() def main(): x = 10 def f(): print x x = x + 1 g(f) if __name__ == '__main__': main() with the message: Traceback (most recent call last): File "a.py", line 13, in <module> main() File "a.py", line 10, in main g(f) File "a.py", line 3, in g f() File "a.py", line 8, in f print x UnboundLocalError: local variable 'x' referenced before assignment But if I simply change the variable x to an array, it works:

Doxygen for Python: How to generate documentation for nested functions

旧时模样 提交于 2019-12-12 04:48:51
问题 I am documenting my Python code using Doxygen. The code makes use of Pythons capability of defining nested functions. So I have documented them as if they were "normal" functions and set EXTRACT_ALL=YES . But still, the nested functions cannot be found anywhere. Is there a way to make Doxygen do that? (Doxygen version 1.8.6) 回答1: there is no way to access nested functions so im sure it just doesnt document it def wrapper(): def nested(a,b,c): return a+b+c return nested(1,2,3) #a user can call

Static links - how to determine the number of steps to reach an outer scope local?

不想你离开。 提交于 2019-12-11 13:56:54
问题 I've been reading about using static (aka access) links to implement nested procedures. I have no trouble understanding the concept except how to determine how many "hops" are needed to reach the stack frame of the function that contains the local we want to access. Many sources - among them, this PDF handout (page 4) - list two cases: Suppose f calls g. Let nf = nesting level of f and ng = nesting level of g. We now have two cases: 1) nf < ng --- the callee is nested more deeply than the

Returning value from function inside a function

Deadly 提交于 2019-12-11 03:40:00
问题 I'm using goMap and I'm trying to add a function inside it, but I cannot get it to return when the function is called. If I use alert() inside the function, it has the values I need it that should be returned. getAddress: function(latlngcoords) { var goMap = this; var input = latlngcoords; var latlngStr = input.split(",", 2); var lat = parseFloat(latlngStr[0]); var lng = parseFloat(latlngStr[1]); var latlng = new google.maps.LatLng(lat, lng); var address; geocoder.geocode({'latLng': latlng},