anonymous-function

Matlab function handle workspace shenanigans

佐手、 提交于 2019-12-23 07:39:29
问题 In short : is there an elegant way to restrict the scope of anonymous functions, or is Matlab broken in this example? I have a function that creates a function handle to be used in a pipe network solver. It takes as input a Network state which includes information about the pipes and their connections (or edges and vertices if you must), constructs a large string which will return a large matrix when in function form and "evals" that string to create the handle. function [Jv,...] =

Is there += for window.onload in Javascript?

不羁岁月 提交于 2019-12-23 07:39:13
问题 recently I came up with the following problem: In my web site in all html pages I call a function in body onLoad event: <body onLoad="func1();"> This is part of my template for html, so it appears on every page in my site and I can't change that. Now, the deal is that on some pages, I need to call some other functions onload and I tried with window.onload property, but it wipes the calling of func1... I now that I can just say: window.onload = func2(); //where func2() calls to func1() but

Scala: How do I define an anonymous function with a variable argument list?

余生颓废 提交于 2019-12-23 07:04:29
问题 In Scala, how do I define an anonymous function which takes a variable number of arguments? scala> def foo = (blah:Int*) => 3 <console>:1: error: ')' expected but identifier found. def foo = (blah:Int*) => 3 ^ 回答1: It looks like this is not possible. In the language specification in chapter 6.23 Anonymous functions the syntax does not allow an * after a type. In chapter 4.6 Function Declarations and Definitions after the type there can be an * . What you can do however is this: scala> def foo

Passing additional iteration-dependent inputs to ode45

筅森魡賤 提交于 2019-12-23 03:14:48
问题 I'm trying to solve differential equation using the ode45 function. Consider the following code, [t1,X2] = ode45(@(t,x)fun(t,x,C1,C2,C3,C4),t0,X01); where parameters C1 , C2 , C3 and C4 are column vectors, which should be available to the function that ode45 is referring to ( fun.m ). I want the values to change after every iteration, so for example, at the beginning the entry of C1 I want in is C1(1) , in the next iteration it's C1(2) , etc. How can I implement that? 回答1: You may have

How does `arguments.callee` refer to anonymous functions?

前提是你 提交于 2019-12-23 02:07:08
问题 A script was needed to quickly tell me how many html comments there are on the page and what their contents are. Using an anonymous function for recursive DOM traversal seemed appropriate: var comments = []; //set up an array where comment contents will be copied to (function(D) { if (8===D.nodeType) comments.push(D.nodeValue); //check if node is a comment D=D.firstChild; while (D) { arguments.callee(D); //recursively look for comments... D=D.nextSibling; //...and remember to iterate over all

LINQ - What does (x, i) do?

我们两清 提交于 2019-12-22 14:48:07
问题 I stumbled across this code today and realized I don't understand it what-so-ever. someArray.Select((x, i) => new XElement("entry", new XElement("field", new XAttribute("name", "Option"), i + 1) What is the point of (x, i) ? I see a reference to the i , but I'm not understanding how the x fits into this lamda expression. Also, why is i an integer? I see towards the end there is an i + 1 , so I'm assuming that's true. Thanks for your help 回答1: The x is the value, and the i is the index. For

Closure objects within arrays before PHP 5.3

荒凉一梦 提交于 2019-12-22 09:17:48
问题 I know it's possible to do the following with PHP 5.3 (anonymous functions), but is there a similar alternative in older PHP version (pre-5.3)? $exampleArray = array( 'func' => function() { echo 'this is an example'; } Is it possible to do this with __call or typecasting the function as an (object) first? Also, I tried making the function un-anonymous by giving it a name, but this didn't seem to work. 回答1: If you want to create anonymous in PHP < 5.3, you can use create_function function.

Javascript: Why use an anonymous function here?

ε祈祈猫儿з 提交于 2019-12-22 04:37:13
问题 I was browsing the JIT's code, and I saw this: var isGraph = ($type(json) == 'array'); var ans = new Graph(this.graphOptions); if(!isGraph) //make tree (function (ans, json) { ans.addNode(json); for(var i=0, ch = json.children; i<ch.length; i++) { ans.addAdjacence(json, ch[i]); arguments.callee(ans, ch[i]); } })(ans, json); else //make graph (function (ans, json) { var getNode = function(id) { for(var w=0; w<json.length; w++) { if(json[w].id == id) { return json[w]; } } return undefined; };

Recursive anonymous functions in SML

孤街浪徒 提交于 2019-12-22 04:29:11
问题 Is it possible to write recursive anonymous functions in SML? I know I could just use the fun syntax, but I'm curious. I have written, as an example of what I want: val fact = fn n => case n of 0 => 1 | x => x * fact (n - 1) 回答1: The anonymous function aren't really anonymous anymore when you bind it to a variable. And since val rec is just the derived form of fun with no difference other than appearance, you could just as well have written it using the fun syntax. Also you can do pattern

Expression tree depth limitations

假如想象 提交于 2019-12-21 17:39:03
问题 I'm facing a problem trying to call Compile() on the LambdaExpression of type Expression<Func<MyType, bool>> which has a depth around 400. And lesser values do not cause any problems. And I can't find anything about such kind of limitation. Can anyone clarify this? Can I increase this limit? upd: Sorry, forgot to mention, I'm getting StackOverflowException: An unhandled exception of type 'System.StackOverflowException' occurred in System.Core.dll {Cannot evaluate expression because the