It is not possible to use version checking to decide to use a language feature that will cause a parse error in a previous version. The parser looks at the whole file, regardless of branching. If the lint check fails for that version, it won't work, regardless of branching: >...

The first variant is straightforward: In the first line, apply println on x. In the second line, apply the no-argument println (this prints the extra newline). With the second variant you effectively tell Scala to do this: In the first line, define a function object from println(). Subsequently, do nothing...

First of all: Delete your first two lines containing stuff from the symbolic toolbox. You won't need any of this. You have two options: Using a function-file: These would be the contents of the file my_fun.m: function result = my_fun(X) F = [1 2 3 4; 1 2 3 4];...

You don't need a for loop, and you certainly don't need an IIFE. You have an array of results, so just call the native .forEach function. It takes a callback that can is executed on all elements in the array. Benefits of this approach: Gives you closure by default. The...

It sure is, but you have to reference the function, not call it, and arguments are passed automagically myArray.sort(sortAscending); whenever you add parentheses and arguments to a function, it's called immediately. When you want it to be called by another function, for instance as a callback in sort(), you reference...

The actual lambda is going to result in a new named method (you just don't know what that name is) being created at compile time (the exact semantics will vary based on some of the specifics). The only work being done on each invocation of the method is the creation...

Turns out I was running the $app->map('') command twice by accident, in one case sending only 'Admin' and 'Manager' which caused the error. So was a stupid error on my part :(. Just goes to show to watch out for this stuff.

I think you can use use event delegation For solving this problem . event delegation is a mechanism of responding to ui-events via a single common parent rather than each child. More about event Delegation you can refer this stack overflow question In you case it is better to use...

As already mentioned in the comments: Doing this inline is madness and you are much better off using a separate function / .m file. It will be Faster Easier to read Easier to write Easier to debug You could do this for example in a similar way to this: function...

You can use Array.prototype.some method, it will make code more comprehensive and simpler: var myArr=[['de'],['df','de'],['df','dz'],['de']]; if (myArr.some(function(el) { return el.indexOf('de') === -1; }) && confirm("Continue even though one of the choices doesn't contain 'de'?")) { document.write('proceed'); } ...

First problem, Element.node.style is not reliable. To check for current states and values, always use window.getComputedStyle( Node ). Second problem, css properties are represented in Strings, you cannot operate with math operators like +=. el.style.opacity = parseFloat( getComputedStyle( el ).opacity ) + 0.001; ...

The value of x is "hardwired" into the anonymous function when you create it. The function internally stores the value that x has at that time, and will always use that. Subsequent changes to x have no effect on the function. See this example from the documentation: For example, create...

Think of that anonymous function as being an ordinary object with a method on it. You could write that code like this: class MyDispatcherHelper { public function handle($event, $dispatcher, $exception) { $dispatcher = new \Phalcon\Mvc\Dispatcher(); $dispatcher->setEventsManager($evManager); return $dispatcher; } } $evManager = $di->getShared('eventsManager'); $evManager->attach('dispatch', new MyDispatcherHelper()); So now there's no...

Without more context, it's impossible to suggest very specific improvements. That said, for sure you can get rid of the while loop. Just use: BackgroundWorker backgroundWorker = new BackgroundWorker(); backgroundWorker.DoWork += delegate { //code }; backgroundWorker.RunWorkerAsync(); Note that if you have code you want to execute when the BackgroundWorker task...

what do you do if you want to reference "this" in the anonymous inner function at some later time? There is no way to refer to the value of this that the callback would have if we hadn't called .bind. However, you don't have to use .bind, there are...

Looks like the problem is you are calling connectListener where you should just be setting it as the function to be called on a connect event: var client = net.connect({port : 50505}, connectListener); If you want to write to a specific client with specific args, you can do so by...

The argument to the ready handler is passed by jQuery and is set to the jQuery object (see https://api.jquery.com/ready/ > Aliasing the jQuery Namespace). So you can't pass it into the function declaration in your above code. You could set it to a global object or set a form field...

Function z creates and returns a new function, but an anonymous one. That new function is defined so that it has one argument - $y. However, this anonymous function also uses argument $x from a function z. To make it simple, function z basically creates a function which can repeat...

Just save the outer this instance under a different name so that it is preserved: public function Roulette() { var rouletteThis = this; new QuickLoad(url, function (o:*):void {trace(rouletteThis);}); } ...

Half of the point of anonymous functions are that they can capture the context in which they're specified. It's extremely convenient to be able to do so - that's the "why" part. The way the compiler does this is to create a new class in cases where it needs to....

The behavior you are referring to applies only to local variables or method/catch parameters. You can access and, potentially, modify instance members just fine public class Example { public void method() { String localFoo = "local"; new Object() { public void bar() { foo = "bar"; // yup System.out.println(localFoo); //...

TL;DR: This is exactly how the throws() assertion in QUnit is intended to work, and how it must work. Long, drawn out response: In your example you are calling the assertion with the result of the call to sometimesThrows(false). That is to say, in your example above, when you call...

This is exhibiting a functional programming technique called currying. (related also to partial function appliction) Greater than > usually takes 2 arguments (one on the left and one on the right). This is a way to feed one at a time. It might be easier to see what is happening...

Using a function creates a scope. You can have params inside and do more than just alerting. Now you can do the same without a function, but then you will keep the state on the window object and thats something that you would like to prevent in some cases.

EDIT After I answered this, a better strategy has been found: Just use nargin; see @k-messaoudi's answer. For inline functions: According to inline's help: INLINE(EXPR) constructs an inline function object from the MATLAB expression contained in the string EXPR. The input arguments are automatically determined by searching EXPR for...

Instead of passing the function directly, you can wrap it in another function, creating a closure. The inner function will be able to reference the value you stored in self, which refers to the original Ploter you're looking for: bindEvents: function() { var self = this; d3.json(this.DATAURL) .on("load", function(data) {...

When you do this setTimeout(function(arr[c]) { You are defining a new function and saying that I want this function to accept a parameter called 'arr[c]', you aren't saying that you want to pass arr[c] to it and because you can't have any special characters in the name of a parameter...

This is called a callback function, and it basically provides a reference to a function that is called at each iteration of the array that you passed as the first parameter. It is a very common pattern in JavaScript, and many libraries work based on this. For example, I assume...

Here there is a workaround. The function integral integrates numerically a function. Therefore to use it, you need a numerical expression, thus you need to give values to a, g and v. If you dont want to do it you could symbolically integrate the equation s, so: s = (g^2*t^2...

The fact that you call greet makes PHP treat it like a function and not a property. You can have the same name for both a property and method in PHP, so the distinction is relevant. What you can doe as a workaround is use the __call() magic method. It...

You forgot to return the result of statement: MyDictionary.Keys.Where(delegate(string s) { return s.Length == 5; }); Think about delegate as a complete method which have to be as same as possible to an independent method, except the naming part. So, you can imagine it as: delegate(string s) { // you...

Do you really need a symfun? It seems function handles are fine in your case. f=@(a,b,x)((a*exp(-a*(x-b)))/((1+exp(-a*(x-b)))^2)) paramList = [0.18, 20; 0.25, 25; 0.35, 15; 0.3, 20; 0.33, 30]; for rw=1:size(paramList,1) fcnList{rw}=@(x)f(paramList(rw,1),paramList(rw,2),x); end This generates the list. In case you simply want to evaluate use: fcnList{1}(5) Or to get the expression:...

I have the following implementation based upon Nick's question. First the class for the FuelTank: public class FuelTank { private float fuel; //Basic classes for the event handling, could be done by providing a few simple delegates, //but this is just to stick as close to the original question as...

If you can use Python 3 then the newly introduced(Python 3.3+) inspect.Signature and inspect.Parameter can make your code very clean(PEP 362 - Function Signature Object). These come very handy in decorators as well: from inspect import Parameter, signature, Signature def get_multivar_lambda(expression, variables=["x"]): params = [Parameter(v, Parameter.POSITIONAL_OR_KEYWORD) for v in variables]...

The answer is to make use of the PHP use keyword: class Greetings { public static function getRepeatGreeterFunc($greetingCount) { $repeatGreeter = function($greeting) use ($greetingCount) { // I want $greetingCount to bind to the outer $greetingCount here. // If 4 is passed to getRepeatGreeterFunc, then it should be 4 here, //...

In practice, the stateless lambda has a function that exists so long as the compiler cannot prove nobody calls it. This function is stored in your executable at compile time, and is loaded at run time. Barring a dll or so format (or other similar things), it lives as long...

One thing you have to be aware that you work here with asynchronous actions. Let's number lines in order of exaction (n means some high number far far later) 1] $(document).on("click", '.delete-component', function(e) { n+1] return 4; }); 2] console.log('here'); What you did was attached listener to click. Click won't...

You can use a function pointer, or function object in C++11, but there is no built-in way to refer to a function. For example: std::function<int (int)> myFun = [] (int i) { if i <= 1 { return 1; } return i * myFun(i-1); } I would argue that calling...

The .then() method expects you to pass it a function, because it's (eventually) going to call it. If you just pass a (non-function) value, that can't happen. The point of calling .then() is to say, "when the operation has finished, please do this." edit — ah OK, sorry. In this...

Don't pass functions between Nashorn and Java. Pass objects which implement functional interfaces. I assume o.timer is implemented in Java. In that case, make its parameter a Runnable (the generic functional interface for a function which takes nothing and returns nothing). Nashorn will detect that Java expects a functional interface...

AAA3 is a local variable and it can't be access outside the function or current scope. Variable declarations, wherever they occur, are processed before any code is executed. The scope of a variable declared with var is its current execution context, which is either the enclosing function or, for variables...

I would suggest the following: k = linspace(a,b); x = c:0.01:d; [X,K] = meshgrid(x,k) y = arrayfun(@(p,t) normcdf(p, b0+b1*t, sigma), K(:), X(:)) res = cumtrapz(x,y) Untested though as you gave no example data and desired results. Maybe you need to swap the order of x and k as well as...

The code that works captures the local variable h. That means that its lifetime is extended. The compiler does that by allocating the variable h on the heap. Your code doesn't have any variable capture. Which means that h is allocated on the stack and its lifetime ends when the...

Simple rules to determine the scope of underscore: If the underscore is an argument to a method, then the scope will be outside that method, otherwise respective the rules below; If the underscore is inside an expression delimited by () or {}, the innermost such delimiter that contains the underscore...

You can use a closure around the addListener part: (function(text){ google.maps.event.addListener(marker, 'click', function () { ShowMarkerContentPopUp(this, text); }); })(text); This creates a new scope and takes the text variable as an argument. It means the text inside the closure is protected from being changed outside of the closure. The same...

Since the syntax for function declarations and function expressions is identical, JS tells which one you are using from the code around the function. To stop it being a function declaration you need to use it in an expression. Wrapping it in parenthesis will will do that but preceding it...

There are several problems with what you're doing. For starters, attempting to call the function recursively (function(n+function(n-1))) will result in a call stack size exceeded error because you're adding the sum to each argument passed to the recursive call. You probably want something closer to (n + function(n-1)). However, this...

The problem is in this line: a = func_array(1) you need to access the content of the cell array, not the element. a = func_array{1} and everything works fine. The visual output in the command window looks the same, which is truly a little misleading, but have a look in...

To iterate over the functions and paramVector objects at the same time, use Map. For example Map(function(f,p) f(p), functions, paramVector) Note that Map() always returns a list. You can also use mapply() which will attempt to simplify to a vector mapply(function(f,p) f(p), functions, paramVector) ...

Unlike in some scripting languages, identifierCollection's lifetime won't be extended simply because you captured it into a closure. So as soon as you change that [=] for a [&] to capture by reference, it's a dangling reference to a local variable that you're capturing. You'll have to manage the lifetime...

The problem is that type class constraints for type parameters currently do not match subtypes; I do not know if that is a bug or intentional. For now, simply remove the : Base constraint from the type parameter T.

You need to (or, rather, it may be best to) expand varargin into a comma-separated list with your current implementation: h = @(varargin)f(A,B,C,varargin{:}) The question of if there is a better way is dependent on the specifics of the problem....

You just mixed up the object with the function. It should be: this.success_callback_func.call(this.success_callback_ob, msg) A Function has a .call() method, that takes a context object as the first argument. Object has no .call() method....

It's actually not a that bad question, the 'use strict'; indicates that the code inside the function should be evaluated in strict mode which is part of ECMAScript5. With strict mode enabled, you can not use undeclared variables - which is important here. If your browser is capable of ECMAScript5...