closures

Assign an anonymous method to an interface variable or parameter?

别等时光非礼了梦想. 提交于 2019-11-30 22:41:16
问题 Anonymous methods are essentially interface s with an Invoke method: type TProc = reference to procedure; IProc = interface procedure Invoke; end; Now, is there a possibility to assign them to an actual interface variable or pass them as interface parameter? procedure TakeInterface(const Value: IInterface); begin end; var P: TProc; I: IInterface; begin I := P; // E2010 TakeInterface(P); // E2010 end; [DCC32 Error] E2010 Incompatible types: 'IInterface' and 'procedure, untyped pointer or

Can I use a Closure to define a stage in a Jenkins Declarative Pipeline?

不问归期 提交于 2019-11-30 22:19:43
I'm trying to do something like this: def makeStage = { stage('a') { steps { echo 'Hello World' } } } pipeline { agent none stages { makeStage() } } But it gives me this exception: WorkflowScript: 11: Expected a stage @ line 11, column 5. makeStage() ^ Is it possible to define a stage as a external closure and if so - how? You can't define stages outside the declarative pipeline. The main purpose of declarative pipeline is to provide simplified and opinionated syntax so you can focus on what should be done (by using some of the available steps ) and not how to do it. If you are interested in

Function inside function - every time?

情到浓时终转凉″ 提交于 2019-11-30 21:32:09
问题 Let we have this code: def big_function(): def little_function(): ....... ......... The Python documentation says about def statement: A function definition is an executable statement. Its execution binds the function name... So, the question is: Does def little_function() execute every time when big_function is invoked? Question is about def statement exactly, not the little_function() body. 回答1: You can check the bytecode with the dis module: >>> import dis >>> def my_function(): ... def

Why higher order procedures?

廉价感情. 提交于 2019-11-30 21:28:19
So if a language provides higher order procedure then I can have procedure that returns procedure. Something like: (define (Proc a b c) (lambda (x) ( #| method body here in terms of a b c and x |# ))) To create new procedure, I would just do something like: (define ProcA (Proc a1 b1 c1)) ; Would create ProcA that has 1 argument Similar task could be done in a language which does not support higher order procedure by defining Proc that takes 4 instead of 3 arguments and calling this procedure to define ProcA , like: (define (Proc a b c x) ( #| method body -- does not return any procedure |# )

jQuery-UI Dialog Memory Leaks

那年仲夏 提交于 2019-11-30 21:20:37
I'm working with IE7 and some jQuery dialogs and I'm running into about a 6meg leak per dialog opened. I'm assuming it's to do with closures, but so far everything I've done to remove them haven't helped. At this point I think I've taken care of all the closures except on for a callback function I pass in, but it's still leaking 6 megs even after the dialog is closed and removed. The relevant source code is: function DialogDestroyAndRemove(event) { $(event.target).dialog("destroy").remove(); } function CallbackAndCloseDialog(event) { if (event.data.callback != undefined) { event.data.callback

How do Valas closures map to Genie?

*爱你&永不变心* 提交于 2019-11-30 20:53:31
The Vala Tutorial has an example about DBus using anonymous methods . Bus.own_name (BusType.SESSION, "org.example.DemoService", /* name to register */ BusNameOwnerFlags.NONE, /* flags */ on_bus_aquired, /* callback function on registration succeeded */ () => {}, /* callback on name register succeeded */ () => stderr.printf ("Could not acquire name\n")); /* callback on name lost */ I am trying to rewrite this code in Genie, but could not manage to convert the two last lines. The Genie Tutorial only has an example on how to use a closure to define an event handler . f.my_event += def (t, a)

Use of Functional Interface in Java 8

空扰寡人 提交于 2019-11-30 20:31:27
This is a follow up question from :: (double colon) operator in Java 8 in which Java allows you to refer to methods using :: operator. Is it possible to provide some custom Functional Interface that I create and use it with :: operator? And how to do it? “Is it possible to provide some custom Functional Interface that I create and use it with :: operator? And how to do it?” It is possible and it’s as easy as you could imagine: just create an interface with exactly one method. You don’t even need the @FunctionalInterface annotation; this annotation just documents your intention and helps

Why does this closure-scoped variable lose its value?

戏子无情 提交于 2019-11-30 20:28:32
I saw this Javascript quiz here: http://www.netfxharmonics.com/2008/01/NetFX-Harmonics-JavaScript-Quiz and I could not figure out this problem: (function(){ var a = 1; var b = 2; (function( ) { a = b; var b; })( ); console.log('a:'+ a); // => "a:undefined" console.log('b:'+ b); // => "b:2" })() However, if you remove the var b; declaration from the inner function, then a == 2 as you would expect. Why is this happening? (You can play with it here: http://jsfiddle.net/gnhMZ/ ) It's happening because this function: (function( ) { a = b; var b; })( ); ...assigns undefined to a . var takes effect

How does a lambda function refer to its parameters in python?

不想你离开。 提交于 2019-11-30 20:26:50
I am new in Python. My task was quite simple -- I need a list of functions that I can use to do things in batch. So I toyed it with some examples like fs = [lambda x: x + i for i in xrange(10)] Surprisingly, the call of [f(0) for f in fs] gave me the result like [9, 9, 9, 9, 9, 9, 9, 9, 9, 9] . It was not what I expected as I'd like the variable i has different values in different functions. So My question is: Is the variable i in lambda global or local? Does python has the same concept like 'closure' in javascript? I mean does each lambda here holds a reference to the i variable or they just

How to create custom MouseEvent.CLICK event in AS3 (pass parameters to function)?

一笑奈何 提交于 2019-11-30 20:21:46
This question doesn't relate only to MouseEvent.CLICK event type but to all event types that already exist in AS3. I read a lot about custom events but until now I couldn't figure it out how to do what I want to do. I'm going to try to explain, I hope you understand: Here is a illustration of my situation: for(var i:Number; i < 10; i++){ var someVar = i; myClips[i].addEventListener(MouseEvent.CLICK, doSomething); } function doSomething(e:MouseEvent){ /* */ } But I want to be able to pass someVar as a parameter to doSomething . So I tried this: for(var i:Number; i < 10; i++){ var someVar = i;